Minimus usb and LUFA

May 21, 2012 at 7:20 pm (maker) (, , , )

Once I’d got the basics of programming the Minimus sorted out (see my last post), I was keen to see if I could get a USB stack compiled and running on it, so I could then actually think about talking to my code running on it from a PC.

Well it turns out that the LUFA stack “knows” about the minimus and it doesn’t take much to get the demo applications running.  LUFA is an excellent set of code, supporting both raw USB access and many common classes.

I downloaded and extracted the code base into my project area and sought out the sample keyboard class application (Demos/Device/ClassDriver/Keyboard).

There is a top-level project file (lufa.pnproj) for Programmers Notepad which gives you the full set of code – all demos, library, drivers, etc. Navigate to the demo application you wish to build and then you can “make all” in that directory and built the entire library and code.

Before that though, I had to configure the Makefile for the minimus. The documentation is very good once you know a little about what you are doing, but it took me a while to understand enough of the ‘getting started’ documentation to get the stage where I had running code.

The following had to be set to work for the minimus:

MCU = at90usb162
F_CPU = 16000000

Then I had to tailor the example a bit for the minimus.  Key things to do:

  • Keyboard.c: In SetupHardware() comment out Joystick_Init() – as there is no joystick on a minimus
  • Keyboard.c: Same in CALLBACK_HID_Device_CreateHIDReport() – comment out the line with the call to Joystick_GetStatus()
  • Keyboard.c: Then I commented out all the code examining JoyStatus_LCL in the same function and was left with a single test – the check for the switch
  • Keyboard.h: Comment out the #include <LUFA/Drivers/Board/Joystick.h> line

After some thought, I decided what I wanted was to generate a Windows-L key sequence (thinking it would be entertaining to force the ‘change user’ screen to show).  For what I had to lookup the USB modifier term for the Windows key, which had a peculiar name – it turns out it is the HID_KEYBOARD_MODIFIER_LEFTGUI modifier key …

My final CALLBACK_HID_Device_CreateHIDReport() function was thus as follows

  USB_KeyboardReport_Data_t* KeyboardReport =

  uint8_t ButtonStatus_LCL = Buttons_GetStatus();
  uint8_t UsedKeyCodes = 0;

  if (ButtonStatus_LCL & BUTTONS_BUTTON1)
    KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_L;
    KeyboardReport->Modifier = HID_KEYBOARD_MODIFIER_LEFTGUI;

  *ReportSize = sizeof(USB_KeyboardReport_Data_t);
  return false;

Note that the sample code allows for up to 6 keys to be returned in one go. I’m only using one for this test.

At this point I was ready to compile everything and give it a go.

Unfortunately when configuring the Makefile, I had got distracted before changing F_CPU (I couldn’t remember the clock speed and was about to look it up when kids happened).  So for my first build, after loading and running, nothing happened at all.  It just so happens that nothing works when F_CPU is the default of 8000000.

After quite a bit of head scratching, I returned to the Makefile and remembered that I hadn’t looked up the clock setting.  Thankfully setting it correctly and another build (after a ‘make clean’ to be sure) sorted it all out.

There was some benefit to this problem though – I got to navigate a fair bit of the LUFA code and standard AVR definitions trying to decode macros for watchdogs, definitions for LEDs and so on.  Some key bits of information I learned:

  • The standard AVR definitions I’d need were installed with WinAVR in c:\WinAvr-version\avr\include\avr directory. Key files being io.h and wdt.h
  • The definitions for the minimus from the LUFA libraries were installed in <LUFA Root>\LUFA\Drivers\Board\AVR8\MINIMUS with the main (well, only actually) files being Buttons.h and LEDs.h
  • The key bits of LUFA I was using were in <LUFA Root>\LUFA\Drivers\USB\Class\Device

So once it was running my code, Windows obligingly went through its “detecting new device” routine and recognised the minimus as a USB HID keyboard device and at that point, pressing the button triggered the Windows-L response I’d been looking for.

And that was it.  I now have a successfully running USB stack on the minimus.  My very many thanks to Dean Camera at  The LUFA code is just great – so many possibilities!




  1. Minimus usb – getting the solder out « Kevin's Blog said,

    […] having spent some time programming the device as is (see my previous posts here and here) if I was to get any further I have to do some soldering!  The minimus has 22 IO pins sitting […]

  2. Arduino and the Minimus32 | Kevin's Blog said,

    […] had some Minimus boards kicking around for, well, since 2012 or so but they kind of lost their interest as I acquired more Arduino-compatible boards of other […]

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: