stm32f1-hal
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.
- It implements selected embedded-hal traits.
- It uses the os-trait crate, which makes it easy to integrate with different RTOSes.
- It works with stable Rust.
馃幆 Motivation
Existing crates didn鈥檛 fully meet my needs:
- stm32f1xx-hal鈥檚 design didn鈥檛 align with my workflow.
- stm32-hal lacks support for the STM32F1 series.
- Embassy and RTIC are async framework, but I need a sync one.
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.
馃摉 Design Philosophy
-
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 + generics. In complex modules, combining macros with generics 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.
- The initialization code is not hidden. This makes the
mainfunction more verbose, but everything that鈥檚 happening is clearly visible. - Static variables are kept to a minimum in the library.
- The initialization code is not hidden. This makes the
馃摝 Usage
cargo add stm32f1-hal
use ;
!
Examples
For a more complete example, see example. And stm32f1-FreeRTOS-example shows how to use this crate with FreeRTOS together.
馃椇 Roadmap
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.
- GPIO (tested)
- EXTI (tested)
- UART + poll mode (tested)
- UART + interrupt (stress tested)
- UART + DMA (stress tested)
- I2C + interrupt (tested)
- DMA
- ADC
- SPI
- More features
馃洜 Contributing
- Open issues for bugs or feature requests.
- Submit PRs with improvements or new peripheral support.
馃敄 Keywords
stm32 路 stm32f1 路 rust 路 embedded-hal 路 hal 路 microcontroller 路 embedded development