| Crates.io | stm32f1-hal |
| lib.rs | stm32f1-hal |
| version | 0.14.0 |
| created_at | 2025-08-24 21:12:36.321007+00 |
| updated_at | 2026-01-21 19:30:45.432759+00 |
| description | HAL for the STM32F1 family |
| homepage | |
| repository | https://github.com/mcu-rust/stm32f1-hal |
| max_upload_size | |
| id | 1808792 |
| size | 558,328 |
stm32f1-hal is a Rust Hardware Abstraction Layer (HAL) for STM32F1 microcontrollers (All F1 series devices). It provides a clear, idiomatic interface for embedded development on STM32F1.
Existing crates didn鈥檛 fully meet my needs:
To address this gap, I created stm32f1-hal. While parts of the implementation are adapted from stm32f1xx-hal, the focus here is on clarity, readability, and usability.
Readability is the most important. We only write code a few times, but we read it countless times. Clear understanding is essential for long-term maintenance.
Prefer sync-code over complex macros In complex modules, combining macros with generics and calling a lot of low level interfaces often makes the code harder to follow and maintain. Instead, I use sync-code to synchronizes code blocks across peripherals, keeping peripheral code easy to read and maintain.
A script is used to generate code for GPIO alternate function remapping.
Concise is not equal to simple. Fewer lines of code do not necessarily mean easier to read or understand.
main function more verbose, but everything that鈥檚 happening is clearly visible.cargo add stm32f1-hal
use stm32f1_hal::{self as hal, pac, cortex_m_rt::entry, prelude::*};
#[entry]
fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();
let mut flash = dp.FLASH.init();
let cfg = rcc::Config::default();
let mut rcc = dp.RCC.init().freeze(cfg, &mut flash.acr);
let mut gpioa = dp.GPIOA.split(&mut rcc);
let mut led = gpioa.pa5.into_push_pull_output(&mut gpioa.crl);
loop {
led.set_high();
// delay...
led.set_low();
// delay...
}
}
For a more complete example, see example. And stm32f1-FreeRTOS-example shows how to use this crate with FreeRTOS together.
This project is still in its early stages, with only a few features implemented so far. Contributions and feedback are welcome to help expand support for more peripherals and features.
stm32 路 stm32f1 路 rust 路 embedded-hal 路 hal 路 microcontroller 路 embedded development