diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32h5/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32h5/src/bin/stop.rs | 71 |
2 files changed, 72 insertions, 1 deletions
diff --git a/examples/stm32h5/Cargo.toml b/examples/stm32h5/Cargo.toml index 4527f4bcb..82760db64 100644 --- a/examples/stm32h5/Cargo.toml +++ b/examples/stm32h5/Cargo.toml | |||
| @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32h563zi to your chip name, if necessary. | 8 | # Change stm32h563zi to your chip name, if necessary. |
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32h563zi", "memory-x", "time-driver-any", "exti", "unstable-pac"] } | 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32h563zi", "memory-x", "time-driver-any", "exti", "unstable-pac", "low-power"] } |
| 10 | embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } |
| 11 | embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 12 | embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
diff --git a/examples/stm32h5/src/bin/stop.rs b/examples/stm32h5/src/bin/stop.rs new file mode 100644 index 000000000..0d14c0668 --- /dev/null +++ b/examples/stm32h5/src/bin/stop.rs | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | // Notice: | ||
| 2 | // the MCU might need an extra reset to make the code actually running | ||
| 3 | |||
| 4 | #![no_std] | ||
| 5 | #![no_main] | ||
| 6 | |||
| 7 | use defmt::*; | ||
| 8 | use embassy_executor::Spawner; | ||
| 9 | use embassy_stm32::gpio::{AnyPin, Level, Output, Speed}; | ||
| 10 | use embassy_stm32::low_power::Executor; | ||
| 11 | use embassy_stm32::rcc::{HSIPrescaler, LsConfig}; | ||
| 12 | use embassy_stm32::rtc::{Rtc, RtcConfig}; | ||
| 13 | use embassy_stm32::Config; | ||
| 14 | use embassy_time::Timer; | ||
| 15 | use static_cell::StaticCell; | ||
| 16 | use {defmt_rtt as _, panic_probe as _}; | ||
| 17 | |||
| 18 | #[cortex_m_rt::entry] | ||
| 19 | fn main() -> ! { | ||
| 20 | Executor::take().run(|spawner| { | ||
| 21 | unwrap!(spawner.spawn(async_main(spawner))); | ||
| 22 | }) | ||
| 23 | } | ||
| 24 | |||
| 25 | #[embassy_executor::task] | ||
| 26 | async fn async_main(spawner: Spawner) { | ||
| 27 | defmt::info!("Program Start"); | ||
| 28 | |||
| 29 | let mut config = Config::default(); | ||
| 30 | |||
| 31 | // System Clock seems need to be equal or lower than 16 MHz | ||
| 32 | config.rcc.hsi = Some(HSIPrescaler::DIV4); | ||
| 33 | |||
| 34 | config.rcc.ls = LsConfig::default_lsi(); | ||
| 35 | // when enabled the power-consumption is much higher during stop, but debugging and RTT is working | ||
| 36 | // if you wan't to measure the power-consumption, or for production: uncomment this line | ||
| 37 | // config.enable_debug_during_sleep = false; | ||
| 38 | let p = embassy_stm32::init(config); | ||
| 39 | |||
| 40 | // give the RTC to the executor... | ||
| 41 | let rtc = Rtc::new(p.RTC, RtcConfig::default()); | ||
| 42 | static RTC: StaticCell<Rtc> = StaticCell::new(); | ||
| 43 | let rtc = RTC.init(rtc); | ||
| 44 | embassy_stm32::low_power::stop_with_rtc(rtc); | ||
| 45 | |||
| 46 | unwrap!(spawner.spawn(blinky(p.PB4.into()))); | ||
| 47 | unwrap!(spawner.spawn(timeout())); | ||
| 48 | } | ||
| 49 | |||
| 50 | #[embassy_executor::task] | ||
| 51 | async fn blinky(led: AnyPin) { | ||
| 52 | let mut led = Output::new(led, Level::Low, Speed::Low); | ||
| 53 | loop { | ||
| 54 | info!("high"); | ||
| 55 | led.set_high(); | ||
| 56 | Timer::after_millis(300).await; | ||
| 57 | |||
| 58 | info!("low"); | ||
| 59 | led.set_low(); | ||
| 60 | Timer::after_millis(300).await; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | // when enable_debug_during_sleep is false, it is more difficult to reprogram the MCU | ||
| 65 | // therefore we block the MCU after 30s to be able to reprogram it easily | ||
| 66 | #[embassy_executor::task] | ||
| 67 | async fn timeout() -> ! { | ||
| 68 | Timer::after_secs(30).await; | ||
| 69 | #[allow(clippy::empty_loop)] | ||
| 70 | loop {} | ||
| 71 | } | ||
