May 22, 2013

Resources

There is a support forum (on Google Groups):

This is a good place to ask questions, and there is an excellent chance that the project author, Dean Camera (who seems to be quite a nice guy), will actually jump right in and help out.

First Steps with LUFA

I downloaded the latest release (LUFA-130303.zip in 5-22-2013) and unzipped it. Then:
unzip LUFA-130303.zip
cd LUFA-130303
make doxygen
firefox LUFA/Documentation/html/index.html
This will get you going reading the documentation.
This also seems to be online at:

I wasted some time fiddling with older LUFA releases (but not much), these were giving me warnings from Doxygen about some obsolete commands, and when I tried "make all" in a couple of project folders, the C compiler was telling me I had to insert a bunch of const declarations before I could use progmem. All this was cleaned up in the latest release, so it was just a matter of grabbing and unbundling it.

After that I tried visiting different project directories and typing "make all". I was getting errors because there were still residuals from the make of one project scattered in the directory tree when I launched the build for another project. Things like: Endpoint_WaitUntilReady and USB_DeviceState were missing. The cure is to type "make clean" whenever you change directories to a new project.

LUFA is different

It is important to understand ways in which LUFA is different from what you may be expecting. Although it is called a library, it is more of a framework within which you can build an AVR microcontroller project that uses USB. What I would expect from the name library is that you get LUFA, and build it to something like liblufa.a and put this where the avr toolchain can find it at link time. This is not what you do.

You can do something like this -- but you will be departing from the mainstream, and on a linux system you will need to craft your own makefile to do this apparently. But you are discouraged from doing it because there are many compile time LUFA settings that are unique to each project. If you work with more than one Atmel controller, you would need (at the very least) a liblufa_x.a and liblufa_y.a for each of them.

So what you do is to drop your own project into the LUFA distribution (or make an appropriate setting of the LUFA_PATH variable in your project makefile) and make use of the LUFA make scheme. I have tried things this way, and it is quite straightforward and painless.

A first LUFA project

Somewhere I found a long list of LUFA projects and scanned the list looking for the simplest one I could find. For some reason I picked the Ikea Dioder project: I had trouble though when I dropped this into LUFA130303. It was missing the Config directory, and even when I provided one, there were prototype complaints (apparently LUFA has changed some since this project was done). But I learned some things from this fellows host side python scripts.

Next I selected the LUFA Generic HID demo in Demos/Device/LowLevel/GenericHID. This looked quite familiar after studying the Ikea Dioder, which was clearly derived from this demo. I made a copy of this entire directory (just a few files) in Demos/Device/LowLevel/Zap, changed some settings in the makefile and was able to program this into my atmega32u4 -- my first LUFA build running on an AVR chip.

Based on this, here is a recipe to start your first LUFA project:

  1. Pick some LUFA Demo or Project from the latest distribution.
  2. Make a new directory for your project and copy your template projects files into it.
  3. Rename GenericHID.c and GenericHID.h to a name of your choosing.
  4. Edit GenericHID.c to include the renamed header file.
  5. Inspect Config/LUFAConfig.h and ponder the selections there.
  6. Edit makefile to build the renamed target
  7. Edit makefile to specify chip and board
  8. Edit makefile to add a target "load" that runs avrdude properly
  9. make clean ; make
  10. make load to burn the device.
Take a look at Descriptors.c -- you can specify the vid and pid of your device here, as well as setting the manufacturer string and device name. You also specify endpoint numbers here.
Feedback? Questions? Drop me a line!

Tom's Computer Info / [email protected]