ubaboot v0.5 is a USB bootloader for atmega32u4 in 512 bytes.
- Targets atmega32u4-based boards
- Compiles to less than 512 bytes
- Tested with Adafruit Feather 32u4 and Teensy 2.0
- Can write and read (verify) both flash and eeprom memory
- Also reads signature/lock/fuse bytes
- Sample pyusb driver program included
- Works with Linux; other platforms may work but not tested
ubaboot uses a custom (vendor-defined) USB protocol. See below for details.
The included ubaboot.py
driver program can upload and verify firmware.
You must configure ubaboot to work with your board. See config.h
.
- Install dependencies:
- avr-gcc
- avr-libc
- make
- avrdude
- pyusb
- Edit
config.h
to set required and optional configuration. - Build via
make
. - Set your fuses for a 512 byte bootloader.
- Program your board via "make program". This uses
avrdude
to flash the firmware; setAVRDUDE_PROGRAMMER
in theMakefile
for your programmer. - Install a udev rule so you can use your device without root privilege.
- Use
ubaboot.py
to load programs via the bootloader.
Required configuration:
- Choose a vendor and product ID.
- Set crystal/oscillator frequency for your board.
- Set low-speed mode if using the internal RC oscillator.
- Enable USB voltage regulator if needed for your board.
Optional configuration:
- Setup registers and pin number for blinky USB activity LED.
Note: ubaboot does not come with a USB vendor ID/product ID. You must configure one before using ubaboot.
All operations are control transfers type vendor and recipient device.
Returns the three device signature bytes.
SETUP field | Value |
---|---|
bmRequestType | 0xc0 |
bRequest | 1 |
wValue | ignored |
wIndex | ignored |
wLength | 3 |
Reads program flash memory.
SETUP field | Value |
---|---|
bmRequestType | 0xc0 |
bRequest | 2 |
wValue | address to read |
wIndex | ignored |
wLength | length to read |
Address and length need not be aligned to flash pages.
Writes program memory.
SETUP field | Value |
---|---|
bmRequestType | 0x40 |
bRequest | 3 |
wValue | address to write |
wIndex | ignored |
wLength | length to write |
Both address and length must be aligned to page boundary (128 bytes for atmega32u4).
Allow 20 ms timeout per page being programmed.
Reboots into the target program.
SETUP field | Value |
---|---|
bmRequestType | 0x40 |
bRequest | 4 |
wValue | ignored |
wIndex | ignored |
wLength | 0 |
Reads EEPROM memory.
SETUP field | Value |
---|---|
bmRequestType | 0xc0 |
bRequest | 5 |
wValue | address to read |
wIndex | ignored |
wLength | length to read |
Writes EEPROM memory.
SETUP field | Value |
---|---|
bmRequestType | 0x40 |
bRequest | 6 |
wValue | address to write |
wIndex | ignored |
wLength | length to write |
Allow 10 ms timeout per byte being programmed.
Reads the fuse bytes and lock byte.
SETUP field | Value |
---|---|
bmRequestType | 0xc0 |
bRequest | 7 |
wValue | ignored |
wIndex | ignored |
wLength | 4 |
The bytes are returned in the following order:
Offset | Value |
---|---|
0 | low fuse |
1 | lock byte |
2 | extended fuse |
3 | high fuse |
The firmware allows max 64 kib transfers but your USB stack might not.
libusb on linux is limited to 4 kib per control transfer.
Thank you Richard Woodbury for reviewing lots of code and testing!
Copyright 2017 by Robert Evans (rrevans@gmail.com)
ubaboot is licensed under the terms of GPLv3. See LICENSE for details.
This documentation is licensed under the terms of CC BY-SA 4.0