STM32_HID_Bootloader
STM32_HID_Bootloader copied to clipboard
Document how the bootloader is started
I just tried this bootloader and found it a bit unclear how it is started exactly. I think I've managed to puzzle it together from various sources, but I might be missing pieces. Here's what I found:
- The bootloader lives at 0x0, so it always starts first. Normally, it just starts the main application right away.
- If the RTC register RTC_BKP_DR4 (or DR10 in version <= 2.1) contains the magic value 0x424C, the bootloader waits for an upload instead. This can be used to start the bootloader from within the main application.
- If the BOOT1 pin is high at startup, the bootloader also waits for an upload. This can be used to force bootloader mode, even when the main application is broken. Note that the BOOT1 pin is normally used by the hardware to decide between system flash and RAM, but only when BOOT0 is 1. When BOOT0 is 0, it always boots from main flash, ignoring the value of BOOT1.
- In normal operation, the bootloader is started by a magic sequence on the serial port, that main the application must be programmed to understand (e.g. the STM32 Arduino core used must understand it). This sequence is opening the serial port, setting RTS off, toggling DTR (on-off-on-off), sending a magic string
1EAF
and closing the port. The device should then write the appropriate magic value to the RTC backup register and reset, so the bootloader starts.
I think it would be valuable to document this somehow. Maybe a little less detailed version for users might be also useful, but these details help Arduino core devs to better understand how this all fits together.
Some docs always helps when someone got into troubles