aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Enderle <[email protected]>2024-01-02 23:05:58 +0100
committerChristian Enderle <[email protected]>2024-01-02 23:05:58 +0100
commit38303009907fbf9ebd4919e85166c8bebb6e0ba4 (patch)
tree4401fba4e2d40c4b82e029e09b51647237c4618f
parentf1c077ed2e420b1b4f8c1835fe05a1279a742267 (diff)
stm32l5: add low-power stop example
-rw-r--r--examples/stm32l5/Cargo.toml6
-rw-r--r--examples/stm32l5/src/bin/stop.rs61
2 files changed, 66 insertions, 1 deletions
diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml
index 329e7b98d..c50314587 100644
--- a/examples/stm32l5/Cargo.toml
+++ b/examples/stm32l5/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8# Change stm32l552ze to your chip name, if necessary. 8# Change stm32l552ze to your chip name, if necessary.
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "memory-x"] } 9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "memory-x", "low-power"] }
10embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } 10embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] }
11embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 11embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
12embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 12embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
@@ -30,3 +30,7 @@ static_cell = "2"
30 30
31[profile.release] 31[profile.release]
32debug = 2 32debug = 2
33
34[[bin]]
35name = "stop"
36default-features = ["embassy-stm32/low-power"]
diff --git a/examples/stm32l5/src/bin/stop.rs b/examples/stm32l5/src/bin/stop.rs
new file mode 100644
index 000000000..21b30a266
--- /dev/null
+++ b/examples/stm32l5/src/bin/stop.rs
@@ -0,0 +1,61 @@
1#![no_std]
2#![no_main]
3
4use defmt::*;
5use embassy_executor::Spawner;
6use embassy_stm32::gpio::{Level, Output, Speed, AnyPin};
7use embassy_stm32::low_power::Executor;
8use embassy_stm32::rtc::{Rtc, RtcConfig};
9use embassy_stm32::Config;
10use embassy_stm32::rcc::LsConfig;
11use embassy_time::Timer;
12use static_cell::StaticCell;
13use {defmt_rtt as _, panic_probe as _};
14
15#[cortex_m_rt::entry]
16fn main() -> ! {
17 Executor::take().run(|spawner| {
18 unwrap!(spawner.spawn(async_main(spawner)));
19 })
20}
21
22#[embassy_executor::task]
23async fn async_main(spawner: Spawner) {
24 let mut config = Config::default();
25 config.rcc.ls = LsConfig::default_lsi();
26 // when enabled the power-consumption is much higher during stop, but debugging and RTT is working
27 // if you wan't to measure the power-consumption, or for production: uncomment this line
28 // config.enable_debug_during_sleep = false;
29 let p = embassy_stm32::init(config);
30
31 // give the RTC to the executor...
32 let rtc = Rtc::new(p.RTC, RtcConfig::default());
33 static RTC: StaticCell<Rtc> = StaticCell::new();
34 let rtc = RTC.init(rtc);
35 embassy_stm32::low_power::stop_with_rtc(rtc);
36
37 unwrap!(spawner.spawn(blinky(p.PC7.into())));
38 unwrap!(spawner.spawn(timeout()));
39}
40
41#[embassy_executor::task]
42async fn blinky(led: AnyPin) -> ! {
43 let mut led = Output::new(led, Level::Low, Speed::Low);
44 loop {
45 info!("high");
46 led.set_high();
47 Timer::after_millis(300).await;
48
49 info!("low");
50 led.set_low();
51 Timer::after_millis(300).await;
52 }
53}
54
55// when enable_debug_during_sleep is false, it is more difficult to reprogram the MCU
56// therefore we block the MCU after 30s to be able to reprogram it easily
57#[embassy_executor::task]
58async fn timeout() -> ! {
59 Timer::after_secs(30).await;
60 loop {}
61}