Crate stm32f3xx_hal

source ·
Expand description

stm32f3xx-hal

stm32f3xx-hal contains a multi device hardware abstraction on top of the peripheral access API for the STMicro STM32F3 series microcontrollers.

Philosophie

HAL (meaning Hardware Abstraction Layer) is a generic term used in many contexts, but in the specific context of this crate, it is meant to abstract away the control exposed by the devices “peripheral access crate” to simplify initialization routines, with a robust interface avoiding miss-configurations while still not abstracting away too much.

Also, this crate’s goal is to integrate well with the rest of the rust embedded ecosystem, for example by implementing the embedded_hal traits or using crates like embedded_time, or rtcc.

Basic Usage

#![no_std]
#![no_main]

use cortex_m::asm;
use cortex_m_rt::entry;
use panic_halt as _;
use stm32f3xx_hal::{self as hal, pac, prelude::*};

#[entry]
fn main() -> ! {
      let dp = pac::Peripherals::take().unwrap();

      let mut rcc = dp.RCC.constrain();
      let mut gpioe = dp.GPIOE.split(&mut rcc.ahb);

      let mut led = gpioe
            .pe13
            .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);

      loop {
            led.toggle().unwrap();
            asm::delay(8_000_000);
      }
}

Cargo features

Target chip selection

This crate requires you to specify your target chip as a feature.

Please select one of the following (x denotes any character in [a-z]):

  • stm32f301x6, stm32f301x8, stm32f318x8
  • stm32f302x6, stm32f302x8, stm32f302xb, stm32f302xc, stm32f302xd, stm32f302xe
  • stm32f303x6, stm32f303x8, stm32f303xb, stm32f303xc, stm32f303xd, stm32f303xe
  • stm32f328x8
  • stm32f358xc
  • stm32f398xe
  • stm32f373x8, stm32f373xb, stm32f373xc, stm32f378xc
  • stm32f334x4, stm32f334x6, stm32f334x8

Example: The STM32F3Discovery board has a STM32F303VCT6 chip. So you need to specify stm32f303xc in your Cargo.toml (note that VC → xc).

For more information, see the README.

ld

When this feature is enabled the memory.x linker script for target chip is automatically provided by this crate. See cortex-m-rt document for more info.

rt

This feature enables stm32f3’s rt feature. See cortex-m-rt document for more info.

can

Enable CAN peripherals on supported targets. The can implementation of the interface is backed by bxcan

usb

Enable USB peripherals on supported targets via the stm32-usbd crate.

rtc

Enables RTC support, build upon rtcc crate.

enumset

Enable functions, which leverage enumset. This is especially usefull to get all set status events at once, see for example serial::Serial::triggered_events()

defmt

Currently these are only used for panicking calls, like assert! panic! or unwrap(). These are enabled using the defmt filter. For now defmt is mostly intended for internal development and testing to further reduce panicking calls in this crate. The support of this feature is subject to change as the development of defmt is advancing.

To use this feature follow the Application Setup of the defmt-book.

Re-exports

Modules

  • Analog to Digital Converter.
  • Controller Area Network.
  • Digital-to-Analog Converter
  • Delays
  • Direct memory access (DMA) controller.
  • Flash memory
  • General Purpose Input / Output
  • Inter-Integrated Circuit (I2C) bus
  • Common Interrupt interface defintions shared between peipherals.
  • Peripheral access Peripheral access API for STM32F303 microcontrollers (generated using svd2rust v0.24.1 ( ))
  • Prelude
  • Pulse width modulation
  • Reset and Clock Control
  • Real Time Clock
  • Serial
  • Device electronic signature
  • Serial Peripheral Interface (SPI) bus
  • System configuration controller
  • Timers
  • USB peripheral.
  • Watchdog

Macros

  • Turns the non-blocking expression $e into a blocking operation.

Structs

  • A generic Error type for failable integer to enum conversions used in multiple occasions inside this crate.

Enums

  • Switch something on or off.
  • Enable use of interrupt macro. Enumeration of all the interrupts.

Attribute Macros