volium / nanoBoot

nanoBoot - 512 byte USB HID Bootloader for ATmega16U4/ATmega32U4
Other
27 stars 12 forks source link

How to upload code to atmega32u4 with nanoBoot? #17

Open gitboy555 opened 2 years ago

gitboy555 commented 2 years ago

Hi!

I found this 512 byte bootloader called nanoBoot and successfully flashed it on an atmega32u4 board. It goes to bootloader mode when I do the HW reset so that means it's working fine. My issue now is I don't know how to upload code to it. Can I use AVRDUDE to upload or flash code to it?

sigprof commented 5 months ago

You can use the hid_bootloader_cli tool, which is a modification of teensy_loader_cli (the USB protocol is actually the same, but the USB IDs need to be different from the PJRC-owned ones, and the Teensy tool does not support third-party USB IDs, so it needed to be forked). Unfortunately, you may need to compile the tool from source yourself, because at the moment the only place which has that tool packaged is MSYS2 (at least Repology does not know anything else).

There is also a Python implementation of the flashing tool, which might be easier to get running (but it also needs the hidapi and intelhex Python packages, and at least hidapi depends on a native library).

Also apparently there is a way to use the teensy programmer support in recent versions of avrdude, but that requires supplying a custom avrdude.conf (it seems to be the only way to override the usbvid and usbpid parameters), and using -F (to ignore the HID usage mismatch) and -V (disable verification, because the bootloader does not support reading — although that issue applies to the original Halfkay bootloader too), and still produces some warnings about inability to read the flash to get the pad bytes for the last incomplete page. And avrdude must be built with the hidapi support enabled, which might not be the case in all distros (e.g., in Nixpkgs that option had been enabled around 2024-04-15, and apparently uses libhidapi-libusb instead of libhidapi-hidraw, which causes some problems).