STM32 Overview
Presented by Ing. Davide Giacalone, Advanced Research Engineer, SRA
STM32 is more than a CPU
The STM32 microcontroller family, exemplified by the STM32F7 Cortex-M7, offers extensive connectivity to various peripherals. These include:
- Quad-SPI Flash
- I2S / TDM / DFSDM
- Camera Interface
- SPDIF
- Ethernet
- USB
- SD Card
- SPI, UART, CAN, I2C interfaces
- TFT-LCD controller and MIPI®-DSI
STM32 Families Overview
STMicroelectronics offers a broad range of STM32 microcontrollers categorized by performance and power consumption:
High Performance
- STM32F2: 398 CoreMark, 120 MHz Cortex-M3
- STM32F4: 608 CoreMark, 180 MHz Cortex-M4
- STM32F7: 1082 CoreMark, 216 MHz Cortex-M7
- STM32H7: Up to 3224 CoreMark, Up to 550 MHz Cortex-M7, 240 MHz Cortex-M4
Mainstream
- STM32G0: 142 CoreMark, 64 MHz Cortex-M0+
- STM32F0: 106 CoreMark, 48 MHz Cortex-M0
- STM32F1: 177 CoreMark, 72 MHz Cortex-M3
- STM32G4: 569 CoreMark, 170 MHz Cortex-M4
- STM32F3: 245 CoreMark, 72 MHz Cortex-M4
Ultra-low-power
- STM32L0: 75 CoreMark, 32 MHz Cortex-M0+
- STM32L1: 93 CoreMark, 32 MHz Cortex-M3
- STM32L4: 273 CoreMark, 80 MHz Cortex-M4
- STM32L4+: 409 CoreMark, 120 MHz Cortex-M4
- STM32L5: 443 CoreMark, 110 MHz Cortex-M33
- STM32U5: 651 CoreMark, 160 MHz Cortex-M33
Wireless
- STM32WL: 162 CoreMark, 48 MHz Cortex-M4, 48 MHz Cortex-M0+
- STM32WB: 216 CoreMark, 64 MHz Cortex-M4, 32 MHz Cortex-M0+
STM32F4 Series Comparison
Product line | FCPU (MHz) | Flash (KB) | RAM (KB) | ART Accelerator™ | FSMC (NOR/ PSRAM/LCD) support | QSPI | DFSDM | DAC | DMA | USB 2.0 OTG FS | TFT LCD Controller | MIPI DSI | TRNG |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
STM32F469/479 | 180 | Up to 2056 | Up to 384 | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
STM32F429/439 | 180 | Up to 2056 | Up to 256 | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | No | Yes |
STM32F427/437 | 180 | Up to 2056 | Up to 256 | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | No | Yes |
STM32F446 | 180 | Up to 512 | Up to 128 | Yes | No | Yes | No | Yes | Yes | Yes | No | No | Yes |
STM32F407/417 | 168 | Up to 1024 | Up to 192 | Yes | Yes | No | No | Yes | Yes | Yes | Yes | No | No |
STM32F401/411 | 84 | Up to 512 | Up to 128 | Yes | No | No | No | No | Yes | No | No | No | No |
Note: Some devices are optimized for mixed-signal applications and include features like 16 and 32-bit timers, 12-bit ADC (0.41 µs), True Random Number Generator, and Batch Acquisition Mode. They support low voltage (1.7 to 3.6 V) and operate within a temperature range of -40 °C to 125 °C.
STM32 Tools
STMicroelectronics provides a comprehensive suite of tools to facilitate STM32 development:
Hardware Development Tools
- STM32 Nucleo boards
- STM32 Discovery kits
- STM32 Eval boards
STM32 Docs
- Datasheet
- Reference Manual
STM32CubeMX
- A graphical tool for easy configuration of STM32 microcontrollers and their peripherals.
- Generates C code compliant with STM32 MCUs.
STM32CubeIDE
- A C/C++ development platform.
- Enables code generation, compilation, and debugging for STM32 microcontrollers.
The STM32 ecosystem supports various STM32 series (L, F, G, H, W, MP) across different core architectures (Cortex-M0+, M3, M4, M7, M33). STM32CubeMX and STM32CubeIDE are available for Windows and macOS.
STM32 Boards
STMicroelectronics offers various development boards to support STM32 development, including:
- STM32 Nucleo boards
- STM32 Discovery kits
- STM32 Eval boards
These boards facilitate prototyping and development, offering features like integrated ST-Link debuggers, Arduino connectors, and expansion capabilities.
Board | ST-Link | ARDUINO connector | Display |
---|---|---|---|
Custom | No | ||
STM32 Nucleo | Yes (V2.1/V3) | X | |
STM32 Discovery | Yes (V2.1/V3) | X | X |
STM32 Eval | Yes (V2.1/V3) | X | X |
STM32 Nucleo Structure
Each Nucleo board is based on one of the STM32 MCU product lines and offers two types of extension resources:
- Arduino Uno v3 connectivity: Allows connection of Arduino shields.
- Morpho headers: Provide easy access to all MCU peripherals.
Nucleo boards feature an integrated ST-LINK/V2-1 debugger and programmer, supporting drag-and-drop flash programming and targeting on-board or external STM32-based applications.
The structure includes a Mini USB connector for power and debugging, the ST-LINK/V2-1, the STM32 microcontroller, Arduino connectors, and Morpho extension headers for expanded I/O access.
STM32 Nucleo Key Assets
Key features of the STM32 Nucleo boards include:
- Flexible board power supply (through USB or external source).
- Integrated ST-Link/V2-1 for mass storage device flash programming.
- Two push buttons and two color LEDs for user interaction and status indication.
- Direct access to all STM32 I/Os via Morpho extension headers.
- Flexible prototyping capabilities.
- Unlimited expansion capabilities, allowing users to simply expose the whole STM32 portfolio to the community.
Enlarging the STM32 Nucleo Family
The STM32 Nucleo family is expanding to cover the entire STM32 portfolio, offering different pin counts and features:
- Nucleo-32: STM32 with 32 pins.
- Nucleo-144: STM32 with 144 pins.
Common features across the family include flexible board power supply (USB or external), integrated ST-LINK/V2-1 for drag-and-drop programming, one STM32 microcontroller, Arduino Uno connectors, Arduino Nano connectors, ST Zio connectors for easy add-on, ST morpho extension for direct access to all MCU I/Os, and optional Ethernet & USB OTG.
Examples of Nucleo Expansion Boards
Nucleo expansion boards offer specialized functionalities:
- Sense: Motion & environmental sensors, proximity sensors, microphones.
- Connect: BLE, Wi-Fi, Sub-GHz, NFC connectivity.
- Power Drive: Power management, LED boost.
- Move Actuate: Motor drive, actuators.
- Translate: Audio amplifiers, OpAmps.
Examples include boards for proximity and light sensing, Wi-Fi connectivity, Sub-1GHz communication, NFC, LCD drivers, motor drivers, and audio microphones. For more information, visit: http://www.st.com/en/ecosystems/stm32-nucleo-expansion-boards.html
Outline of Development Process
The development process using STM32 tools typically involves the following steps:
- Updater settings and managing embedded software packages.
- Creating a new project (for standalone MCU or board).
- Configuring the Pinout.
- Configuring Peripherals.
- Setting up the Clock Tree.
- Configuring NVIC (Nested Vectored Interrupt Controller).
- Adding Additional Software components.
- Generating the project code.
The STM32 ecosystem supports a wide range of STM32 MCUs and MPUs, from ultra-low power to high performance, across various series (STM32L, STM32F, STM32G, STM32H, STM32W, STM32MP).
Create New Project – MCUs Selector
STM32CubeMX allows users to create new projects by selecting an MCU. The MCU selector provides filters for Part Number, Core, Series, Line, and Peripherals, enabling precise selection. A detailed list of MCUs with their specifications (Flash, RAM, frequency, etc.) is displayed.
For example, the STM32F401RE is an Arm Cortex-M4 MCU with DSP and FPU, operating up to 84 MHz, featuring 512 Kbytes of Flash memory and 96 Kbytes of SRAM.
Create New Project – Board Selector
Users can also create projects by selecting a specific development board. The Board Selector offers filters for Part Number, Vendor, Type, and MCU Series. The STM32 Nucleo boards, such as the NUCLEO-F401RE, are listed with their specifications and associated MCUs.
The STM32 Nucleo-64 boards provide an affordable and flexible platform for prototyping, integrating the ST-LINK debugger/programmer and supporting Arduino Uno V3 connectivity and ST morpho headers for expansion.
CubeMX View: Pinout & Configuration
The STM32CubeMX interface provides several key configuration views:
- Pinout & Configuration: Allows detailed configuration of MCU pins and peripherals.
- Clock Configuration: Manages the MCU's clock tree.
- Project Manager: Handles project settings and software packs.
- Tools: Access to various development utilities.
The Pinout view displays a graphical representation of the MCU's pins, allowing users to assign peripheral functions to specific pins. For instance, the STM32F401RETx LQFP64 package is shown with its pinout.
Pinout & Configuration View
Within the Pinout & Configuration view, users can select peripherals from categories (System Core, Analog, Timers, Connectivity, Multimedia, Computing, Middleware) and configure their modes. The MCU pinout section visually represents pin assignments.
Peripherals Configuration Section (Set Parameters)
In the Peripherals Configuration section, users select peripherals and configure their modes. STM32CubeMX automatically assigns and configures the necessary pins. For example, when configuring TIM1, users can set its mode, clock source, channel configurations (e.g., PWM Generation), counter settings (prescaler, mode, period), and trigger outputs.
MCU Pinout Section
For advanced users, the Chip view within STM32CubeMX allows direct mapping of peripheral functions to physical pins. This feature, coupled with the conflict solver, prevents unintended pin changes. Pin functionality assignment is crucial for defining how each pin behaves.
Peripherals Configuration Section (Set Interrupts)
The Peripherals Configuration section also allows users to set up interrupts. By navigating to the NVIC (Nested Vectored Interrupt Controller) settings, users can enable specific interrupts, configure their preemption priority and sub-priority, and manage interrupt activation. This is essential for handling events like timer overflows or external pin changes.
Hello World on UART (1/2)
To implement a "Hello World" application via UART, users first check the parameter settings for USART2 in STM32CubeMX. Key settings include Baud Rate (e.g., 115200), Word Length (8 Bits), Parity (None), and Stop Bits (1). The MCU pinout highlights the USART TX and RX pins (PA2 and PA3 for USART2).
Hello World on UART (2/2)
On STM32CubeIDE, the "Hello World" UART example requires defining the `_write` function to handle character transmission and then writing the `printf` function to output the message. The `_write` function typically uses HAL_UART_Transmit to send data over the specified UART peripheral.
/* USER CODE BEGIN PFP */
int _write(int fd, char* ptr, int len) {
HAL_UART_Transmit(&huart2, (uint8_t *) ptr, len, HAL_MAX_DELAY);
return len;
}
/* USER CODE END PFP */
/* USER CODE BEGIN 2 */
printf("hello\r\n");
/* USER CODE END 2 */
LED Blinking, Solution 1 (Not Precise)
A basic LED blinking example involves configuring a specific pin (e.g., PA5, connected to LD2) as a GPIO output in STM32CubeMX. The code then toggles the pin's status and adds a delay to control the blinking speed. This method provides a simple but not precisely timed blinking effect.
/* USER CODE BEGIN 2 */
while (1) {
HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
HAL_Delay(500);
}
/* USER CODE END 2 */
LED Blinking, with Timer and Interrupt (1/2)
For more precise LED blinking, timers and interrupts are utilized. This involves enabling Timer 10 in STM32CubeMX, setting its parameters (prescaler, counter period), and enabling the related interrupt. The NVIC settings are then configured to enable the Timer 10 global interrupt.
LED Blinking, with Timer and Interrupt (2/2)
This method involves declaring a global flag (`time_elapsed`), starting Timer 10 in interrupt mode using `HAL_TIM_Base_Start_IT()`, and redefining the `HAL_TIM_PeriodElapsedCallback` function to set the flag when the timer period elapses. The main loop then checks this flag to toggle the LED and reset the flag.
volatile uint8_t time_elapsed = 0;
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
if(htim == &htim10) {
time_elapsed = 1;
}
}
/* USER CODE BEGIN WHILE */
while (1) {
if(time_elapsed) {
time_elapsed = 0;
HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
}
}
/* USER CODE END WHILE */
Led Blinking, with PWM
To achieve LED blinking with Pulse Width Modulation (PWM), specific pins are configured in STM32CubeMX. For example, PA5 can be set as TIM2_CH1. The clock source is enabled, and the counter period and pulse values are adjusted to generate the PWM signal. The code then starts the timer in PWM mode using `HAL_TIM_PWM_Start()`.
Button Interrupt (1/2)
To handle button presses using interrupts, the relevant pin (e.g., PC13, connected to the blue push button) is first checked and configured as GPIO_EXTI13 in STM32CubeMX. Subsequently, the EXTI line interrupts (e.g., EXTI line 15:10) are enabled within the NVIC settings.
Button Interrupt (2/2)
This involves declaring a global flag (`button_pressed`), redefining the `HAL_GPIO_EXTI_Callback` function to set this flag when the button is pressed, and managing the flag in the main loop. When the flag is set, the application can perform an action, such as printing a message.
volatile uint8_t button_pressed = 0;
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
if(GPIO_Pin == GPIO_PIN_13) {
button_pressed = 1;
}
}
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) {
if(button_pressed) {
button_pressed = 0;
printf("yes, you pressed a button!\r\n");
}
}
/* USER CODE END WHILE */