Getting started with STM32
Welcome to the first guide in a series of guides. This guide is intended for beginners (hobbyists, students) who want to get started with STM32 microcontrollers but don’t know how to or where to get started.
This guide gives you an overview of the available hardware and software for working with STM32 microcontrollers. Also, it will briefly introduce you to the STM32 family of microcontrollers.
All guides, except this one, assume you will be using the STM32-base project. To be able to follow the following guides, you will need a basic understanding of the C programming language. Prior experience with an embedded platform is not required.
Introduction to STM32
STM32 does not refer to one specific microcontroller. It is the name STMicroelectronics gave to their ARM Cortex-M based microcontroller family. The STM32 family itself can be divided into multiple groups, which in turn can be divided into series.
The STM32 family currently consists of fifteen series. These series are grouped in four different groups: High Performance, Mainstream, Ultra Low Power, and Wireless. The following list briefly describes each series:
- STM32F0 (Mainstream)
Based on the Arm Cortex-M0 processor. Optimized for low cost. Designed to compete with 8-bit and 16-bit platforms.
- STM32F1 (Mainstream)
Based on the Arm Cortex-M3 processor. General purpose.
- STM32F2 (High Performance)
Based on the Arm Cortex-M3 processor. General purpose. Optimized for high performance.
- STM32F3 (Mainstream)
Based on the Arm Cortex-M4 processor with FPU and DSP instructions. Optimized for mixed signal applications.
- STM32F4 (High Performance)
Based on the Arm Cortex-M4 processor with FPU and DSP instructions. Optimized for high performance.
- STM32F7 (High Performance)
Based on the Arm Cortex-M7 processor with FPU and DSP instructions. Optimized for high performance. Pin-to-pin compatible with STM32F4 series.
- STM32G0 (Mainstream)
Based on the Arm Cortex-M0+ processor. Optimized for efficiency. Designed to compete with 8-bit and 16-bit platforms.
- STM32G4 (Mainstream)
Based on the Arm Cortex-M4 processor with FPU and DSP instructions. Optimized for mixed signal applications. Successor of STM32F3 series.
- STM32H7 (High Performance)
Based on the Arm Cortex-M7 processor with FPU and DSP instructions. Some devices have a second Arm Cortex-M4 based co-processor.
- STM32L0 (Ultra Low Power)
Based on the Arm Cortex-M0+ processor. Optimized for low power applications.
- STM32L1 (Ultra Low Power)
Based on the Arm Cortex-M3 processor. Optimized for low power applications.
- STM32L4 (Ultra Low Power)
Based on the Arm Cortex-M4 processor with FPU and DSP instructions. Optimized for low power applications.
- STM32L4+ (Ultra Low Power)
Based on the Arm Cortex-M4 processor with FPU and DSP instructions. Optimized for low power applications. Higher performance than the STM32L4 series.
- STM32L5 (Ultra Low Power)
Based on the Arm Cortex-M33 processor. Optimized for low power applications. Improved security.
- STM32WB (Wireless)
Based on the Arm Cortex-M4 processor with FPU and DSP instructions. Features a second Arm Cortex-M0+ processor as network processor. Supports both Bluetooth 5 and IEEE 802.15.4 wireless standards.
You will need at least one development board to get started. Without a development board, you can not run or debug your code properly. If you already own a development board, you can skip this chapter.
The STM32 family consists of many different microcontrollers. Picking one is hard for a beginner. Luckily, most things you will need to learn first are common to all microcontrollers in the STM32 family. This means you can start with virtually any STM32 microcontroller.
Both series are around for a long time and are still popular among hobbyists. This means that there are a lot of resources available for devices in these series. Also, the devices in the STM32F1 series are not as complex as most other parts.
Most development boards are designed to work with as few components as possible. They are designed this way to be as cheap as possible and to not limit the user in any way. There are also boards that feature additional components such as LEDs, sensors, and memories.
Most pins, if not all, of the microcontroller are exposed via headers for easy access. There is also at least one dedicated header for connecting a debugger.
Development boards are manufactured by different parties. STMicroelectronics offers three different ranges of development boards:
- Nucleo boards
These boards are very similar to Arduino boards. They feature only the microcontroller and a builtin ST-Link debugger. There are three form factors available.
- Discovery kits
These boards all contain input and output devices in addition to the microcontroller. These boards also come with a builtin ST-Link debugger.
- Evaluation boards
These boards are very extensive and feature many extra devices and interfaces in addition to the microcontroller.
Both the Nucleo and Discovery boards are very well suited for absolute beginners. They are guaranteed to work properly and include a builtin debugger. And all this for reasonable prices. If you are in a very thight budget, you can buy one of the Chinese development boards. The following boards are recommended for beginners:
This board features an STM32F103RBT6 device with 128kB of FLASH memory.
This board features an STM32F407VGT6 device with 1024kB of FLASH memory.
- Black Pill
This board features an STM32F103C8T6 device with 64kB of FLASH memory. Be sure to also buy an ST-Link clone for debugging and flashing.
If you want to get started with the STM32-base project, you don’t have to make a lot of choices on the software side. The STM32-base project is designed to be used with the GNU Arm Embedded Toolchain. STM32-base can be used with you favorite code editor. A recommendation for an editor is Visual Studio Code.
Other software discussed in this chapter can be used when you do not want to use the STM32-base project. The other software is discussed to give you a better overview of all available software for STM32 microcontrollers.
IDE stands for Integrated Development Environment. This usually means that, once installed, an IDE is ready to be used without any further actions required. IDEs install all required software, like compilers and drivers, once they are installed.
Some IDEs are free, others require a licence to be bought. The IDEs listed here are potentially interesting to beginners and hobbyists since they’re free. For a complete overview of available IDEs, refer to the ST website.
- Arm Keil MDK - Free for STM32G0, STM32F0, and STM32L0 series (Windows)
- PlatformIO IDE - Free (Windows, Linux, macOS)
- STM32CubeIDE - Free (Windows, Linux, macOS)
- Segger Embedded Studio - Free for non-commercial use (Windows, Linux, macOS)
- SW4STM32 - Free (Windows, Linux, macOS)
Platforms offer, in addition to an IDE, their own API for controlling a device. Platforms like these are usually aimed at prototyping. There are two platforms available for STM32 microcontrollers.
The second one is Arm Mbed. This platform supports not only STM32 microcontrollers. It supports a wide range of devices from different vendors. Mbed includes an OS specifically developed for IoT applications. It has both an cloud based IDE and a downloadable variant.
ST offers an CMSIS and HAL for each device series. The CMSIS contains all the register and peripheral definitions needed to make use of the available peripherals on a microcontroller. The HAL is a higher level library that offers portability of code between different series. The CMSIS and HAL code is distributed in so-called STM32Cube packages.
A popular open-source alternative to the official CMSIS is libopencm3. This project aims to create an open-source firmware library for Arm Cortex-M microcontrollers. Not all STM32 series are supported.