From 9008e4ca79a8cea093484f09d02c9ca67e7e2b1f Mon Sep 17 00:00:00 2001 From: liebman Date: Thu, 18 Dec 2025 15:04:45 -0800 Subject: low-power: stm32wl5x --- examples/stm32wl5x-lp/.cargo/config.toml | 9 +++++ examples/stm32wl5x-lp/Cargo.toml | 39 +++++++++++++++++++++ examples/stm32wl5x-lp/build.rs | 5 +++ examples/stm32wl5x-lp/memory.x | 15 ++++++++ examples/stm32wl5x-lp/src/bin/blinky.rs | 59 ++++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+) create mode 100644 examples/stm32wl5x-lp/.cargo/config.toml create mode 100644 examples/stm32wl5x-lp/Cargo.toml create mode 100644 examples/stm32wl5x-lp/build.rs create mode 100644 examples/stm32wl5x-lp/memory.x create mode 100644 examples/stm32wl5x-lp/src/bin/blinky.rs (limited to 'examples') diff --git a/examples/stm32wl5x-lp/.cargo/config.toml b/examples/stm32wl5x-lp/.cargo/config.toml new file mode 100644 index 000000000..969068656 --- /dev/null +++ b/examples/stm32wl5x-lp/.cargo/config.toml @@ -0,0 +1,9 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# replace your chip as listed in `probe-rs chip list` +runner = "probe-rs run --chip STM32WLE5JCIx --connect-under-reset" + +[build] +target = "thumbv7em-none-eabi" + +[env] +DEFMT_LOG = "debug" diff --git a/examples/stm32wl5x-lp/Cargo.toml b/examples/stm32wl5x-lp/Cargo.toml new file mode 100644 index 000000000..b1823fb8a --- /dev/null +++ b/examples/stm32wl5x-lp/Cargo.toml @@ -0,0 +1,39 @@ +[package] +edition = "2024" +name = "embassy-stm32wl5x-lp" +version = "0.1.0" +license = "MIT OR Apache-2.0" +publish = false + +[dependencies] +# Change stm32wl55jc-cm4 to your chip name, if necessary. +embassy-stm32 = { version = "0.4.0", path = "../../embassy-stm32", features = ["defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti", "chrono", "low-power-pender"] } +embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] } +embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["defmt"] } +embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } +embassy-embedded-hal = { version = "0.5.0", path = "../../embassy-embedded-hal" } + +defmt = "1.0.1" +defmt-rtt = { version = "1.1.0", optional = true } +defmt-serial = { git = "https://github.com/gauteh/defmt-serial", rev = "411ae7fa909b4fd2667885aff687e009b9108190", optional = true } + +cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } +cortex-m-rt = "0.7.0" +embedded-hal = "1.0.0" +embedded-storage = "0.3.1" +panic-probe = { version = "1.0.0", features = ["print-defmt"] } +chrono = { version = "^0.4", default-features = false } +static_cell = { version = "2.1.1", default-features = false } + +[profile.release] +debug = 2 + +[package.metadata.embassy] +build = [ + { target = "thumbv7em-none-eabi", artifact-dir = "out/examples/stm32wl" } +] + +[features] +default = ["defmt-serial"] +defmt-rtt = ["dep:defmt-rtt"] +defmt-serial = ["dep:defmt-serial"] diff --git a/examples/stm32wl5x-lp/build.rs b/examples/stm32wl5x-lp/build.rs new file mode 100644 index 000000000..8cd32d7ed --- /dev/null +++ b/examples/stm32wl5x-lp/build.rs @@ -0,0 +1,5 @@ +fn main() { + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); +} diff --git a/examples/stm32wl5x-lp/memory.x b/examples/stm32wl5x-lp/memory.x new file mode 100644 index 000000000..4590867a8 --- /dev/null +++ b/examples/stm32wl5x-lp/memory.x @@ -0,0 +1,15 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + FLASH : ORIGIN = 0x08000000, LENGTH = 256K + SHARED_RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128 + RAM (rwx) : ORIGIN = 0x20000080, LENGTH = 64K - 128 +} + +SECTIONS +{ + .shared_data : + { + *(.shared_data) + } > SHARED_RAM +} diff --git a/examples/stm32wl5x-lp/src/bin/blinky.rs b/examples/stm32wl5x-lp/src/bin/blinky.rs new file mode 100644 index 000000000..068b65248 --- /dev/null +++ b/examples/stm32wl5x-lp/src/bin/blinky.rs @@ -0,0 +1,59 @@ +#![no_std] +#![no_main] + +use core::mem::MaybeUninit; + +use defmt::*; +#[cfg(feature = "defmt-rtt")] +use defmt_rtt as _; +use embassy_executor::Spawner; +use embassy_stm32::SharedData; +use embassy_stm32::gpio::{Level, Output, Speed}; +use embassy_time::Timer; +use panic_probe as _; + +#[unsafe(link_section = ".shared_data")] +static SHARED_DATA: MaybeUninit = MaybeUninit::uninit(); + +#[embassy_executor::main(executor = "embassy_stm32::Executor", entry = "cortex_m_rt::entry")] +async fn async_main(_spawner: Spawner) { + let mut config = embassy_stm32::Config::default(); + // enable HSI clock + // config.rcc.hsi = true; + // enable LSI clock for RTC + config.rcc.ls = embassy_stm32::rcc::LsConfig::default_lsi(); + config.rcc.msi = Some(embassy_stm32::rcc::MSIRange::RANGE4M); + config.rcc.sys = embassy_stm32::rcc::Sysclk::MSI; + #[cfg(feature = "defmt-serial")] + { + // disable debug during sleep to reduce power consumption since we are + // using defmt-serial on LPUART1. + config.enable_debug_during_sleep = false; + } + let p = embassy_stm32::init_primary(config, &SHARED_DATA); + + #[cfg(feature = "defmt-serial")] + { + use embassy_stm32::mode::Blocking; + use embassy_stm32::usart::Uart; + use static_cell::StaticCell; + let config = embassy_stm32::usart::Config::default(); + let uart = Uart::new_blocking(p.LPUART1, p.PA3, p.PA2, config).expect("failed to configure UART!"); + static SERIAL: StaticCell> = StaticCell::new(); + defmt_serial::defmt_serial(SERIAL.init(uart)); + } + + info!("Hello World!"); + + let mut led = Output::new(p.PB15, Level::High, Speed::Low); + + loop { + info!("low"); + led.set_low(); + Timer::after_millis(5000).await; + + info!("high"); + led.set_high(); + Timer::after_millis(5000).await; + } +} -- cgit