Skip to content

LirisFlow/stm32f1-hal

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stm32f1-hal

CI Crates.io Docs.rs License Downloads

stm32f1-hal is a Rust Hardware Abstraction Layer (HAL) for STM32F1 microcontrollers (All F1 series devices). It implements selected embedded-hal traits to provide a clear, idiomatic interface for embedded development on STM32F1. Many parts are adapted from stm32f1xx-hal, with a focus on readability and maintainability.

🎯 Motivation

Existing crates didn’t 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.

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

  • Concise is not equal to simple. Fewer lines of code do not necessarily mean easier to read or understand.

  • 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, a preprocessing tool that replaces annotated comments with reusable code blocks, keeping peripheral code consistent and readable.

  • In addition, a script is used to generate code for GPIO alternate function remapping.

📦 Usage

cargo add stm32f1-hal
use stm32f1_hal as hal;
use hal::pac;
use hal::prelude::*;

fn main() {
    let dp = pac::Peripherals::take().unwrap();
    let mut flash = dp.FLASH.constrain();
    let mut rcc = dp.RCC.constrain();

    let clocks = rcc.cfgr.freeze(&mut flash.acr);
    let mut gpioa = dp.GPIOA.split(&mut rcc.apb2);

    let mut led = gpioa.pa5.into_push_pull_output(&mut gpioa.crl);

    loop {
        led.set_high();
        // delay...
        led.set_low();
        // delay...
    }
}

See example. See crate.

🗺 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
  • UART
  • I2C
  • ADC
  • DMA
  • More features

🛠 Contributing

  • Open issues for bugs or feature requests.
  • Submit PRs with improvements or new peripheral support (I2C, ADC, DMA, etc.).

🔖 Keywords

stm32 · stm32f1 · rust · embedded-hal · hal · microcontroller · embedded development

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Rust 97.2%
  • Python 2.8%