cancel
Showing results for 
Search instead for 
Did you mean: 

Why do we need a bootloader in a microcontroller

B.Montanari
ST Employee

Why do we need a bootloader in a microcontroller?

1. Programming without JTAG/SWD probes

There are a few reasons a bootloader is needed in a microcontroller, including the main one: programming/updating the user application without the need of JTAG/SWD probes with the desired level of security needed by the application. In this article, we give an overview of why it is needed and how to make use of the built-in system memory bootloader available in all STM32 microcontrollers or create a custom one based on our extensive offer. This relatively small piece of code allows the programmer to initialize the processor and peripherals, program, verify and load the application into the flash memory directly and, of course, perform firmware upgrades.
 

2. STMicroelectronics bootloader offer

ST has two main offers when it comes to bootloader, one is ST’s native bootloader, called system bootloader, and the other one is what we call as In-Application Programming (IAP). Both approaches allow the user to program the Flash memory and Option Bytes, the main difference is that the system bootloader resides outside the user Flash memory, located in a dedicated ROM region and, because of that, follows a pre-defined activation pattern with specified protocols according to the interface used. The IAP on the other hand is much more flexible but will consume user Flash memory.
Let’s dive deeper into the topic to see where we can find the related documentation for the system bootloader and how we can develop the IAP leveraging from the available packages.
 

3. STM32 system bootloader documentation

When using the STM32 system bootloader, the base documentation for understanding the activation patterns, pins used and available interfaces is the AN2606, it is a generic guide that covers the supported protocols, peripherals, hardware requirements, and possible configurations for all STM32 series. Given that the system bootloader can support several communication interfaces, such as: UART, SPI, I2C, USB DFU, CAN and FDCAN, depending on the STM32 device, we recommend first using the AN2606 to understand what is available for your chosen MCU and then check the respective application note related to the interface, here you can find all of them:
AN2606: STM32 microcontroller system memory boot mode
AN3155: USART protocol
AN4286: SPI protocol
AN4221: I2C protocol
AN3156: USB DFU protocol
AN3154: CAN protocol
AN5405: FDCAN protocol
An easy way to test the system bootloader is by leveraging the ecosystem available, including the STM32CubeProg and the STLINKV3-SET, these two combined allow a seamless test to take place, as the STLINK V3-SET has all the hardware needed to validate the mentioned interfaces and the STM32CubeProg is a software that comes with an easy-to-use GUI and CLI, both supporting the native boot.
Now that we know the foundation of the native boot, let’s explore more about the available content related to IAP. We must not forget that an important feature for most applications is its security and safe boot process. Fortunately, ST has the “Secure Boot and Secure Firmware Update” (SBSFU) to ease this process of creating a solution. You can find more information about this process in our wiki page and in our dedicated page, listing all our available trainings and contents for the subject.
Regarding the basics surrounding a custom bootloader, we provide a video series called “How to create a super simple bootloader”, where the foundation, such as linker script manipulation, jumping from one code to another and adding offset to the interrupt vector is explored. There is also a dedicated portion aiming to show a simple way your code can share an API between application and custom boot, reducing the overall Flash memory usage. This video series will not dive into the actual Flash memory programming or how to use a given protocol, this is covered with these application notes and firmware packages:
X-CUBE-IAP-SD: In-application programming with SD cards software expansion for STM32Cube (AN4854)
X-CUBE-IAP-USART: STM32Cube in-application programming using the USART embedded software (AN4657)
In summary, a bootloader is a great asset in real life applications, as it can range from simply programming the Flash memory in an easy way without necessarily relying in programming probes to allowing your product to ensure a valid code is installed, a way to update and even rollback to a previous stable version and establish a root of trust if needed.
Hope you enjoyed the article!

Comments
skydiveh
Associate II

For me the article gave me a good insight were to search for more information.

Ahmet Yasin CİVAN
Associate III

Thank you for sharing.

Javier1
Principal

This is very helpful , thanks @Laura C.​ 

LauraCx
ST Employee

Thanks to @B.Montanari​ 

Version history
Last update:
‎2022-12-13 04:43 AM
Updated by: