diff options
| author | xoviat <[email protected]> | 2025-11-04 22:47:13 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-11-04 22:47:13 +0000 |
| commit | ff42c61dc6c0f870b4022aca52f3c45d992ae735 (patch) | |
| tree | d5e126d6c2d891bb47375925353e155177954699 /tests/stm32 | |
| parent | d23c027dd1a1c5f7cdf818750dddf6a250658423 (diff) | |
| parent | b9559c7713bc7f773cdef0df14f1158840d06d06 (diff) | |
Merge pull request #4841 from xoviat/lp3
rtc: use consistent api between stop and non-stop
Diffstat (limited to 'tests/stm32')
| -rw-r--r-- | tests/stm32/Cargo.toml | 1 | ||||
| -rw-r--r-- | tests/stm32/src/bin/rtc.rs | 15 | ||||
| -rw-r--r-- | tests/stm32/src/bin/stop.rs | 11 |
3 files changed, 15 insertions, 12 deletions
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index 1161e827b..e75a4ebb1 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml | |||
| @@ -94,6 +94,7 @@ rand_core = { version = "0.9.1", default-features = false } | |||
| 94 | rand_chacha = { version = "0.9.0", default-features = false } | 94 | rand_chacha = { version = "0.9.0", default-features = false } |
| 95 | static_cell = "2" | 95 | static_cell = "2" |
| 96 | portable-atomic = { version = "1.5", features = [] } | 96 | portable-atomic = { version = "1.5", features = [] } |
| 97 | critical-section = "1.1" | ||
| 97 | 98 | ||
| 98 | chrono = { version = "^0.4", default-features = false, optional = true} | 99 | chrono = { version = "^0.4", default-features = false, optional = true} |
| 99 | sha2 = { version = "0.10.8", default-features = false } | 100 | sha2 = { version = "0.10.8", default-features = false } |
diff --git a/tests/stm32/src/bin/rtc.rs b/tests/stm32/src/bin/rtc.rs index 5c80eb250..43cf4a411 100644 --- a/tests/stm32/src/bin/rtc.rs +++ b/tests/stm32/src/bin/rtc.rs | |||
| @@ -9,11 +9,9 @@ use chrono::{NaiveDate, NaiveDateTime}; | |||
| 9 | use common::*; | 9 | use common::*; |
| 10 | use defmt::assert; | 10 | use defmt::assert; |
| 11 | use embassy_executor::Spawner; | 11 | use embassy_executor::Spawner; |
| 12 | #[cfg(feature = "stop")] | ||
| 13 | use embassy_stm32::low_power::reconfigure_rtc; | ||
| 14 | use embassy_stm32::rcc::LsConfig; | 12 | use embassy_stm32::rcc::LsConfig; |
| 15 | #[cfg(feature = "stop")] | 13 | #[cfg(feature = "stop")] |
| 16 | use embassy_stm32::rtc::RtcTimeProvider; | 14 | use embassy_stm32::rtc::Rtc; |
| 17 | #[cfg(not(feature = "stop"))] | 15 | #[cfg(not(feature = "stop"))] |
| 18 | use embassy_stm32::rtc::{Rtc, RtcConfig}; | 16 | use embassy_stm32::rtc::{Rtc, RtcConfig}; |
| 19 | use embassy_time::Timer; | 17 | use embassy_time::Timer; |
| @@ -31,23 +29,22 @@ async fn main(_spawner: Spawner) { | |||
| 31 | .unwrap(); | 29 | .unwrap(); |
| 32 | 30 | ||
| 33 | #[cfg(not(feature = "stop"))] | 31 | #[cfg(not(feature = "stop"))] |
| 34 | let mut rtc = Rtc::new(p.RTC, RtcConfig::default()); | 32 | let (mut rtc, time_provider) = Rtc::new(p.RTC, RtcConfig::default()); |
| 35 | 33 | ||
| 36 | #[cfg(feature = "stop")] | 34 | #[cfg(feature = "stop")] |
| 37 | let time_provider = RtcTimeProvider::new(p.RTC); | 35 | let (rtc, time_provider) = Rtc::new(p.RTC); |
| 38 | 36 | ||
| 39 | #[cfg(not(feature = "stop"))] | 37 | #[cfg(not(feature = "stop"))] |
| 40 | rtc.set_datetime(now.into()).expect("datetime not set"); | 38 | rtc.set_datetime(now.into()).expect("datetime not set"); |
| 41 | 39 | ||
| 42 | #[cfg(feature = "stop")] | 40 | #[cfg(feature = "stop")] |
| 43 | reconfigure_rtc(|rtc| rtc.set_datetime(now.into()).expect("datetime not set")); | 41 | critical_section::with(|cs| { |
| 42 | rtc.borrow_mut(cs).set_datetime(now.into()).expect("datetime not set"); | ||
| 43 | }); | ||
| 44 | 44 | ||
| 45 | info!("Waiting 5 seconds"); | 45 | info!("Waiting 5 seconds"); |
| 46 | Timer::after_millis(5000).await; | 46 | Timer::after_millis(5000).await; |
| 47 | 47 | ||
| 48 | #[cfg(not(feature = "stop"))] | ||
| 49 | let then: NaiveDateTime = rtc.now().unwrap().into(); | ||
| 50 | #[cfg(feature = "stop")] | ||
| 51 | let then: NaiveDateTime = time_provider.now().unwrap().into(); | 48 | let then: NaiveDateTime = time_provider.now().unwrap().into(); |
| 52 | 49 | ||
| 53 | let seconds = (then - now).num_seconds(); | 50 | let seconds = (then - now).num_seconds(); |
diff --git a/tests/stm32/src/bin/stop.rs b/tests/stm32/src/bin/stop.rs index a9dbac676..4b3a775bb 100644 --- a/tests/stm32/src/bin/stop.rs +++ b/tests/stm32/src/bin/stop.rs | |||
| @@ -10,8 +10,9 @@ use common::*; | |||
| 10 | use cortex_m_rt::entry; | 10 | use cortex_m_rt::entry; |
| 11 | use embassy_executor::Spawner; | 11 | use embassy_executor::Spawner; |
| 12 | use embassy_stm32::Config; | 12 | use embassy_stm32::Config; |
| 13 | use embassy_stm32::low_power::{Executor, StopMode, reconfigure_rtc, stop_ready}; | 13 | use embassy_stm32::low_power::{Executor, StopMode, stop_ready}; |
| 14 | use embassy_stm32::rcc::LsConfig; | 14 | use embassy_stm32::rcc::LsConfig; |
| 15 | use embassy_stm32::rtc::Rtc; | ||
| 15 | use embassy_time::Timer; | 16 | use embassy_time::Timer; |
| 16 | 17 | ||
| 17 | #[entry] | 18 | #[entry] |
| @@ -56,7 +57,7 @@ async fn async_main(spawner: Spawner) { | |||
| 56 | config.rcc.hsi = Some(HSIPrescaler::DIV4); // 64 MHz HSI will need a /4 | 57 | config.rcc.hsi = Some(HSIPrescaler::DIV4); // 64 MHz HSI will need a /4 |
| 57 | } | 58 | } |
| 58 | 59 | ||
| 59 | let _p = init_with_config(config); | 60 | let p = init_with_config(config); |
| 60 | info!("Hello World!"); | 61 | info!("Hello World!"); |
| 61 | 62 | ||
| 62 | let now = NaiveDate::from_ymd_opt(2020, 5, 15) | 63 | let now = NaiveDate::from_ymd_opt(2020, 5, 15) |
| @@ -64,7 +65,11 @@ async fn async_main(spawner: Spawner) { | |||
| 64 | .and_hms_opt(10, 30, 15) | 65 | .and_hms_opt(10, 30, 15) |
| 65 | .unwrap(); | 66 | .unwrap(); |
| 66 | 67 | ||
| 67 | reconfigure_rtc(|rtc| rtc.set_datetime(now.into()).expect("datetime not set")); | 68 | let (rtc, _time_provider) = Rtc::new(p.RTC); |
| 69 | |||
| 70 | critical_section::with(|cs| { | ||
| 71 | rtc.borrow_mut(cs).set_datetime(now.into()).expect("datetime not set"); | ||
| 72 | }); | ||
| 68 | 73 | ||
| 69 | spawner.spawn(task_1().unwrap()); | 74 | spawner.spawn(task_1().unwrap()); |
| 70 | spawner.spawn(task_2().unwrap()); | 75 | spawner.spawn(task_2().unwrap()); |
