aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorxoviat <[email protected]>2025-12-19 17:56:09 +0000
committerGitHub <[email protected]>2025-12-19 17:56:09 +0000
commitecb395e9334360994a9201c0ad3e7e921aa2d81a (patch)
tree77fe36797942a3f1bba868bb3fd7229077bef528 /examples
parent905bdfa7662c2ac5d2dfc81219c9704955473253 (diff)
parent941707372099ae5b82e8adf48ec4d0470a1642de (diff)
Merge pull request #5108 from liebman/low-power-stm32wl5x
low-power: stm32wl5x
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32wl5x-lp/.cargo/config.toml9
-rw-r--r--examples/stm32wl5x-lp/Cargo.toml39
-rw-r--r--examples/stm32wl5x-lp/build.rs5
-rw-r--r--examples/stm32wl5x-lp/memory.x15
-rw-r--r--examples/stm32wl5x-lp/src/bin/blinky.rs57
5 files changed, 125 insertions, 0 deletions
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 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace your chip as listed in `probe-rs chip list`
3runner = "probe-rs run --chip STM32WLE5JCIx --connect-under-reset"
4
5[build]
6target = "thumbv7em-none-eabi"
7
8[env]
9DEFMT_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 @@
1[package]
2edition = "2024"
3name = "embassy-stm32wl5x-lp"
4version = "0.1.0"
5license = "MIT OR Apache-2.0"
6publish = false
7
8[dependencies]
9# Change stm32wl55jc-cm4 to your chip name, if necessary.
10embassy-stm32 = { version = "0.4.0", path = "../../embassy-stm32", features = ["defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti", "chrono", "low-power-pender"] }
11embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] }
12embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["defmt"] }
13embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
14embassy-embedded-hal = { version = "0.5.0", path = "../../embassy-embedded-hal" }
15
16defmt = "1.0.1"
17defmt-rtt = { version = "1.1.0", optional = true }
18defmt-serial = { git = "https://github.com/gauteh/defmt-serial", rev = "411ae7fa909b4fd2667885aff687e009b9108190", optional = true }
19
20cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
21cortex-m-rt = "0.7.0"
22embedded-hal = "1.0.0"
23embedded-storage = "0.3.1"
24panic-probe = { version = "1.0.0", features = ["print-defmt"] }
25chrono = { version = "^0.4", default-features = false }
26static_cell = { version = "2.1.1", default-features = false }
27
28[profile.release]
29debug = 2
30
31[package.metadata.embassy]
32build = [
33 { target = "thumbv7em-none-eabi", artifact-dir = "out/examples/stm32wl" }
34]
35
36[features]
37default = ["defmt-serial"]
38defmt-rtt = ["dep:defmt-rtt"]
39defmt-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 @@
1fn main() {
2 println!("cargo:rustc-link-arg-bins=--nmagic");
3 println!("cargo:rustc-link-arg-bins=-Tlink.x");
4 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
5}
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 @@
1MEMORY
2{
3 /* NOTE 1 K = 1 KiBi = 1024 bytes */
4 FLASH : ORIGIN = 0x08000000, LENGTH = 256K
5 SHARED_RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128
6 RAM (rwx) : ORIGIN = 0x20000080, LENGTH = 64K - 128
7}
8
9SECTIONS
10{
11 .shared_data :
12 {
13 *(.shared_data)
14 } > SHARED_RAM
15}
diff --git a/examples/stm32wl5x-lp/src/bin/blinky.rs b/examples/stm32wl5x-lp/src/bin/blinky.rs
new file mode 100644
index 000000000..60b671a77
--- /dev/null
+++ b/examples/stm32wl5x-lp/src/bin/blinky.rs
@@ -0,0 +1,57 @@
1// This example is configured for the nucleo-wl55jc board. Curret monitor should show just a few microamps when the device is in stop2 mode.
2#![no_std]
3#![no_main]
4
5use core::mem::MaybeUninit;
6
7use defmt::*;
8#[cfg(feature = "defmt-rtt")]
9use defmt_rtt as _;
10use embassy_executor::Spawner;
11use embassy_stm32::SharedData;
12use embassy_stm32::gpio::{Level, Output, Speed};
13use embassy_time::Timer;
14use panic_probe as _;
15
16#[unsafe(link_section = ".shared_data")]
17static SHARED_DATA: MaybeUninit<SharedData> = MaybeUninit::uninit();
18
19#[embassy_executor::main(executor = "embassy_stm32::Executor", entry = "cortex_m_rt::entry")]
20async fn async_main(_spawner: Spawner) {
21 let mut config = embassy_stm32::Config::default();
22 config.rcc.ls = embassy_stm32::rcc::LsConfig::default_lsi();
23 config.rcc.msi = Some(embassy_stm32::rcc::MSIRange::RANGE4M);
24 config.rcc.sys = embassy_stm32::rcc::Sysclk::MSI;
25 #[cfg(feature = "defmt-serial")]
26 {
27 // disable debug during sleep to reduce power consumption since we are
28 // using defmt-serial on LPUART1.
29 config.enable_debug_during_sleep = false;
30 }
31 let p = embassy_stm32::init_primary(config, &SHARED_DATA);
32
33 #[cfg(feature = "defmt-serial")]
34 {
35 use embassy_stm32::mode::Blocking;
36 use embassy_stm32::usart::Uart;
37 use static_cell::StaticCell;
38 let config = embassy_stm32::usart::Config::default();
39 let uart = Uart::new_blocking(p.LPUART1, p.PA3, p.PA2, config).expect("failed to configure UART!");
40 static SERIAL: StaticCell<Uart<'static, Blocking>> = StaticCell::new();
41 defmt_serial::defmt_serial(SERIAL.init(uart));
42 }
43
44 info!("Hello World!");
45
46 let mut led = Output::new(p.PB15, Level::High, Speed::Low);
47
48 loop {
49 info!("low");
50 led.set_low();
51 Timer::after_millis(5000).await;
52
53 info!("high");
54 led.set_high();
55 Timer::after_millis(5000).await;
56 }
57}