daskygit / nanoBoot

nanoBoot - 512 byte USB HID Bootloader for ATmega16U4/ATmega32U4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nanoBoot

Build Status

This repository contains the source code for the USB HID-based bootloader for ATmegaXXU4 family of devices.

The name nanoBoot comes from the fact that the compiled source fits in the smallest available boot size on the ATMegaXXu4 devices, 256 words or 512 bytes. The code is based on Dean Camera's LUFA USB implementation, but it is EXTREMELY streamlined, size-optimized and targeted for the ATmega16U4 and ATmega32u4 devices; I had to make quite a few hardware assumptions, mostly to the fuse settings related to clock configuration for things to be as compact as possible, but the code still allows for some flexibility.

It's very likely that a few sections can be rewritten to make it even smaller, and the ultimate goal is to support EEPROM programming as well, although that would require changes to the host code.

The current version (commit #d0ea26b) is supported as-is in the 'hid_bootloader_loader.py' script that ships with LUFA-151115, and is exactly 506 bytes long.

HW assumptions:

  • CLK is 16 MHz Crystal and fuses are setup correctly to support it:

    • Select Clock Source (CKSEL3:CKSEL0) fuses are set to Extenal Crystal, CKSEL=1111 SUT=11
    • Divide clock by 8 fuse (CKDIV8) can be set to either 0 or 1
  • Bootloader starts on reset; Hardware Boot Enable fuse is configured, HWBE=0

  • Boot Flash Size is set correctly to 256 words (512 bytes), StartAddress=0x3F00, BOOTSZ=11

  • Device signature = 0x1E9587

  • Fuse Settings:

    • lfuse memory = 0xFF or 0x7F (CKDIV8=1 or 0, 16CK+65ms)
    • hfuse memory = 0xD6 (EESAVE=0, BOOTRST=0)
    • efuse memory = 0xC7 (=0xF7, No BOD)
  • Alternatively, BOD can be used to ease CKSEL-SUT setting requirements to allow teensy-like FUSE settings:

    • lfuse memory = 0x5F (CKDIV8=0, 16CK + 0ms)
    • hfuse memory = 0xDF (EESAVE=1, BOOTRST=1)
    • efuse memory = 0xF4 (BOD=2.4V)

The documentation is part of the source code itself, and even though some people may find it extremely verbose, I think that's better than lack of documentation; after all, assembly can be hard to read sometimes... ohhh yes, in case that was not expected, this is all written in pure GAS (GNU Assembly), compiled using the Atmel AVR 8-bit Toolchain.

About

nanoBoot - 512 byte USB HID Bootloader for ATmega16U4/ATmega32U4

License:Other


Languages

Language:Assembly 74.5%Language:Makefile 22.7%Language:Python 2.7%Language:Batchfile 0.1%