diff options
| author | xoviat <[email protected]> | 2023-08-26 20:37:01 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-08-26 20:37:01 -0500 |
| commit | db71887817e665c5c226e8775ad2d5814babac6e (patch) | |
| tree | 5ca82259ad73a91002b063e89ad2bc8369726c8e /tests/stm32/src | |
| parent | 1e430f74133acaeb31cb689ded3da77cb7b1c0ca (diff) | |
tests/stm32: add stop and cleanpu
Diffstat (limited to 'tests/stm32/src')
| -rw-r--r-- | tests/stm32/src/bin/stop.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/stm32/src/bin/stop.rs b/tests/stm32/src/bin/stop.rs new file mode 100644 index 000000000..4a49bde9d --- /dev/null +++ b/tests/stm32/src/bin/stop.rs | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | // required-features: stop,chrono | ||
| 2 | |||
| 3 | #![no_std] | ||
| 4 | #![no_main] | ||
| 5 | #![feature(type_alias_impl_trait)] | ||
| 6 | #[path = "../common.rs"] | ||
| 7 | mod common; | ||
| 8 | |||
| 9 | use chrono::NaiveDate; | ||
| 10 | use common::*; | ||
| 11 | use cortex_m_rt::entry; | ||
| 12 | use embassy_executor::Spawner; | ||
| 13 | use embassy_stm32::low_power::{stop_with_rtc, Executor}; | ||
| 14 | use embassy_stm32::rtc::{Rtc, RtcClockSource, RtcConfig}; | ||
| 15 | use embassy_time::{Duration, Timer}; | ||
| 16 | use static_cell::make_static; | ||
| 17 | |||
| 18 | #[entry] | ||
| 19 | fn main() -> ! { | ||
| 20 | let executor = Executor::take(); | ||
| 21 | executor.run(|spawner| { | ||
| 22 | unwrap!(spawner.spawn(async_main(spawner))); | ||
| 23 | }); | ||
| 24 | } | ||
| 25 | |||
| 26 | #[embassy_executor::task] | ||
| 27 | async fn async_main(_spawner: Spawner) { | ||
| 28 | let mut config = config(); | ||
| 29 | |||
| 30 | config.rcc.rtc = Some(RtcClockSource::LSI); | ||
| 31 | |||
| 32 | let p = embassy_stm32::init(config); | ||
| 33 | info!("Hello World!"); | ||
| 34 | |||
| 35 | let now = NaiveDate::from_ymd_opt(2020, 5, 15) | ||
| 36 | .unwrap() | ||
| 37 | .and_hms_opt(10, 30, 15) | ||
| 38 | .unwrap(); | ||
| 39 | |||
| 40 | let mut rtc = Rtc::new(p.RTC, RtcConfig::default()); | ||
| 41 | |||
| 42 | rtc.set_datetime(now.into()).expect("datetime not set"); | ||
| 43 | |||
| 44 | let rtc = make_static!(rtc); | ||
| 45 | |||
| 46 | stop_with_rtc(rtc); | ||
| 47 | |||
| 48 | info!("Waiting 5 seconds"); | ||
| 49 | Timer::after(Duration::from_secs(5)).await; | ||
| 50 | |||
| 51 | info!("Test OK"); | ||
| 52 | cortex_m::asm::bkpt(); | ||
| 53 | } | ||
