[][src]Crate stm32f1xx_hal

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)

Follow the cortex-m-quickstart instructions, add this crate as a dependency and make sure you enable the "rt" Cargo feature of this crate. Also select which microcontroller you will be using by using the corresponding feature. The currently supported microcontrollers are:

  • stm32f103
  • stm32f100
[dependencies.stm32f1xx-hal]
version = "0.2.1"
features = ["stm32f103", "rt"]

Usage example

The following example blinks an LED connected to PC13 which is where the LED is connected on the blue_pill board. If you are testing on a different breakout board, you may need to change the pin accordingly.

#![no_std]
#![no_main]
 
extern crate panic_halt;
 
use nb::block;
 
use stm32f1xx_hal::{
    prelude::*,
    pac,
    timer::Timer,
};
use cortex_m_rt::entry;
 
#[entry]
fn main() -> ! {
    // Get access to the core peripherals from the cortex-m crate
    let cp = cortex_m::Peripherals::take().unwrap();
    // 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);
 
    // Acquire the GPIOC peripheral
    let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
 
    // Configure gpio C pin 13 as a push-pull output. The `crh` register is
    // passed to the function in order to configure the port. For pins 0-7,
    // crl should be passed instead.
    let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
    // Configure the syst timer to trigger an update every second
    let mut timer = Timer::syst(cp.SYST, 1.hz(), clocks);
 
    // Wait for the timer to trigger an update and change the state of the LED
    loop {
        block!(timer.wait()).unwrap();
        led.set_high();
        block!(timer.wait()).unwrap();
        led.set_low();
    }
}

More examples

See the examples folder.

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

delay

Delays

device
dma

Direct Memory Access

flash

Flash memory

gpio

General Purpose I/Os

i2c

Inter-Integrated Circuit (I2C) bus

pac
prelude
pwm

Pulse width modulation

pwm_input

This module allows Timer peripherals to be configured as pwm input. In this mode, the timer sample a squared signal to find it's frequency and duty cycle.

qei

Quadrature Encoder Interface

rcc

Reset & Control Clock

rtc

Real time clock

serial

Serial Communication (USART)

spi

Serial Peripheral Interface

stm32
time

Time units

timer

Timer

watchdog

Watchdog peripherals