aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/stm32/Cargo.toml1
-rw-r--r--tests/stm32/src/bin/rtc.rs15
-rw-r--r--tests/stm32/src/bin/stop.rs11
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 }
94rand_chacha = { version = "0.9.0", default-features = false } 94rand_chacha = { version = "0.9.0", default-features = false }
95static_cell = "2" 95static_cell = "2"
96portable-atomic = { version = "1.5", features = [] } 96portable-atomic = { version = "1.5", features = [] }
97critical-section = "1.1"
97 98
98chrono = { version = "^0.4", default-features = false, optional = true} 99chrono = { version = "^0.4", default-features = false, optional = true}
99sha2 = { version = "0.10.8", default-features = false } 100sha2 = { 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};
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();
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::*;
10use cortex_m_rt::entry; 10use cortex_m_rt::entry;
11use embassy_executor::Spawner; 11use embassy_executor::Spawner;
12use embassy_stm32::Config; 12use embassy_stm32::Config;
13use embassy_stm32::low_power::{Executor, StopMode, reconfigure_rtc, stop_ready}; 13use embassy_stm32::low_power::{Executor, StopMode, stop_ready};
14use embassy_stm32::rcc::LsConfig; 14use embassy_stm32::rcc::LsConfig;
15use embassy_stm32::rtc::Rtc;
15use embassy_time::Timer; 16use 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());