on
2021-04-28
3:57 AM
- edited on
2025-08-06
6:30 AM
by
Laurids_PETERSE
This article provides information about the STM32 boot process. In the first part, it gives you an overview of this process and it presents the different boot modes. In the second part, it details the STM32 system bootloader and the STM32 boot from internal user flash memory.
Note that the STM32 microprocessors are not covered by this FAQ. For more information, see the dedicated wiki page.
All the STM32 microcontrollers are able to boot from the following:
For STM32 microcontrollers, these are the only three possible boot targets.
The answer is available in the reference manual of your STM32 in the chapter "Boot configuration".
Below is an example of a boot configuration definition for a STM32G071:
See section 2.5 page 68 of RM0444 Reference Manual STM32G0x1.
According to the STM32 selected, this configuration depends on a combination of
Pin values:
Warning: in RDP level 2, the device can only boot from main flash memory.
When an STM32 is powered on, the embedded flash memory automatically loads the option bytes. During the option bytes loading sequence, the device remains under reset and the embedded flash memory cannot be accessed. The values on the BOOT pin are latched on the fourth rising edge of SYSCLK after reset release. Afterwards, the boot mode configuration is resolved.
The bootloader is stored in the internal boot ROM (system memory part of the flash) of any STM32 device, and is programmed by ST during production. Its main task is to download the application program to the internal flash memory through one of the available serial peripherals, such as USART, CAN, USB, I²C, or SPI.
This application note, AN2606 STM32 microcontroller system memory boot mode, gives all the details about:
Note: on some STM32 microcontrollers with flash empty check mechanism, it is not possible to jump in the bootloader from your application running in the user flash. All the details are described in this application note.
To check if you properly activated the bootloader, or to investigate any communication issue with the bootloader, you could follow our related MOOC: STM32 boot and startup tips MOOC
For each communication interface (CAN/USART/USB/I2C/SPI/FDCAN), a dedicated application note describes the protocol:
All STM32 microcontrollers are based on the Arm Cortex®-M core. The boot process of this core is:
On many STM32 families, the boot address in the internal flash is 0x0800_0000. This address is remapped to address 0x0000_0000 by the boot mode mechanism. The address located at 0x0000_0004 will point on the reset handler.
On some families like the STM32H7 or STM32L5, the boot address could be different and specified thanks to the option bytes.
Keep in mind, the first 32-bit word of your binary is the main stack pointer location and the second 32-bit word is the address of the reset handler.
The reset handler implementation can be found in an assembly file named for example startup_stm32g071xx.s (naming depends on the targeted device).
This file should be present in your STM32 project.
Depending on your IDE, you can find the implementation in the CMSIS package include in the STM32CubeFirmware.
For example in a STM32CubeIDE project, you can set a breakpoint in the file startup_stm32g071xx.s at those lines:
Reset_Handler:
ldr r0, =_estack
mov sp, r0 /* set stack pointer */
And then debugging the startup of the target.
This article provided information about the STM32 booting process. It gave you an overview of:
Good article.
Consider changing "Depending on you IDE" to "Depending on your IDE".
I have question about SPI interfaces and the boot selection. I am not using SPI and I don't want it selected.
Issue 1: AN2606 says that to prevent SPI from being selected, SPI_MOSI should be at a known state (high or low) at the start of the selection process. I'm wondering if keeping SCK at a known, unchanging state (high or low) would also prevent the interface from being selected. It also seems that keeping NSS high would also prevent that interface from being selected.
Issue 2: I have a design where I use an STM32 analog input, which is connected to an op-amp output. That pin also happens to be SPI_MISO of one of the possible bootloader SPI interfaces. AN2606 says that SPI_MISO during boot mode selection is an output, which in my case would imply that the SPI_MISO pin is driving out into my op-amp output. I put a 1K resistor between the pins to prevent contention. I'm wondering if SPI_MISO is actually tri-stated, and would only drive out if NSS and SCK performed an SPI data transaction.
Hello,
Why is the reset handler initializing the SP value again when it is automatically being done after reading the 0x00 address?