Bootloader

From STM32duino wiki
Jump to: navigation, search

This page contains information about the STM32duino Bootloader, for instructions for how to flash the bootloader, see Burning the bootloader.

Standard STM bootloader

All STM32 MCUs embed a standard bootloader preloaded by STM in a rom section.
This standard bootloader is always available (cannot be modified or deleted) and can be activated by thoroughly setting the boot pins available in each version.
Anybody can always use the standard STM bootloader to upload firmware in the MCU.
Different MCUs have different standard bootloaders supporting different devices.
For details about the standard STM bootloaders available in each MCU you can refer to doc. AN2606:
http://www.st.com/content/ccc/resource/technical/document/application_note/b9/9b/16/3a/12/1e/40/0c/CD00167594.pdf/files/CD00167594.pdf/jcr:content/translations/en.CD00167594.pdf

Original Maple bootloader and stm32duino bootloader

STM32F103 MCUs embed a standard USART bootloader bound to USART1.
The bootloader can be activated by setting:

  • boot0 = HIGH
  • boot1 = LOW

and then resetting the device.
In order to simplify the upload process leveraging the USB device, Leaflabs developed a custom DFU bootloader that needs to be uploaded in the MCU at address 0x08000000 via one of the standard STM upload methods (ST Link or standard STM serial bootloader); this custom bootloader is called the original Maple bootloader.
Leaflabs' documentation about the original Maple bootloader can be found here: http://docs.leaflabs.com/static.leaflabs.com/pub/leaflabs/maple-docs/latest/bootloader.html

stm32duino.com guys modified the original Maple bootloader in order to:

  • enable support for STM32F103 non-Maple boards (blue pill and other generic boards)
  • fix issues found in the original Maple bootloader
  • reduce the bootloader size so that enlarging the memory available to user sketches
  • remove the option to upload to RAM

This modified version of the Maple bootloader is known as STM32duino-bootloader or also bootloader 2.0.
Details about the STM32duino-bootloader as well as ready to use binary files can be found in the Github repository: https://github.com/rogerclarkmelbourne/STM32duino-bootloader

Notes:

  • Maple devices (including clones) generally come with the original Maple bootloader preloaded
  • Generic STM32F103 boards on the other side come with no custom bootloader installed


Boot0 and Boot1 Jumper settings

Normal boot (through bootloader if one is installed):
Boot0 = 0
Boot1 = 0

Use native bootloader on UART1:
Boot0 = 1
Boot1 = 0

Not used:
Boot0 = 0
Boot1 = 1

Boot from RAM (not implemented in v2.0 bootloader)
Boot0 = 1
Boot1 = 1


Building the Bootloaders

Tested on Linux Mint 17.3 - Arduino 1.6.12
I believe this is the same process I used on Mint 17.2 and Arduino 1.6.5.
Make sure that you have a bin subdirectory in your home folder and that it is in your path.

echo $PATH
ls ~/bin

Create the bin folder if it does not exist.

mkdir ~/bin

Locate the arm compiler used by STM32duino. From the home folder enter

find | grep -i arm-none-eabi-gcc$
./.arduino15/packages/arduino/tools/arm-none-eabi-gcc
./.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gcc

The second line is the one you want.
Create symbolic links to all the arm tools in your ~/bin folder.

$ ln -s ~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gcc ~/bin/arm-none-eabi-gcc
$ ln -s ~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ ~/bin/arm-none-eabi-g++
$ ln -s ~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-ar ~/bin/arm-none-eabi-ar
$ ln -s ~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-objcopy ~/bin/arm-none-eabi-objcopy
$ ln -s ~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-objdump ~/bin/arm-none-eabi-objdump
$ ln -s ~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-size ~/bin/arm-none-eabi-size
$ ln -s ~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-nm ~/bin/arm-none-eabi-nm

Download and unzip the bootloader files [1] and save somewhere convenient. Change to that folder.

chmod +x make_all.bat

Execute make_all.bat. Even though this is a Windows batch file, there is nothing there that keeps it from running on Linux.

./make_all.bat

This should take a minute or so.
md5sum one of the new files and compare with the same file in the repository. This ensures that the newly created binary matches the original.

md5sum binaries/maple_rev5_boot20.bin 
be310d2430bc6c674849bf17ef63b435  binaries/maple_rev5_boot20.bin
md5sum ~/Downloads/maple_rev5_boot20.bin
be310d2430bc6c674849bf17ef63b435  /home/fred/Downloads/maple_rev5_boot20.bin

The files match, so you are ready to compile a custom bootloader.