Skip to content

kkroesch/stm32-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

STM32 Rust Template

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 Justfile for building, flashing, and debugging
  • A clean and reproducible setup to start developing STM32 firmware in Rust

🚀 Getting Started

1. Install Rust tooling

rustup update
rustup target add thumbv7m-none-eabi
cargo install probe-rs-tools

2. Install ARM cross-compiler (macOS)

brew install arm-none-eabi-gcc

3. Connect the ST-Link Programmer

Wiring (Blue Pill ↔ ST-Link V2):

ST-Link Blue Pill
SWDIO PA13
SWCLK PA14
GND GND
3V3 3V3

4. Check whether the probe is detected

probe-rs list

Expected 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.


🧪 Build & Run

This project configures Cargo to use probe-rs run as the runner. Flashing and starting the firmware is as simple as:

cargo run --release

probe-rs will stay attached to the target; press Ctrl-C to exit the session.


📦 Using the Justfile

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 flash

Examples:

just flash
just debug

📂 Project Structure

.
├── .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.


🔧 What's Included

  • 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

📚 Recommended Next Steps

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

🤝 Contributing

PRs, examples, and improvements for other STM32 families (F0/F4/G0/G4) are welcome.


Happy hacking with STM32 + Rust 🚀

About

I took the blue pill.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published