STM32 Microcontrollers

Complete guide to ST's ARM Cortex-M based MCUs - From ultra-low-power to high-performance applications

STM32 Boards

STM32 Family Overview

STMicroelectronics' STM32 family of 32-bit ARM Cortex-M microcontrollers offers a comprehensive range of performance, power efficiency, and integration options.

  • ARM Cortex-M Cores: M0, M0+, M3, M4, M7, M33
  • Performance Range: From 32MHz to 550MHz
  • Memory Options: Up to 2MB Flash, 1MB RAM
  • Rich Peripherals: USB, CAN, Ethernet, Graphics
  • Advanced Security: Cryptographic acceleration, secure boot
  • Scalable Architecture: Code compatibility across series
  • Comprehensive Ecosystem: STM32Cube tools, HAL libraries
  • Energy Efficiency: As low as 8nA in shutdown mode
  • Industrial Robustness: -40°C to +125°C operation
  • Cost Effective: Competitive pricing for features
  • Industrial Automation: PLCs, motor control
  • Consumer Electronics: Smart home devices
  • Medical Devices: Patient monitoring
  • Automotive: Body electronics, telematics
  • IoT Edge Nodes: Sensor hubs, gateways

STM32 Series Comparison

STM32 microcontrollers are organized into several series targeting different application needs:

Series Core Max Freq Key Features Target Applications
STM32L0/L1 Cortex-M0+/M3 32MHz Ultra-low-power, LCD Battery-powered devices
STM32F0 Cortex-M0 48MHz Cost-sensitive, 16-bit legacy Consumer, industrial
STM32G0 Cortex-M0+ 64MHz Value line, USB PD USB-C, smart devices
STM32F1/F2/F3 Cortex-M3 72MHz Mainstream, analog General purpose
STM32F4 Cortex-M4 180MHz DSP, FPU, Ethernet Audio, motor control
STM32F7/H7 Cortex-M7/M4 550MHz Dual-core, TFT, Chrom-ART GUI, advanced control
STM32WB Cortex-M4/M0+ 64MHz Bluetooth 5.0, Zigbee Wireless IoT
STM32WL Cortex-M4/M0+ 48MHz Sub-GHz LPWAN LoRa, Sigfox

Popular STM32 Boards

Development boards make it easy to evaluate and prototype with STM32 microcontrollers:

Nucleo-F411RE

Nucleo-F411RE

Affordable development board with Arduino connectivity

STM32F411RE 100MHz 512KB Flash 128KB RAM Cortex-M4 FPU
Learn More
Discovery-F746NG

Discovery-F746NG

High-performance board with TFT display

STM32F746NG 216MHz 1MB Flash 320KB RAM Cortex-M7 LCD
Learn More
Nucleo-L476RG

Nucleo-L476RG

Ultra-low-power board with Bluetooth

STM32L476RG 80MHz 1MB Flash 128KB RAM ULP BLE Ready
Learn More
Nucleo-WB55RG

Nucleo-WB55RG

Wireless dual-core board with BLE/Zigbee

STM32WB55RG 64MHz 1MB Flash 256KB RAM BLE 5.0 Dual Core
Learn More

STM32F4 Series Architecture

The STM32F4 series features ARM Cortex-M4 cores with DSP instructions and floating-point unit (FPU).

Block Diagram

STM32F4 Block Diagram

Key Peripherals

Peripheral Features Use Cases
GPIO Up to 140 I/Os, interrupt capability General I/O, external interrupts
Timers 16/32-bit, PWM, encoder interface Motor control, measurement
ADC/DAC 12-bit, 2.4MSPS, 24 channels Sensor reading, audio
USART/UART Up to 6 interfaces, LIN/IRDA Serial communication
SPI/I2C Up to 6/4 interfaces Sensors, displays, memory
USB OTG FS/HS with PHY Device/Host communication

Memory Map

Memory Type Address Range Size Description
Flash 0x0800 0000 Up to 2MB Program memory
SRAM 0x2000 0000 Up to 384KB Data memory
Peripherals 0x4000 0000 - AHB/APB bus access
System 0xE000 0000 - Cortex-M core peripherals

Programming with STM32CubeIDE

// Blink LED on PA5 using HAL
#include "stm32f4xx_hal.h"

int main(void) {
    HAL_Init();
    __HAL_RCC_GPIOA_CLK_ENABLE();
    
    GPIO_InitTypeDef GPIO_InitStruct = {0};
    GPIO_InitStruct.Pin = GPIO_PIN_5;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
    
    while(1) {
        HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
        HAL_Delay(500);
    }
}

Advanced STM32 Features

Direct Memory Access (DMA)

DMA allows peripheral-to-memory transfers without CPU intervention:

// ADC with DMA Example
void ADC_DMA_Init() {
    // Configure ADC
    hadc1.Instance = ADC1;
    hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
    hadc1.Init.Resolution = ADC_RESOLUTION_12B;
    HAL_ADC_Init(&hadc1);
    
    // Configure DMA
    hdma_adc1.Instance = DMA2_Stream0;
    hdma_adc1.Init.Channel = DMA_CHANNEL_0;
    hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
    hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
    hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
    HAL_DMA_Init(&hdma_adc1);
    
    // Link DMA to ADC
    __HAL_LINKDMA(&hadc1, DMA_Handle, hdma_adc1);
    
    // Start ADC with DMA
    HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_buffer, ADC_BUF_LEN);
}

Timer PWM Generation

STM32 timers can generate complex PWM signals:

// PWM Output on TIM1 Channel 1
void PWM_Init() {
    TIM_HandleTypeDef htim1;
    TIM_OC_InitTypeDef sConfigOC = {0};
    
    htim1.Instance = TIM1;
    htim1.Init.Prescaler = 84-1; // 1MHz clock
    htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
    htim1.Init.Period = 1000-1;  // 1kHz PWM
    HAL_TIM_PWM_Init(&htim1);
    
    sConfigOC.OCMode = TIM_OCMODE_PWM1;
    sConfigOC.Pulse = 500;       // 50% duty
    sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
    HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1);
    
    HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
}

FreeRTOS Integration

STM32 works well with real-time operating systems:

// Simple FreeRTOS Example
void Task1(void *pvParameters) {
    while(1) {
        HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
        vTaskDelay(500 / portTICK_PERIOD_MS);
    }
}

void Task2(void *pvParameters) {
    while(1) {
        // Process sensor data
        vTaskDelay(100 / portTICK_PERIOD_MS);
    }
}

int main(void) {
    HAL_Init();
    SystemClock_Config();
    
    xTaskCreate(Task1, "LED_Task", 128, NULL, 1, NULL);
    xTaskCreate(Task2, "Sensor_Task", 256, NULL, 2, NULL);
    
    vTaskStartScheduler();
    
    while(1);
}

STM32 Development Tools

STM32CubeIDE

STM32CubeIDE

All-in-one development environment with HAL libraries

Eclipse-based Free Multi-platform
Download
STM32CubeProgrammer

STM32CubeProgrammer

Programming tool for all STM32 devices

Multi-interface Firmware update Secure programming
Download
STM32CubeMX

STM32CubeMX

Pinout configuration and code generation

Visual config HAL code gen Power calc
Download