aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxoviat <[email protected]>2023-10-23 16:26:34 -0500
committerxoviat <[email protected]>2023-10-23 16:26:34 -0500
commitdf4aa0fe253252734dacd555364f5613044f7ecf (patch)
tree8f11004719b10ce77475f0193b3ddc2c9bb8ba16
parente70c531d3d28565b6926d99d8e977c4df6c13c60 (diff)
stm32: fix low-power test
-rw-r--r--embassy-stm32/src/rcc/f4f7.rs23
-rw-r--r--embassy-stm32/src/rtc/mod.rs6
-rw-r--r--tests/stm32/src/bin/stop.rs4
3 files changed, 25 insertions, 8 deletions
diff --git a/embassy-stm32/src/rcc/f4f7.rs b/embassy-stm32/src/rcc/f4f7.rs
index 3f9a2be67..7cc076efa 100644
--- a/embassy-stm32/src/rcc/f4f7.rs
+++ b/embassy-stm32/src/rcc/f4f7.rs
@@ -152,9 +152,9 @@ pub(crate) unsafe fn init(config: Config) {
152 source: config.pll_src, 152 source: config.pll_src,
153 }; 153 };
154 let pll = init_pll(PllInstance::Pll, config.pll, &pll_input); 154 let pll = init_pll(PllInstance::Pll, config.pll, &pll_input);
155 #[cfg(any(all(stm32f4, not(stm32f410)), stm32f7))] 155 #[cfg(any(all(stm32f4, not(any(stm32f410, stm32f429))), stm32f7))]
156 let _plli2s = init_pll(PllInstance::Plli2s, config.plli2s, &pll_input); 156 let _plli2s = init_pll(PllInstance::Plli2s, config.plli2s, &pll_input);
157 #[cfg(any(stm32f446, stm32f427, stm32f437, stm32f4x9, stm32f7))] 157 #[cfg(all(any(stm32f446, stm32f427, stm32f437, stm32f4x9, stm32f7), not(stm32f429)))]
158 let _pllsai = init_pll(PllInstance::Pllsai, config.pllsai, &pll_input); 158 let _pllsai = init_pll(PllInstance::Pllsai, config.pllsai, &pll_input);
159 159
160 // Configure sysclk 160 // Configure sysclk
@@ -197,15 +197,25 @@ pub(crate) unsafe fn init(config: Config) {
197 pclk2_tim, 197 pclk2_tim,
198 rtc, 198 rtc,
199 pll1_q: pll.q, 199 pll1_q: pll.q,
200 #[cfg(all(rcc_f4, not(stm32f410)))] 200 #[cfg(all(rcc_f4, not(any(stm32f410, stm32f429))))]
201 plli2s1_q: _plli2s.q, 201 plli2s1_q: _plli2s.q,
202 #[cfg(all(rcc_f4, not(stm32f410)))] 202 #[cfg(all(rcc_f4, not(any(stm32f410, stm32f429))))]
203 plli2s1_r: _plli2s.r, 203 plli2s1_r: _plli2s.r,
204 204
205 #[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f446, stm32f469, stm32f479))] 205 #[cfg(stm32f429)]
206 plli2s1_q: None,
207 #[cfg(stm32f429)]
208 plli2s1_r: None,
209
210 #[cfg(any(stm32f427, stm32f437, stm32f439, stm32f446, stm32f469, stm32f479))]
206 pllsai1_q: _pllsai.q, 211 pllsai1_q: _pllsai.q,
207 #[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f446, stm32f469, stm32f479))] 212 #[cfg(any(stm32f427, stm32f437, stm32f439, stm32f446, stm32f469, stm32f479))]
208 pllsai1_r: _pllsai.r, 213 pllsai1_r: _pllsai.r,
214
215 #[cfg(stm32f429)]
216 pllsai1_q: None,
217 #[cfg(stm32f429)]
218 pllsai1_r: None,
209 }); 219 });
210} 220}
211 221
@@ -223,6 +233,7 @@ struct PllOutput {
223 r: Option<Hertz>, 233 r: Option<Hertz>,
224} 234}
225 235
236#[allow(dead_code)]
226#[derive(PartialEq, Eq, Clone, Copy)] 237#[derive(PartialEq, Eq, Clone, Copy)]
227enum PllInstance { 238enum PllInstance {
228 Pll, 239 Pll,
diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs
index 552dcc76f..d77443a9c 100644
--- a/embassy-stm32/src/rtc/mod.rs
+++ b/embassy-stm32/src/rtc/mod.rs
@@ -184,7 +184,11 @@ impl Default for RtcCalibrationCyclePeriod {
184impl Rtc { 184impl Rtc {
185 pub fn new(_rtc: impl Peripheral<P = RTC>, rtc_config: RtcConfig) -> Self { 185 pub fn new(_rtc: impl Peripheral<P = RTC>, rtc_config: RtcConfig) -> Self {
186 #[cfg(not(any(stm32l0, stm32f3, stm32l1, stm32f0, stm32f2)))] 186 #[cfg(not(any(stm32l0, stm32f3, stm32l1, stm32f0, stm32f2)))]
187 <RTC as crate::rcc::sealed::RccPeripheral>::enable_and_reset(); 187 critical_section::with(|cs| {
188 <RTC as crate::rcc::sealed::RccPeripheral>::enable_and_reset_with_cs(cs);
189 #[cfg(feature = "low-power")]
190 crate::rcc::clock_refcount_sub(cs);
191 });
188 192
189 let mut this = Self { 193 let mut this = Self {
190 #[cfg(feature = "low-power")] 194 #[cfg(feature = "low-power")]
diff --git a/tests/stm32/src/bin/stop.rs b/tests/stm32/src/bin/stop.rs
index f38924c90..4f62ecae2 100644
--- a/tests/stm32/src/bin/stop.rs
+++ b/tests/stm32/src/bin/stop.rs
@@ -11,7 +11,7 @@ use common::*;
11use cortex_m_rt::entry; 11use cortex_m_rt::entry;
12use embassy_executor::Spawner; 12use embassy_executor::Spawner;
13use embassy_stm32::low_power::{stop_with_rtc, Executor}; 13use embassy_stm32::low_power::{stop_with_rtc, Executor};
14use embassy_stm32::rcc::LsConfig; 14use embassy_stm32::rcc::{low_power_ready, LsConfig};
15use embassy_stm32::rtc::{Rtc, RtcConfig}; 15use embassy_stm32::rtc::{Rtc, RtcConfig};
16use embassy_stm32::Config; 16use embassy_stm32::Config;
17use embassy_time::Timer; 17use embassy_time::Timer;
@@ -28,6 +28,7 @@ fn main() -> ! {
28async fn task_1() { 28async fn task_1() {
29 for _ in 0..9 { 29 for _ in 0..9 {
30 info!("task 1: waiting for 500ms..."); 30 info!("task 1: waiting for 500ms...");
31 defmt::assert!(low_power_ready());
31 Timer::after_millis(500).await; 32 Timer::after_millis(500).await;
32 } 33 }
33} 34}
@@ -36,6 +37,7 @@ async fn task_1() {
36async fn task_2() { 37async fn task_2() {
37 for _ in 0..5 { 38 for _ in 0..5 {
38 info!("task 2: waiting for 1000ms..."); 39 info!("task 2: waiting for 1000ms...");
40 defmt::assert!(low_power_ready());
39 Timer::after_millis(1000).await; 41 Timer::after_millis(1000).await;
40 } 42 }
41 43