STM32 Boot Modes | STM32 Boot0 Boot1 Pins

In this tutorial, we’ll discuss the STM32 Boot Modes, and how to set the STM32 Boot0 Boot1 Pins‘ states to select a desired boot mode for our microcontroller. We’ll also discuss how you can easily identify the STM32 Boot0 Boot1 pins, drive them HIGH or LOW, and much more. Without further ado, let’s get right into it!

Table of Contents

  1. STM32 Boot Modes
  2. STM32 Boot0 Pin
  3. STM32 Boot1 Pin
  4. STM32 Boot0 Pin Disabled, How To Enable?
  5. Wrap Up

STM32 Boot Modes

STM32 microcontrollers support multiple boot modes that determine how the device initializes and where it fetches the initial code to execute. In this section, we’ll discuss the primart boot modes for STM32 microcontrollers.

STM32 Boot Mode Options

1) Main Flash Memory Boot: The microcontroller boots from the main flash memory, where the user application is stored. This is the most common boot mode used in production devices.

2) System Memory Boot: The microcontroller boots from the system memory, which contains the built-in bootloader. This mode is often used for firmware updates or initial programming through various interfaces such as UART, USB, or SPI.

3) Embedded SRAM Boot: The microcontroller boots from the internal SRAM, which is mainly used for debugging or special purposes.

The states of the Boot0 and Boot1 pins during reset decides which boot mode the STM32 microcontroller will go into when powered up. For example, the STM32F103 devie has the following boot modes for each state combination of Boot0 and Boot1 pins. This is almost the same for most of the STM32 microcontrollers.

STM32-Boot-Modes-Boot0-Pin-Boot1-Pin-Combinations


STM32 Boot0 Pin

The Boot0 pin is crucial in selecting the boot mode of the STM32 microcontroller. It is sampled during reset and, in combination with the Boot1 pin, it determines the boot mode.

STM32 Boot0 Pin States

  • (Boot0 = 0): When the Boot0 pin is LOW, the microcontroller typically boots from the main flash memory.
  • (Boot0 = 1): When the Boot0 pin is HIGH, the boot mode depends on the state of the Boot1 pin.

STM32 Boot0 Pin Identification

It’s very easy to identify the Boot0 pin in an STM32 microcontroller as you can see in the figure below. This is a speical function pin for the microcontroller and is not multiplexed with any GPIO functionality.

STM32-Boot0-Pin

STM32 Boot0 Pin Connection

It’s recommended to hook up the STM32 Boot0 pin to GND using a 10kΩ resistor if you’re desinging your own PCB and not planning to have any sort of bootloader (DFU) and such.

If you’re not quite sure about it and if your application will need to have a bootloader in the future or not, then you can just hook it up to a jumper or place a solder pad to make some room for a future change in plans, if any.


STM32 Boot1 Pin

The Boot1 pin works in conjunction with the Boot0 pin to select the boot mode. The combination of Boot0 and Boot1 pin states during reset determines the specific boot mode as shown in the table below:

Boot0Boot1Boot Mode
0xMain Flash Memory
10System Memory
11Embedded SRAM

STM32 Boot1 Pin Identification

On most STM32 microcontrollers, the Boot1 pin is multiplexed with a GPIO pin. It is essential to configure this GPIO pin correctly to be able to use it for boot mode selection, if needed. You need to refer to the specific STM32 datasheet for details on configuring the Boot1 pin.

For example, in the STM32F103 microcontroller’s datasheet, I could easily find out that the Boot1 pin the GPIO pin PB2 as shown in the figure below.

STM32-Boot1-Pin

STM32 Boot1 Pin Connection

If you’re pulling-down the Boot0 pin to GND to make your STM32 boot from FLASH memory always, you can just ignore the Boot1 pin and not connect anything to it. You’re free to use it as any other GPIO pin.

However, if you’re using Boot0 + Boot1 pins to select a custom boot mode, you need to connect the Boot1 to a jumper for state selection (0 or 1) and don’t forget to add a pull-up/down resistor of 10kΩ as recommended by the hardware design guidelines of STM32 microcontrollers.

STM32-Boot0-Boot1-Pin-Pull-Up-Pull-Down-Resistor-PCB-Desing-Guideline
From STM32 Hardware Design Guidelines (AN4488)


STM32 Boot0 Pin Disabled, How To Enable?

In some STM32 microcontrollers, such as the STM32G0 series, the Boot0 pin functionality is disabled by default. This means that the microcontroller will always boot from the main flash memory regardless of the Boot0 pin state. To re-enable the Boot0 pin, you need to flash some code to manually change this behavior by modifying the control registers responsible for this functionality.

Here is an example code that you can build for your target microcontroller, flash it, and run it once. Then you’ll have the Boot0 enabled and can be used for boot selection just like any other STM32 microcontroller series.

Code Example To Re-Enable A Disabled Boot0 Pin in STM32 G0


Wrap Up

In conclusion, we’ve explored different boot modes in STM32 microcontrollers, how the STM32 Boot0 Boot1 pins are used to select the boot mode option, how can we easily identify those two pins in any STM32 microcontroller, and how to desing the hardware circuit to drive the pins according to our application’s needs.

If you’re just getting started with STM32, you need to check out the STM32 Getting Started Tutorial here. And follow this STM32 Series of Tutorials to learn more about STM32 Microcontrollers Programming.

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Author
Khaled Magdy
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?

Leave a Comment