newam/stm32wl-hal

Embedded rust HAL (hardware abstraction layer) for the STM32WL

This is a work in progress, it is unstable, incomplete, and (mostly) untested

stm32wl-hal

Embedded rust HAL (hardware abstraction layer) for the STM32WL.

⚠️ This is a work in progress, it is unstable (lots of API changes) and incomplete.

The code that exists today covers basic usage of:

  • SubGHz LoRa TX + RX
  • SubGHz (G)FSK TX + RX
  • SPI
  • GPIO
  • UART
  • I2C
  • Low-power timers
  • ADC
  • DAC
  • PKA ECDSA signing + verification
  • Secure random number generation
  • AES ECB encryption + decryption
  • RTC date and time

Usage

See hal/README.md.

Examples

All examples run on the NUCLEO-WL55JC2. Examples are located in the examples crate. The arguments got long for this, so a run-ex cargo alias is provided.

The testsuites are also excellent reference material, they are automatically tested for every commit and are guaranteed to work.

The testsuites and examples are a good starting point, but they demonstrate features independent of each-other. A system-level example using multiple features simultaneously is provided in a separate repo: stm32wl-lightswitch-demo

Unit Tests

Off-target unit tests use the built-in cargo framework. The only abnormal part of this is that you must specify the target device as a feature.

On-Target Tests

Workspaces with testsuite in the name denote an on-target test.

On-target tests use the NUCLEO-WL55JC2, you can find a place purchase this here.

On-Target Quickstart

The on-target tests use defmt-test.

  • cargo install --git https://github.com/newAM/probe-run.git (probe-run, newAM/probe-run)
    • Note: My fork contains unreleased fixes for the stm32wl, see #74 for details.
  • rustup target add --toolchain stable thumbv7m-none-eabi (rustup)
  • (Linux users only) udev rules are available at newAM/nucleo-wl55jc2-rs
  • Connect the nucleo board to your PC via USB.
  • cargo test -p pka-testsuite --target thumbv7em-none-eabi

Sample output:

SubGhz Tests

The subghz on-target tests require two nucleo boards, one for transmitting, and one for receiving. Run the subghz-testsuite twice on two different boards.

Assuming both boards are connected to the same system you will have to pass a specific probe to each.

Reference Documentation

  • stm32wl5x reference manual
  • stm32wlex reference manual
  • stm32wle5c8 datasheet
  • stm32wl55cc datasheet
  • stm32wl55xx stm32wl54xx erratum
  • stm32wle5xx stm32wle4xx erratum
Issues

Collection of the latest Issues

justacec

justacec

question
Comment Icon3

I would like to use an LPTIM peripheral to track time. To do so I would like it to be in continuous mode so it just fires off the event and then reloads and keeps going. Unfortunately, the start function implementation for the LPTIM peripherals seems to set the mode to Single. How would I go about setting this up for continuous?

newAM

newAM

enhancement
Comment Icon0
  • Replace wall-of-text # Safety sections with enumerated check-lists of requirements.
  • Lots of duplicated code across testsuites (fixed in #82)
  • Provide a from_millis, from_nanos, from_secs ect. with subghz::Timeout
  • Normalize meta-access of peripherals for all peripherals (maybe trait these to enforce uniformity?)
    • pub unsafe fn steal() -> Self
    • fn mask_irq()
    • pub unsafe fn unmask_irq()
    • pub unsafe fn pulse_reset(rcc: &mut pac::RCC)
    • pub fn enable_clock(rcc: &mut pac::RCC)
    • pub unsafe fn disable_clock(rcc: &mut pac::RCC)
    • Normalize what new does with regards to clocks, resets, enables, and interrupts
Versions

Find the latest versions by id

v0.6.0 - Jul 04, 2022

Added

  • Added rcc::Lsco to use the low-speed oscillator output.
  • Added Rtc::calibrate_lp to calibrate the RTC.
  • Added Rtc::recalibration_pending.
  • Added Rtc::is_alarm_{a,b}_en.
  • Added methods to utilize ADC oversampling.

Changed

  • Rtc.alarm_{a,b} returns Alarm instead of Option<Alarm>.
  • Updated stm32-rs from 0.14.0 to 0.15.1.

Fixed

  • Fixed a documentation bug in rtc::Alarm. Values are masked if true, but the documentation indicated they are masked if false.

v0.5.1 - May 14, 2022

Added

  • Added Rtc::alarm_{a,b} to get the alarm value.
  • Added impl From<Alarm> for chrono::NaiveTime.
  • Added RfSwitch::steal() to all BSPs.

v0.5.0 - May 08, 2022

Added

  • Added set_sleep_clock to GPIO ports to enable and disable clocks during sleep.
  • Added subghz::Timeout::saturating_add.
  • Added SubGhz.set_rtc_period and SubGhz.restart_rtc methods required to workaround an erratum with SubGhz.set_rx_duty_cycle.
  • Added SubGhz.new_no_reset and SubGhz.new_with_dma_no_reset to create a SubGhz without resetting the radio.

Changed

  • Changed minimum supported rust version from 1.57 to 1.60.

Fixed

  • Fixed a typo in the Exti::set_falling_trigger function name.
  • Fixed endianness in SubGhz.op_error.

v0.4.1 - Mar 22, 2022

Added

  • Implement embedded_hal::PwmPin for LpTim.

Changed

  • Inlined trivial Rng methods.

Fixed

  • Fixed UART clock_hz methods returning the wrong frequency.

v0.4.0 - Jan 08, 2022

Added

  • Added a is_pending method to the gpio::Exti trait.
  • Added alarm functionality to the RTC.
  • Added Rtc.is_wakeup_timer_en.
  • Added flash::flash_range.
  • Added Flash.program_bytes for safer flash programming.

Changed

  • Replaced Debug implementation with Display implementation for:
    • subghz::FskPacketStatus
    • subghz::LoRaPacketStatus
    • subghz::Stats
    • subghz::Status
  • Flash::standard_program_generic now checks for overflow.

Fixed

  • Fixed an off-by-one error in flash::Page::addr_range.

Removed

  • Removed util::reset_cycle_count; this functionality is now in cortex-m.

v0.3.0 - Dec 21, 2021

Added

  • Added info::Core::CT to get the CPU core at compile time.
  • Added info::Core::from_cpuid() to get the CPU core at runtime.
  • Added a flash module with erase and program functionality.
  • Added defmt::Format for all types declared in the BSPs.
  • Added info::uid::PTR.

Changed

  • Changed minimum rust version from 1.56 to 1.57 for const_panic.
  • info::UID64
    • Moved to info::Uid64::PTR.
    • Changed the type from *const u8 to *const u32.
  • Moved functions in info into the associated structs/enums.
    • Moved info::uid64 to info::Uid64::from_device.
    • Moved info::uid64_devnum to info::Uid64::read_devnum.
    • Moved info::package to info::Package::from_device.
    • Moved info::uid to info::Uid::from_device.
  • Added #[inline] to util::new_delay and util::reset_cycle_count.
  • Large dependencies are now optional.
    • embedded-time is now an optional feature.
      • Changed I2C::new to use u32 instead of embedded_time::Hertz.
    • chrono is now an optional feature.

v0.2.1 - Nov 20, 2021

Fixed

  • Fixed timeouts after calling SubGhz::set_sleep.

v0.2.0 - Nov 11, 2021

Added

  • Added two board support crates
    • nucleo-wl55jc-bsp
    • lora-e5-bsp

Changed

  • Crate ownership changed from tweedegolf to stm32-rs.
    • Thank you tweedegolf for the initial development effort!
  • Sweeping changes throughout the entire crate, nothing is the same.

Information - Updated Jul 10, 2022

Stars: 26
Forks: 8
Issues: 3

Repositories & Extras

rust_embedded_starter

Boilerplate für Embedded Entwicklung mit Rust mit Flash und Debug automatik

rust_embedded_starter

Embedded Rust Template

This template is based on stm32f4xx-hal

Embedded Rust Template

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

This crate is largely inspired by the awesome work done here:

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

An embedded rust no_std driver for the AHT20 temperature and humidity sensor, forked from Anthony...

An embedded rust no_std driver for the AHT20 temperature and humidity sensor, forked from Anthony Romano's docs

An embedded rust no_std driver for the AHT20 temperature and humidity sensor, forked from Anthony...

embedded-rust-H2AL

Hardware abstraction layer - abstraction layer

embedded-rust-H2AL

cargo-pio = Cargo + PlatformIO

Build Rust embedded projects with PlatformIO!

cargo-pio = Cargo + PlatformIO

Embedded rust HAL (hardware abstraction layer) for the STM32WL series

This is still in development, the code that exists today covers basic usage of:

Embedded rust HAL (hardware abstraction layer) for the STM32WL series

Microchip MCP4725 DAC Driver for Rust Embedded HAL

This is a driver crate for embedded Rust

Microchip MCP4725 DAC Driver for Rust Embedded HAL

An async embedded rust no_std driver for the QMC5883L magnetometer chip based on this driver

An async embedded rust no_std driver for the QMC5883L magnetometer chip based on embassy example

An async embedded rust no_std driver for the QMC5883L magnetometer chip based on this driver
Facebook Instagram Twitter GitHub Dribbble
Privacy