A minimal, ready-to-use template for programming the STM32F103 “Blue Pill” microcontroller using Rust, probe-rs, and the stm32f1xx-hal crate.
This repository provides:
- A correct memory layout (
memory.x) - A working Cargo configuration (
.cargo/config.toml) - A minimal hardware-timer-based LED example (PC13)
- A
Justfilefor building, flashing, and debugging - A clean and reproducible setup to start developing STM32 firmware in Rust
rustup update
rustup target add thumbv7m-none-eabi
cargo install probe-rs-toolsbrew install arm-none-eabi-gccWiring (Blue Pill ↔ ST-Link V2):
| ST-Link | Blue Pill |
|---|---|
| SWDIO | PA13 |
| SWCLK | PA14 |
| GND | GND |
| 3V3 | 3V3 |
probe-rs listExpected output:
The following debug probes were found:
[0]: ST-LINK/V2 (VID:PID 0483:3748)
If you see an ST-Link, you're ready to flash.
This project configures Cargo to use probe-rs run as the runner.
Flashing and starting the firmware is as simple as:
cargo run --releaseprobe-rs will stay attached to the target; press Ctrl-C to exit the session.
The provided Justfile wraps common commands:
just run # build + flash + run (attached)
just flash # flash only, then reset the MCU
just debug # start an interactive debug session
just erase # erase MCU flashExamples:
just flash
just debug.
├── .cargo/
│ └── config.toml # runner + linker configuration
├── memory.x # memory layout for STM32F103C8
├── Justfile # build / flash / debug targets
├── Cargo.toml
└── src/
└── main.rs # minimal LED blink using TIM2 hardware delay
Everything is set up so you can immediately start writing embedded Rust for STM32.
- Clock setup: 8 MHz HSE → 48 MHz system clock
- TIM2 hardware timer for accurate delays
- PC13 LED control (low-active on Blue Pill boards)
- Idiomatic, no-std Rust project structure
Once the LED blink works, try extending the template:
- Timer interrupts (non-blocking)
- PWM for piezo buzzers or LEDs
- RTT logging via
probe-rs attach - Cooperative task scheduling
- Migrating to RTIC or Embassy for async embedded Rust
- UART, ADC, Input Capture, or DMA examples
PRs, examples, and improvements for other STM32 families (F0/F4/G0/G4) are welcome.
Happy hacking with STM32 + Rust 🚀