How to I add a new Burn Bootloader feature ?

Hi,

There doesn't appear to be any documentation about how the Burn Bootloader feature works.

I'd like to add the option to burn a special custom bootloader to the STM32 using the IDE, rather than needing to do it via the command line, but I'm at a loss about which files need to be ammended

I presume its setup somewhere in boards.txt, platform.txt or programmers.txt, but I've no idea where to even start looking

Does anyone know how the Burn Bootloader feature is configured in these files ?

Thanks

Why don't you try the first hit on Google?

They're pretty well explained there, honestly.

Hi DrAzzy

I think you are referring to the section that reads

Upload using an external programmer

TODO...
Burn Bootloader

TODO...

It also says

Each action has its own recipe and its configuration is done through a set of properties having key starting with tools prefix followed by the tool ID and the action:

tools.avrdude.bootloader.pattern=[......]
[.....]

Its kind of difficult working with this level of documentation

I think I may need to reverse engineer the Java of the IDE its self

I never noticed that, quite frankly - after reading the first part of that, and looking at an existing platform.txt, I didn't feel like there were big gaps left behind.

Just like the other recipes, you define a programmer, and a command to execute (with all the parameters), and the IDE substitutes values (from boards.txt and menus) into the curlybraces. If you look at an existing core, it's honestly pretty clear what it's doing - the third party hardware format is pretty sensible (at least the three .txt files )

Hmm. And the existing ARM platforms (Due) don't seem to have "burn bootloader" functionality, so AVR is the only existing example? grr.

Do you have a few examples of the commands that some various ST boards would use to burn a bootloader?

@westfw

umm.
Its a bit complicated - Sorry this is probably going to be a rather verbose response.

We can burn the bootloader using 2 or 3 different "programmers"

i.e The bootloader can be burnt using USB to Serial, using the stm32flash utility, or using the STLink programmer - or using the Black Magic Probe (But STLink and BMP are basically the same sort of thing as they are SWD programmers)

Users have the option to upload using any of the above for normal sketch uploads, if they won't want to have a bootloader on the board.

Actually until recently we didn't have a version of the bootloader that would work with "Generic" STM32F103 boards (i.e basically most boards you can find on AliExpress or TauBao etc) - we only had a bootloader for Maple mini (and clones of that board)

Anyway.

The bootloader functionality would need to do a few things.

  1. For "Generic" STM32F103 boards, it would need to allow the user to select their board variant - in practice they just need to select the bootloader that flashes the LED on the board, but there is no standard for which pin the LED is attached to - hence we have a lot of different bootloaders which are 99% identical.

  2. The user would also need to be given the option of which programmer to use, i.e USB to Serial or STLink or Black Magic Probe

I suspect adding additional programmers to the list is the simpler of the challenges, as there is a file called Programmers.txt which appears to list the programmers.

For bootloader selection, we can't use the Board menu, because in the IDE we don't select board based on where the LED is attached, we select the board based on the device density / hardware facilities

e.g.

We have the following in the boards menu

"Generic STM32F103C Series"
"Generic STM32F103R Series"
"Generic STM32F103V Series"
"Generic STM32F103Z Series"

Then within these boards there is a sub menu for flash / ram size
(well this is a slight simplification, but its basically the system)

Anyway.

The burn bootloader would need to run a script / bat file, which would prompt the user to select the bootloader variant from a list (probably a list of numbers to choose from with the details e.g. LED pin next to each number"

But I'm not sure if interactivity is allowed by the IDE in the scripts it calls, or whether possibly we'd need to run a small java program to handle the bootloader bin selection

Anyway.

At the moment, I just get null pointer exceptions when I try to add new programmers and even when I try to add the xxx.bootloader.tool stuff into boards.txt

e.g.

genericSTM32F103Z.bootloader.tool=bootloader_upload

even if I select an existing programmer

So I presume I'm missing something in platform.txt

I suspect I need to add some recipies to platform.txt e.g.

tools.MYTOOL.erase.params.verbose=-v
tools.MYTOOL.erase.params.quiet=-q -q
tools.MYTOOL.erase.pattern="{cmd.path}" "-C{config.path}" {erase.verbose} -p{build.mcu} -c{protocol} {program.extra_params} -e -Ulock:w:{bootloader.unlock_bits}:m -Uefuse:w:{bootloader.extended_fuses}:m -Uhfuse:w:{bootloader.high_fuses}:m -Ulfuse:w:{bootloader.low_fuses}:m

tools.MYTOOL.bootloader.params.verbose=-v
tools.MYTOOL.bootloader.params.quiet=-q -q
tools.MYTOOL.bootloader.pattern="{cmd.path}" "-C{config.path}" {bootloader.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{runtime.platform.path}/bootloaders/{bootloader.file}:i" -Ulock:w:{bootloader.lock_bits}:m

But I was hoping that there was some docs for this somewhere, or perhaps some other third party hardware setup for bootloaders e.g. ESP8266 that I could look at

But I"ve not found any.

So it looks like its just a case of trying things and seeing what works (which is not a particularly efficient use of time)