aboutsummaryrefslogtreecommitdiff
path: root/tests/stm32/src/bin/rtc.rs
diff options
context:
space:
mode:
authorxoviat <[email protected]>2025-11-04 16:35:07 -0600
committerxoviat <[email protected]>2025-11-04 16:35:07 -0600
commitb9559c7713bc7f773cdef0df14f1158840d06d06 (patch)
treed5e126d6c2d891bb47375925353e155177954699 /tests/stm32/src/bin/rtc.rs
parentd23c027dd1a1c5f7cdf818750dddf6a250658423 (diff)
rtc: use consistent api between stop and non-stop
Diffstat (limited to 'tests/stm32/src/bin/rtc.rs')
-rw-r--r--tests/stm32/src/bin/rtc.rs15
1 files changed, 6 insertions, 9 deletions
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};
9use common::*; 9use common::*;
10use defmt::assert; 10use defmt::assert;
11use embassy_executor::Spawner; 11use embassy_executor::Spawner;
12#[cfg(feature = "stop")]
13use embassy_stm32::low_power::reconfigure_rtc;
14use embassy_stm32::rcc::LsConfig; 12use embassy_stm32::rcc::LsConfig;
15#[cfg(feature = "stop")] 13#[cfg(feature = "stop")]
16use embassy_stm32::rtc::RtcTimeProvider; 14use embassy_stm32::rtc::Rtc;
17#[cfg(not(feature = "stop"))] 15#[cfg(not(feature = "stop"))]
18use embassy_stm32::rtc::{Rtc, RtcConfig}; 16use embassy_stm32::rtc::{Rtc, RtcConfig};
19use embassy_time::Timer; 17use 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();