How does the Braids bootloader work?

Hi All, I was looking through the repository for braids and am a bit confused as to how everything comes together. In particular I noticed that there seems to be a main function in the boot loader code as well as the braids.cc file. It’s a bit hard for me to follow, I was wondering if anyone could explain t me whats going on there or maybe point me towards a relevant app note.

The bootloader is compiled and linked with a linkerscript that places the interrupt vector and code at 0x08000000 (beginning of flash).

The application code is compiled and linked with a different linkerscript that places the interrupt vector and code at 0x08004000 (16k after the beginning of the flash)

Both blocks of code are converted to .hex files and merged together in a single .hex file - so effectively the first 16k of flash contain the bootloader, and the rest the application code.

When the module is powered on, the processor boots with the interrupt vector and code at 0x08000000, so it starts running the bootloader code. It either stays there if the encoder is pressed; or it leaves the white (!exit_updater) loop. In which case, the processor is reset and the program counter is forced to address 0x08004000, so it jumps to the main application code. One of the very first things done in the application code is to set the interrupt vector table to 0x4000 - so that it doesn’t use the interrupt table at the beginning of the flash.

Note that none of this requires any kind of specific hardware support for a bootloader (as is the case on AVR for example).

Thanks for the explanation. That’s very cool how that works. I’ve been developing for an arm cortex-m0 based Bluetooth LE module for just under a year, but all the software is written using the vendor’s SDK. I’ve been learning more and more about the architecture in my spare time to aid in debugging. Being able to look through the code for these modules has been a great help, thanks again.