If you are using the Arduino Pro Micro, there is a binary of a modified LUFA DFU bootloader ready to use at the bottom of this page (along with the source). Load it into the chip with an ISP programmer and further programming can be done using the free ATMEL FLIP software via USB without a programmer.
The bootloader would stay in bootloader mode for 5 seconds after reset. It exits bootloader mode and executes user's application at 0x0000 if it is not connected to ATMEL FLIP software within 5 seconds after reset. It will stays in bootloader mode until next reset.
USB Programming with Microcontroller
Using the LUFA FLIP DFU bootloader
, the Arduino Pro Micro
can be programmed without an ISP programmer. All I need is the ATMEL FLIP software
and the chip can be erased and programmed directly via USB, which also powers the board.
interface of Atmel's FLIP software
Device Firmware Update (DFU)
The Atmega32U4 can be programmed using the USB DFU Class. The LUFA USB library comes with one such DFU bootloader. The only problem is that one would still need an ISP programmer to flash the bootloader on the chip for the first time. A chicken and egg problem. You can borrow an ISP programmer from a friend, or get a cheap programmer off eBay
. The point is that once the bootloader is loaded, the uC firmware can be upgrade in the field using just a USB cable.
Bootloader vs. Application
After reset/power up, the AVR would normally execute the application code at 0x0000 in the flash. If the fuse BOOTRST is programmed, however, the chip would execute the bootloader section of the flash instead.
A bootloader program is not very much different from a normal application, except that it is placed somewhere in the flash other than 0x0000 (usually near the end of the flash address). Exactly where it is in the flash is determined by the fuse setting BOOTSZ. Here 4kB of flash is reserved in order to fit the LUFA DFU bootloader, so the last 4kB of the flash is the bootloader flash and the rest is the application flash.
The recommended fuse settings are shown in the screenshot below. Note that the BOOTSZ is measured in unit of words, whereas in the LUFA makefile it is measured in unit of kilobyte. For the ATmega32U4,
the "BOOT_SECTION_SIZE_KB" define in the LUFA makefile should be 4, not
Compiling the LUFA DFU Bootloader
I had to compile the LUFA DFU bootloader specifically for my Arduino Pro Micro (in particular, the LEDs are not on the right pins). The following section documents several critical steps that make the bootloader work.
Required Software and Makefile Settings
Atmel Studio can be set to use an external makefile. Personally I prefer the GUI setting in the Studio, but I have not yet figured out how to compute the relative addresses required by the LUFA bootloader in Studio so I will stick to the LUFA makefile for now.
The calculation for relocating the DFU bootloader is done in the LUFA makefile, but it requires the GNU tool "bc"
. It also requires the other GNU tools, so MinGW need to be installed, particularly the MSYS
package. Make sure the Environmental Path in Windows include:
- C:\Program Files (x86)\GnuWin32\bin
(Dean Camera's LUFA documentation has explained these issues pretty thoroughly,
however the sea of information in the LUFA doc is overwhelming for a beginner (or maybe it's just me). A step-by-step tutorial would be nice.)
The "BOARD" define in the LUFA makefile should be "USER", as the Arduino Pro Micro is not an officially supported platform (although the chip is). I have a working copy of the makefile at the bottom of my page.
From my experiment, the "BLB1" fuse has to be programmed to "SPM_DISABLE" for the bootloader to work with ATMEL FLIP.
This protects the bootloader from being overwritten during FLIP programming.
Once the DFU bootloader has be programmed onto the chip, Windows will require a driver for it (I am using Win7 64-bit). The driver is included in the FLIP installation directory:
- C:\Program Files (x86)\Atmel\Flip 3.4.7\usb
The Arduino Pro Micro always enters bootloader DFU mode after reset. So to test the DFU bootloader, try downloading a simple program (such as a "blinky", see attachment at the bottom) to the chip.
This took me a while to figure out: to exit the bootloader and run your program, you can click the "Start Application" button.
Alternatively, you can just reset the chip and wait 5 seconds. The bootloader will give control to user's program if it is not connected to the FLIP software within 5 seconds after reset.
LUFA's Troubleshooting page:
LUFA #defines and flags: