The LUFA project contains the TeensyHID bootloader that can be used as a replacement of the original HalfKay bootloader preloaded on the Teensy boards.
It can be useful if like me you have completely erased the original flash with an external programmer. Because the HalfKay bootloader is proprietary code and is protected by lock bits, you can not read it from another board. In this case the TeensyHID is the only alternative to restore a bootloader compatible with the Teensy loader tools.
Compiling the bootloader
I am using the LUFA 091223.zip release. The TeensyHID project can be found in the Bootloaders/TeensyHID subdirectory.
To compile it for a Teensy 1.0 based on the AT90USB162 I make the following changes in the provided Makefile:
MCU = at90usb162 #atmega32u4 ... BOOT_START = 0x3800 #0x7000 ... AVRDUDE_PROGRAMMER = avrispmkii #jtagmkII
The value of BOOT_START is the starting address for a 2048 bytes bootloader (cf AT90USB162 datasheet, 23.7.14, p. 239).
I can check in the build output that the binary can fit in the 2048 bytes limit:
# make ... Program: 2002 bytes (12.2% Full) (.text + .data + .bootloader) Data: 84 bytes (16.4% Full) (.data + .bss + .noinit) ...
Setting the boot size fuse bits
Two BOOTSZ fuse bits in the Fuse High Byte tell the MCU where the start address of the bootloader is (cf AT90USB162 datasheet, 25.2 Fuse bits, p. 245).
To read the hfuse:
# avrdude -p at90usb162 -P usb -c avrispmkii -U hfuse:r:-:h -v ... avrdude: writing output file "
" 0xdf avrdude: safemode: lfuse reads as DF avrdude: safemode: hfuse reads as DF avrdude: safemode: efuse reads as F0 avrdude: safemode: Fuses OK ...
The Teensy factory hfuse value is 0xDF. It tells us that HalfKay is a 512 bytes bootloader that starts at address 0x1E00.
The hfuse value for the TeensyHID bootloader will be 0xDB (BOOTSZ1 = 0, BOOTSZ0 = 1).
To write the hfuse:
# avrdude -p at90usb162 -P usb -c avrispmkii -U hfuse:w:0xdb:m -v ... avrdude: verifying ... avrdude: 1 bytes of hfuse verified avrdude: safemode: lfuse reads as DF avrdude: safemode: hfuse reads as DB avrdude: safemode: efuse reads as F0 avrdude: safemode: Fuses OK ...
Now I can program the bootloader and test it:
# make program
Testing the bootloader
The Teensy loader application is available on the Teensy home page with two blinking-led test binaries, blink_slow.hex and blink_fast.hex.
To execute the bootloader, you have to press and release the pushbutton on the Teensy. The bootloader starts and is enumerated as a USB device and the loader application display changes:
You can now load an HEX file and transfer it on the Teensy target. You may need to unplug the Teensy to reboot it. The reboot feature of the loader does not seem to be implemented.
Compiled binary [added 2010-09-04]
I patched the TeensyHID source code with the Teensy 1.0 HID. The board is now correctly recognized as a Teensy 1.0/AT90USB162 one by the Teensy Loader 1.05.
TeensyHID.hex [AT90USB162 / Patched LUFA091223 HID]
Compiled binary [added 2011-01-06]
Here is the patched TeensyHID binary compiled for an 8MHz AT90USB162 board. Not tested since I don’t own corresponding hardware.
TeensyHID_8MHz.hex [AT90USB162 8MHz / Patched LUFA091223 HID]