Adafruit 32u4 Breakout

May 21, 2013

I bought one of these in April of 2013. One thing I like about buying things from Adafruit, is that they toss in the header pins for the programming interface and for the pins along the edges of the board. The pin spacing on this module is such that it can be plugged into a "standard" breadboard, which is very nice -- and a strong reason to buy this instead of something like a "pro-micro" from Sparkfun.

It runs at 16 Mhz. There is a programmable green LED and a very bright red power LED. When the bootloader is active, the green LED "breathes" (it doesn't just blink).

When I plug mine in, I see:

New USB device found, idVendor=239a, idProduct=0001
usb 2-1.8: New USB device strings: Mfr=0, Product=1, SerialNumber=0
usb 2-1.8: Product: AVR CDC Bootloader
cdc_acm 2-1.8:1.0: ttyACM0: USB ACM device

The description claims that the bootloader will run for about 10 seconds after reset. It seems more like 5 seconds, and later perusal of the BootLoader source confirms that the timeout is indeed 5 seconds. After this time, the bootloader times out and your code will run. The game then to load new code is to press the reset button and then (in my case) type "make load" before 5 seconds is up.

Also, I note that when I first plug in the device, it immediately runs my code. To get to the boot loader, I have to hit the reset button. This is actually quite nice. (I like this a lot better than the Sparkfun pro micro where you have to do weird things with the USB pseudo buad rates to get the boot loaders attention).

The "device programmer" is "avr109", so an avrdude line like this should work:

avrdude -p m32u4 -P /dev/ttyACM0 -c avr109
[tom@trona blink_micro]$  avrdude -p m32u4 -P /dev/ttyACM0 -c avr109
Connecting to programmer: .
Found programmer: Id = "LUFACDC"; type = S
    Software Version = 1.0; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.
Programmer supports the following devices:
    Device code: 0x44
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9587
avrdude: safemode: Fuses OK
avrdude done.  Thank you.
To build the blink demo, I use a makefile, which ultimately does this to build the image to download:
avr-gcc -mmcu=atmega32u4 -Wall -Os -o blink.elf blink.c
avr-objcopy -j .text -j .data -O ihex blink.elf blink.hex
The following line then loads the image
avrdude -p atmega32u4 -c avr109 -P /dev/ttyACM0 -D -U flash:w:blink.hex:i

Where the heck is the LED

I mean, what IO bit drives the led? The PNG schematic is botched and simply shows the LED connected to pin 14 of one of the two 15 pin headers, which doesn't help much. Looking at the silkscreen on the board shows this header pin as labelled "E6", so maybe the LED is driven by the E port on pin 6 (this turns out to be true). For more information, I pull down the source for the bootloader (thank heaven for open source!). The file lufa-lib/trunk/Bootloaders/CDC/BootloaderCDC.c has what I want to know:
#if BOARD == BOARD_ADAFRUIT32U4
   #define BOOTLOADERLED_DDR DDRE
   #define BOOTLOADERLED_PORT PORTE
   #define BOOTLOADERLED 6
#endif
Given this, I modify my blink demo and I am blinking the LED!

I wonder how the bootloader gets a nice "breathing" effect to the blinking LED brightness, and a bit of study of the source code shows they are doing a clever software driven PWM of the bit controlling the LED, slick!

The boot loader

It was easy to get a copy of the loader source code via:
git clone https://github.com/adafruit/lufa-lib.git
This is the LUFA source tree, with what look like straightforward modifications to two files.

The main bootloader file is modified to blink the LED:

lufa-lib/trunk/Bootloaders/CDC/BootloaderCDC.c
The only other file that I have found modified is: lufa-lib/trunk/Bootloaders/CDC/Descriptors.c as follows:
  .VendorID               = 0x239A,       // Adafruit VID for our use only, thanks!
  .ProductID              = 0x0001,       // #1 is the USB CDC (bootloader)

Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org