Getting Started with STM32
What is STM32 / When to Use It
STM32 is a family of 32-bit ARM Cortex-M microcontrollers by STMicroelectronics. Use STM32 for real-time control, precise timing, CAN bus, industrial communication, or DSP.
Which STM32?
| Series | Core | Speed | Flash | Best For |
|---|---|---|---|---|
| STM32F103 Blue Pill | Cortex-M3 | 72 MHz | 64 KB | Budget learning, basic control |
| STM32F407 Black | Cortex-M4F | 168 MHz | 512 KB | DSP, motor control, audio |
| STM32G0 | Cortex-M0+ | 64 MHz | 32 KB | Low power, cost-sensitive |
| STM32H743 | Cortex-M7 | 480 MHz | 1 MB | High-speed DSP, AI inference |
| STM32WL | Cortex-M4 + LoRa | 48 MHz | 256 KB | LoRaWAN end-devices |
Prerequisites
- STM32 dev board (Nucleo, Discovery, or Blue/Black Pill)
- ST-Link v2 programmer (Nucleo/Discovery have built-in)
- USB cable
Install Toolchain
STM32CubeIDE (Recommended)
- Download from st.com (free, needs ST account)
- Install and launch
- Create new project: File → New → STM32 Project
- Select your MCU (e.g., STM32F407VGT6)
- Configure pins in the .ioc file (graphical pinout editor)
- Generate code — CubeMX creates HAL init code automatically
PlatformIO (VSCode)
platformio init --board black_f407ve
Framework: stm32cube (HAL) or libopencm3 (lightweight).
ARM GCC + Make (Advanced)
sudo apt install gcc-arm-none-eabi openocd
First Example: Blink with HAL
#include "main.h"
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
int main(void) {
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
while (1) {
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);
HAL_Delay(500);
}
}
Common Issues
| Problem | Fix |
|---|---|
| ST-Link not detected | Install ST-Link driver from st.com |
| No serial output | Enable UART in CubeMX pinout config |
| Wrong chip detected | Check SWD wiring — SWCLK/SWDIO not swapped |
| Code too large | Blue Pill only 64 KB; upgrade to F4 |
| CubeIDE slow | Use PlatformIO instead |
Flashing via UART (no ST-Link)
- Set BOOT0 pin HIGH, BOOT1 LOW
- Connect USB-UART to PA9 (TX) and PA10 (RX)
- Use stm32flash:
stm32flash -w firmware.bin -v /dev/ttyUSB0
Questions about this guide?
Ask on the Community Forum — share your project, get help, or help others.