While the AT90USB1286 MCU in the Teensylu/Printrboard can be programmed with an ICSP or JTAG programmer, you can also install a bootloader, which will allow you to program it via a USB connection alone. Besides the convenience of not having to attach a hardware programmer, uploading firmware via a USB bootloader is blazingly fast. Also, it allows you to write host software to do end user firmware upgrades without a hardware programmer.
I am currently aware of 3 bootloader options for the AT90USB128x MCU’s:
DFU – USB Device Firmware Upgrade Class
This is the bootloader officially supported by Atmel.
PRO: Works with Atmel FLIP tool.
CON: requires libusb device driver; no command line tool available for Windows. For Linux, an open source host loader app is available; can’t integrate into Arduino IDE
CDC – USB Communication Device Class
PRO: can integrate into Arduino IDE; works with avrude via avr109 protocol.
CON: requires user to know which virtual serial port it’s associated with; in Windows, uses native Windows driver, but requires INF file install, needs upgrade of avrdude to newer version for Arduino < 1.0.
HID – USB Human Interface Device Class
PRO: Trouble free – doesn’t require any device drivers – just plug and play
CON: doesn’t integrate into Arduino IDE
Before you can install a bootloader on your MCU, you must set the fuses correctly to allocate space for it. We need 4K bytes (2K words) of space, so using the Engbedded Atmel Fuse Calculator, we see that we need Boot Flash Size BOOTSZ=01, which is in the high fuse. Here are the fuse settings that I use on mine:
avrdude -c usbtiny -p at90usb1286 -U lfuse:w:0xde:m -U hfuse:w:0xdb:m -U efuse:w:0xf0:m
BE CAREFUL IF YOU WANT TO FIDDLE WITH FUSE SETTINGS YOURSELF. It’s not hard to “brick” your AVR with the wrong settings. In fact, when I was first working with my Printrboard, I managed to brick it by messing up the CKSEL bits, thinking I was supposed to set it for an external oscillator. Luckily, all I had to do was connect an external oscillator (I used the signal generator function of my DSO Quad mini scope) to XTAL1 and then use avrdude to fix the offending fuse. If you do something worse, like disabling SPIEN by accident, you might have to resort to HV programming. Here is some info on recovering a bricked AVR: http://www.larsen-b.com/Article/260.html
Note that I have set hfuse = 0xdb, which disables the JTAG interface. This makes more I/O pins available (in particular, some of the pins exposed on the I/O headers of Printrboard). If you want to use a JTAG programmer, you should instead set hfuse = 0x9b.
Once your fuses are set correctly, use avrdude with your programmer to upload the bootloader. After your bootloader is installed, you don’t need to use the programmer anymore – just a USB connection is enough.
Booting into Bootloader
Once a bootloader is installed (see instructions below), the bootloader must be activated when you want to upload firmware. To boot the AVR into the bootloader instead of normal program code, you must tie the HWB pin to ground during a RESET pulse. To to this on Teensylu or Printrboard, simply remove the 2-pin jumper that’s next to the AT90USB1286 chip, then press and release the reset button. You can then replace the HWB jumper.
NOTE: If you have a Printrboard RevD, the jumper has been reversed, and needs to be INSTALLED to get into the bootloader, and REMOVED to run your firmware.
Below, I describe how to install and use each of the bootloaders. For Arduino IDE integration, use BootloaderCDC. I also like BootloaderHID, because it doesn’t need drivers, and doesn’t require selecting a virtual serial port.
- Download and install FLIP. FLIP will also install the device driver.
- Download BootloaderDFU.zip. I built this one for AT90USB1286 from LUFA-120219.
- Install with avrdude: avrdude -c usbtiny -p at90usb1286 -U flash:w:BootloaderDFU.hex:i (note if avrdude complains of a verification error, ignore it)
- To flash hex files to board, after Booting into Bootloader, use FLIP or dfu-programmer.
- Download BootloaderCDC.zip. I built this one for AT90USB1286 from LUFA-120219.
- Install with avrdude: avrdude -c usbtiny -p at90usb1286 -U flash:w:BootloaderCDC.hex:i (note if avrdude complains of a verification error, ignore it)
- To flash hex files, you’ll need a newer version of avrdude than the one included with Arduino < v1.0. The version I use is 5.10. After Booting into Bootloader (the first time, Windows might want a driver … point it to the INF file that I included) , type: avrdude -c avr109 -P port -p at90usb1286 -U flash:w:firmware.hex:i, substituting your Printrboard’s CDC serial port for port, and the name of your hex file for firmware.hex.
- If you want to flash directly from the Arduino IDE, follow my instructions for installing my at90usb1286txt.zip files into Arduino. Then, after restarting Arduino and Booting into Bootloader, select [BootloaderCDC]Teensylu/Printrboard from the Arduino Tools->Board menu. Then select the serial port associated with your board. Hit the Upload button in the Arduino IDE to compile and upload your sketch.
- Download BootloaderHID.zip. I built this one for AT90USB1286 from LUFA-120219.
- Install with avrdude: avrdude -c usbtiny -p at90usb1286 -U flash:w:BootloaderHID.hex:i (note if avrdude complains of a verification error, ignore it)
- To flash hex files, after Booting into Bootloader, type: hid_bootloader_cli -mmcu=at90usb1286 -w -v firmware.hex, substituting the name of your hex file for firmware.hex. I’ve included the Windows binary. For Linux or OSX, you can build hid_bootloader_cli yourself from the LUFA sources.
NOTE: When uploading a bootloader to the AT90USB1286 using a USBtinyISP, you will get a verify error from avrdude. You can safely ignore it. The problem is that the USBtinyISP has a bug with reading flash memory above the 64K (10000h) boundary. However, it can write it without problems.