Expand description
§HAL for the STM32F1 family of microcontrollers
This is an implementation of the embedded-hal traits for the STM32F1 family of microcontrollers.
§Usage
§Building an application (binary crate)
A detailed usage guide can be found in the README
supported microcontrollers are:
- stm32f103
- stm32f101
- stm32f100
- stm32f105
- stm32f107
§Usage
This crate supports multiple microcontrollers in the stm32f1 family. Which specific microcontroller you want to build for has to be specified with a feature, for example stm32f103.
If no microcontroller is specified, the crate will not compile.
The currently supported variants are
stm32f100stm32f101stm32f103stm32f105stm32f107
You may also need to specify the density of the device with medium, high or xl to enable certain peripherals. Generally the density can be determined by the 2nd character after the number in the device name (i.e. For STM32F103C6U, the 6 indicates a low-density device) but check the datasheet or CubeMX to be sure.
- 4, 6 => low density, no feature required
- 8, B =>
mediumfeature - C, D, E =>
highfeature - F, G =>
xlfeature
§Commonly used setup
Almost all peripherals require references to some registers in RCC and AFIO. The following code shows how to set up those registers
// Get access to the device specific peripherals from the peripheral access crate let dp = pac::Peripherals::take().unwrap(); // Take ownership over the raw flash and rcc devices and convert them into the corresponding // HAL structs let mut flash = dp.FLASH.constrain(); let mut rcc = dp.RCC.constrain(); // Freeze the configuration of all the clocks in the system and store the frozen frequencies in // `clocks` let clocks = rcc.cfgr.freeze(&mut flash.acr); // Prepare the alternate function I/O registers let mut afio = dp.AFIO.constrain(&mut rcc);§Usage examples
See the examples folder.
Most of the examples require the following additional dependencies
[dependencies] embedded-hal = "0.2.3" nb = "0.1.2" cortex-m = "0.6.2" cortex-m-rt = "0.6.11" # Panic behaviour, see https://crates.io/keywords/panic-impl for alternatives panic-halt = "0.2.0"Re-exports§
pub use embedded_hal as hal;pub use embedded_hal_02 as hal_02;
Modules§
- adc
- API for the Analog to Digital converter
- afio
- Alternate Function I/Os
- backup_
domain - Registers that are not reset as long as Vbat or Vdd has power.
- bb
- Bit banding
- can
- Controller Area Network (CAN) Interface
- crc
- CRC
- dac
- API for the Digital to Analog converter
- dma
- Direct Memory Access
- flash
- Flash memory
- gpio
- General Purpose I/Os
- i2c
- Inter-Integrated Circuit (I2C) bus
- pac
- Peripheral access API for STM32F103 microcontrollers (generated using svd2rust v0.36.1 (4052ce6 2025-04-04))
- pacext
- prelude
- rcc
- Reset & Control Clock
- rtc
- Real time clock
- serial
- Serial Communication (USART)
- spi
- Serial Peripheral Interface
- time
- Time units
- timer
- Timer
- usb
- USB peripheral
- watchdog
- Watchdog peripherals