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 microcontrollers contain a standard bootloader preloaded by ST Microelectronics.

The standard ('factory', 'native', 'STM') bootloader is always available -- being stored in read-only memory -- and cannot be modified or deleted. You can access it by configuring the boot pins high or low, and then powering (or resetting) the MCU.

Through the standard bootloader you can upload firmware to the MCU. This can either be an application (Arduino sketch) or another 'non standard' bootloader with more features.

Different STM32 device families offer different capabilities in their factory bootloaders. For example, some support uploading firmware over USB while others do not. An example of the latter is the popular F103 series.

For details about the standard bootloaders available in each MCU you can refer to ST application note AN2606.

Original Maple bootloader and stm32duino bootloader

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: 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:


  • 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 pin settings

Activating the bootloader is done through forcing two boot pins (and then resetting the MCU). Many boards have one or more boot pins exposed as jumpers or push buttons.

Normal boot (to user firmware, which may be a secondary bootloader):

  • Boot0 LOW
  • Boot1 LOW

Allow firmware upload through USART1:

  • Boot0 HIGH
  • Boot1 LOW

Not used:

  • Boot0 = LOW
  • Boot1 = HIGH

Boot from RAM (not implemented in v2.0 bootloader):

  • Boot0 HIGH
  • Boot1 HIGH

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$

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.


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.