stm32l5: add low-power stop example
This commit is contained in:
parent
f1c077ed2e
commit
3830300990
2 changed files with 66 additions and 1 deletions
examples/stm32l5
|
@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Change stm32l552ze to your chip name, if necessary.
|
# Change stm32l552ze to your chip name, if necessary.
|
||||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "memory-x"] }
|
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "memory-x", "low-power"] }
|
||||||
embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] }
|
embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||||
embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||||
embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||||
|
@ -30,3 +30,7 @@ static_cell = "2"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
debug = 2
|
debug = 2
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "stop"
|
||||||
|
default-features = ["embassy-stm32/low-power"]
|
||||||
|
|
61
examples/stm32l5/src/bin/stop.rs
Normal file
61
examples/stm32l5/src/bin/stop.rs
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
|
||||||
|
use defmt::*;
|
||||||
|
use embassy_executor::Spawner;
|
||||||
|
use embassy_stm32::gpio::{Level, Output, Speed, AnyPin};
|
||||||
|
use embassy_stm32::low_power::Executor;
|
||||||
|
use embassy_stm32::rtc::{Rtc, RtcConfig};
|
||||||
|
use embassy_stm32::Config;
|
||||||
|
use embassy_stm32::rcc::LsConfig;
|
||||||
|
use embassy_time::Timer;
|
||||||
|
use static_cell::StaticCell;
|
||||||
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|
||||||
|
#[cortex_m_rt::entry]
|
||||||
|
fn main() -> ! {
|
||||||
|
Executor::take().run(|spawner| {
|
||||||
|
unwrap!(spawner.spawn(async_main(spawner)));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
async fn async_main(spawner: Spawner) {
|
||||||
|
let mut config = Config::default();
|
||||||
|
config.rcc.ls = LsConfig::default_lsi();
|
||||||
|
// when enabled the power-consumption is much higher during stop, but debugging and RTT is working
|
||||||
|
// if you wan't to measure the power-consumption, or for production: uncomment this line
|
||||||
|
// config.enable_debug_during_sleep = false;
|
||||||
|
let p = embassy_stm32::init(config);
|
||||||
|
|
||||||
|
// give the RTC to the executor...
|
||||||
|
let rtc = Rtc::new(p.RTC, RtcConfig::default());
|
||||||
|
static RTC: StaticCell<Rtc> = StaticCell::new();
|
||||||
|
let rtc = RTC.init(rtc);
|
||||||
|
embassy_stm32::low_power::stop_with_rtc(rtc);
|
||||||
|
|
||||||
|
unwrap!(spawner.spawn(blinky(p.PC7.into())));
|
||||||
|
unwrap!(spawner.spawn(timeout()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
async fn blinky(led: AnyPin) -> ! {
|
||||||
|
let mut led = Output::new(led, Level::Low, Speed::Low);
|
||||||
|
loop {
|
||||||
|
info!("high");
|
||||||
|
led.set_high();
|
||||||
|
Timer::after_millis(300).await;
|
||||||
|
|
||||||
|
info!("low");
|
||||||
|
led.set_low();
|
||||||
|
Timer::after_millis(300).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// when enable_debug_during_sleep is false, it is more difficult to reprogram the MCU
|
||||||
|
// therefore we block the MCU after 30s to be able to reprogram it easily
|
||||||
|
#[embassy_executor::task]
|
||||||
|
async fn timeout() -> ! {
|
||||||
|
Timer::after_secs(30).await;
|
||||||
|
loop {}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue