• Stars
    star
    164
  • Rank 230,032 (Top 5 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Rust embedded-hal HAL for all MCUs in the STM32 F3 family

stm32f3xx-hal

Build Status Crate Docs Crates.io Minimum Supported Rust Version

stm32f3xx-hal contains a multi device hardware abstraction on top of the peripheral access API for the STMicro STM32F3 series microcontrollers. The selection of the MCU is done by feature gates, typically specified by board support crates. An excerpt of supported chip variants:

  • stm32f301
  • stm32f318
  • stm32f302
  • stm32f303
  • stm32f373
  • stm32f378
  • stm32f334
  • stm32f328
  • stm32f358
  • stm32f398

The idea behind this crate is to gloss over the slight differences in the various peripherals available on those MCUs so a HAL can be written for all chips in that same family without having to cut and paste crates for every single model.

Collaboration on this crate is highly welcome as are pull requests!

This crate relies on Adam Greigs fantastic stm32f3 crate to provide appropriate register definitions and implements a partial set of the embedded-hal traits.

Almost all of the implementation was shamelessly adapted from the stm32f30x-hal crate by Jorge Aparicio.

Getting Started

Adding stm32f3xx-hal and other dependencies

Cargo.toml:

[dependencies]
# Only set the critical section feature, if you are using a bare-metal platform
# without any RTOS
# See https://github.com/rust-embedded/critical-section for further details.
cortex-m = { version = "0.7.4", features = ["critical-section-single-core"]}
cortex-m-rt = { version = "0.7.3", features = ["device"] }
# Panic behavior, see https://crates.io/keywords/panic-impl for alternatives
panic-halt = "0.2.0"
# Replace stm32f303xc with your target chip, see next section for more info
stm32f3xx-hal = { version = "0.9.2", features = ["ld", "rt", "stm32f303xc"] }

We also need to tell Rust about target architecture and how to link our executable by creating .cargo/config.

.cargo/config:

[target.thumbv7em-none-eabihf]
rustflags = [
  "-C", "link-arg=-Tlink.x",
]

[build]
target = "thumbv7em-none-eabihf"

Selecting the right chip

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

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

All possible chip variants are selectable via cargo features. You can find a list here, in the docs.

Note

  1. This features are mutually exclusive. Only one feature / chip variant can be chosen.
  2. You have to choose exactly one feature to build this crate at all.

Background

For some of the stm32f3xx chips there are sub-variants that differ in functionality, peripheral use and hence 'under the hood' implementation. To allow the full use of all peripherals on certain sub-variants without allowing for code that just doesn't run on other sub-variants, they are distinct features that need to be specified.

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);
      }
}

See the examples folder for more example programs.

Changelog

Minimum Supported Rust Version (MSRV)

This crate is guaranteed to compile on stable Rust 1.59.0 and up. It might compile with older versions but that may change in any new patch release.

Contributing

License

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

More Repositories

1

stm32-rs

Embedded Rust device crates for STM32 microcontrollers
Python
1,281
star
2

stm32f1xx-hal

A Rust embedded-hal HAL impl for the STM32F1 family based on japarics stm32f103xx-hal
Rust
564
star
3

stm32f4xx-hal

A Rust embedded-hal HAL for all MCUs in the STM32 F4 family
Rust
550
star
4

stm32h7xx-hal

Peripheral access API for STM32H7 series microcontrollers
Rust
215
star
5

stm32l4xx-hal

A Hardware abstraction layer for the stm32l432xx series chips written in rust.
Rust
156
star
6

stm32-eth

Embedded Ethernet driver in Rust
Rust
147
star
7

stm32f0xx-hal

A Rust `embedded-hal` implementation for all MCUs in the STM32 F0 family
Rust
125
star
8

stm32f7xx-hal

A Rust embedded-hal HAL for all MCUs in the STM32 F7 family
Rust
115
star
9

stm32-usbd

usb-device implementation for STM32 microcontrollers
Rust
99
star
10

stm32l0xx-hal

A hardware abstraction layer (HAL) for the STM32L0 series microcontrollers written in Rust
Rust
96
star
11

stm32g0xx-hal

Peripheral access API for STM32G0 series microcontrollers
Rust
72
star
12

stm32g4xx-hal

Peripheral access API for STM32G4 series microcontrollers
Rust
58
star
13

stm32-usbd-examples

stm32-usbd examples for different microcontrollers
Rust
48
star
14

stm32wlxx-hal

A Hardware abstraction layer for the stm32wl series chips written in rust.
Rust
45
star
15

stm32f407g-disc

Rust BSP crate for the STM32F4DISCOVERY (STM32F407G-DISC) development board
Rust
43
star
16

synopsys-usb-otg

usb-device implementation for Synopsys USB OTG IP cores
Rust
43
star
17

bxcan

bxCAN peripheral driver for STM32 chips
Rust
31
star
18

stm32-fmc

Hardware Abstraction Layer for STM32 Memory Controllers (FMC/FSMC)
Rust
17
star
19

stm32f429i-disc

Rust BSP crate for the STM32F429I-DISC development board
Rust
15
star
20

stm32-rs-nightlies

Up-to-date builds of current stm32-rs master branch, for use as Cargo git dependencies
Rust
14
star
21

fdcan

FDCAN peripheral driver for STM32 chips
Rust
12
star
22

stm32-rs-mmaps

Textual memory maps of stm32-rs devices, used to help review PRs to stm32-rs
9
star
23

stm32l1xx-hal

[WIP] Peripheral access API for STM32L1 series microcontrollers
Rust
9
star
24

stm32h5xx-hal

Rust
8
star
25

nucleo-f042k6

Rust BSP crate for the STM Nucleo-F042K6 development board
Shell
8
star
26

stm32-device-signature

Device electronic signature 'driver' for STM32 microcontrollers
Rust
8
star
27

stm32f072b-disco

A BSP/example crate for the STM32F072 Discovery kit
Rust
7
star
28

cube-parse

Rust
7
star
29

cube-MX-db

MCU database files from CubeMX
5
star
30

meta

Meta discussions and files applicable to the entire stm32-rs project
3
star
31

stm32c0xx-hal

Peripheral access API for STM32C0 series microcontrollers
Rust
2
star