aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/hsem/mod.rs9
-rw-r--r--embassy-stm32/src/low_power.rs24
-rw-r--r--tests/stm32/Cargo.toml2
-rw-r--r--tests/stm32/src/bin/hsem.rs3
4 files changed, 27 insertions, 11 deletions
diff --git a/embassy-stm32/src/hsem/mod.rs b/embassy-stm32/src/hsem/mod.rs
index 5f1ed9b09..e62de0454 100644
--- a/embassy-stm32/src/hsem/mod.rs
+++ b/embassy-stm32/src/hsem/mod.rs
@@ -293,8 +293,13 @@ impl<T: Instance> HardwareSemaphore<T> {
293} 293}
294 294
295#[cfg(all(stm32wb, feature = "low-power"))] 295#[cfg(all(stm32wb, feature = "low-power"))]
296pub(crate) fn init_hsem(_cs: CriticalSection) { 296pub(crate) fn init_hsem(cs: CriticalSection) {
297 rcc::enable_and_reset::<crate::peripherals::HSEM>(); 297 rcc::enable_and_reset_with_cs::<crate::peripherals::HSEM>(cs);
298
299 unsafe {
300 crate::rcc::REFCOUNT_STOP1 = 0;
301 crate::rcc::REFCOUNT_STOP2 = 0;
302 }
298} 303}
299 304
300struct State { 305struct State {
diff --git a/embassy-stm32/src/low_power.rs b/embassy-stm32/src/low_power.rs
index 15478eed4..f35eb71e4 100644
--- a/embassy-stm32/src/low_power.rs
+++ b/embassy-stm32/src/low_power.rs
@@ -147,17 +147,17 @@ pub enum StopMode {
147 Stop2, 147 Stop2,
148} 148}
149 149
150#[cfg(any(stm32l4, stm32l5, stm32u5, stm32wba, stm32wlex, stm32u0))] 150#[cfg(any(stm32l4, stm32l5, stm32u5, stm32wba, stm32wb, stm32wlex, stm32u0))]
151use crate::pac::pwr::vals::Lpms; 151use crate::pac::pwr::vals::Lpms;
152 152
153#[cfg(any(stm32l4, stm32l5, stm32u5, stm32wba, stm32wlex, stm32u0))] 153#[cfg(any(stm32l4, stm32l5, stm32u5, stm32wba, stm32wb, stm32wlex, stm32u0))]
154impl Into<Lpms> for StopMode { 154impl Into<Lpms> for StopMode {
155 fn into(self) -> Lpms { 155 fn into(self) -> Lpms {
156 match self { 156 match self {
157 StopMode::Stop1 => Lpms::STOP1, 157 StopMode::Stop1 => Lpms::STOP1,
158 #[cfg(not(stm32wba))] 158 #[cfg(not(any(stm32wb, stm32wba)))]
159 StopMode::Stop2 => Lpms::STOP2, 159 StopMode::Stop2 => Lpms::STOP2,
160 #[cfg(stm32wba)] 160 #[cfg(any(stm32wb, stm32wba))]
161 StopMode::Stop2 => Lpms::STOP1, // TODO: WBA has no STOP2? 161 StopMode::Stop2 => Lpms::STOP1, // TODO: WBA has no STOP2?
162 } 162 }
163 } 163 }
@@ -237,13 +237,15 @@ impl Executor {
237 trace!("low power: stop 1"); 237 trace!("low power: stop 1");
238 Some(StopMode::Stop1) 238 Some(StopMode::Stop1)
239 } else { 239 } else {
240 trace!("low power: not ready to stop"); 240 trace!("low power: not ready to stop (refcount_stop1: {})", unsafe {
241 REFCOUNT_STOP1
242 });
241 None 243 None
242 } 244 }
243 } 245 }
244 246
245 #[cfg(all(stm32wb, feature = "low-power"))] 247 #[cfg(all(stm32wb, feature = "low-power"))]
246 fn configure_stop_stm32wb(&self, _stop_mode: StopMode) -> Result<(), ()> { 248 fn configure_stop_stm32wb(&self) -> Result<(), ()> {
247 use core::task::Poll; 249 use core::task::Poll;
248 250
249 use embassy_futures::poll_once; 251 use embassy_futures::poll_once;
@@ -252,14 +254,20 @@ impl Executor {
252 use crate::pac::rcc::vals::{Smps, Sw}; 254 use crate::pac::rcc::vals::{Smps, Sw};
253 use crate::pac::{PWR, RCC}; 255 use crate::pac::{PWR, RCC};
254 256
257 trace!("low power: trying to get sem3");
258
255 let sem3_mutex = match poll_once(HardwareSemaphoreChannel::<crate::peripherals::HSEM>::new(3).lock(0)) { 259 let sem3_mutex = match poll_once(HardwareSemaphoreChannel::<crate::peripherals::HSEM>::new(3).lock(0)) {
256 Poll::Pending => None, 260 Poll::Pending => None,
257 Poll::Ready(mutex) => Some(mutex), 261 Poll::Ready(mutex) => Some(mutex),
258 } 262 }
259 .ok_or(())?; 263 .ok_or(())?;
260 264
265 trace!("low power: got sem3");
266
261 let sem4_mutex = HardwareSemaphoreChannel::<crate::peripherals::HSEM>::new(4).try_lock(0); 267 let sem4_mutex = HardwareSemaphoreChannel::<crate::peripherals::HSEM>::new(4).try_lock(0);
262 if let Some(sem4_mutex) = sem4_mutex { 268 if let Some(sem4_mutex) = sem4_mutex {
269 trace!("low power: got sem4");
270
263 if PWR.extscr().read().c2ds() { 271 if PWR.extscr().read().c2ds() {
264 drop(sem4_mutex); 272 drop(sem4_mutex);
265 } else { 273 } else {
@@ -297,9 +305,9 @@ impl Executor {
297 #[allow(unused_variables)] 305 #[allow(unused_variables)]
298 fn configure_stop(&self, stop_mode: StopMode) -> Result<(), ()> { 306 fn configure_stop(&self, stop_mode: StopMode) -> Result<(), ()> {
299 #[cfg(all(stm32wb, feature = "low-power"))] 307 #[cfg(all(stm32wb, feature = "low-power"))]
300 self.configure_stop_stm32wb(stop_mode)?; 308 self.configure_stop_stm32wb()?;
301 309
302 #[cfg(any(stm32l4, stm32l5, stm32u5, stm32u0, stm32wba, stm32wlex))] 310 #[cfg(any(stm32l4, stm32l5, stm32u5, stm32u0, stm32wb, stm32wba, stm32wlex))]
303 crate::pac::PWR.cr1().modify(|m| m.set_lpms(stop_mode.into())); 311 crate::pac::PWR.cr1().modify(|m| m.set_lpms(stop_mode.into()));
304 #[cfg(stm32h5)] 312 #[cfg(stm32h5)]
305 crate::pac::PWR.pmcr().modify(|v| { 313 crate::pac::PWR.pmcr().modify(|v| {
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml
index f5684d4df..8fcb6b2b4 100644
--- a/tests/stm32/Cargo.toml
+++ b/tests/stm32/Cargo.toml
@@ -31,7 +31,7 @@ stm32l4r5zi = ["embassy-stm32/stm32l4r5zi", "chrono", "not-gpdma", "rng", "dual-
31stm32l552ze = ["embassy-stm32/stm32l552ze", "not-gpdma", "rng", "hash", "dual-bank"] 31stm32l552ze = ["embassy-stm32/stm32l552ze", "not-gpdma", "rng", "hash", "dual-bank"]
32stm32u585ai = ["embassy-stm32/stm32u585ai", "spi-v345", "chrono", "rng", "hash", "cordic"] 32stm32u585ai = ["embassy-stm32/stm32u585ai", "spi-v345", "chrono", "rng", "hash", "cordic"]
33stm32u5a5zj = ["embassy-stm32/stm32u5a5zj", "spi-v345", "chrono", "rng", "hash"] # FIXME: cordic test cause it crash 33stm32u5a5zj = ["embassy-stm32/stm32u5a5zj", "spi-v345", "chrono", "rng", "hash"] # FIXME: cordic test cause it crash
34stm32wb55rg = ["embassy-stm32/stm32wb55rg", "chrono", "not-gpdma", "ble", "mac" , "rng", "hsem"] 34stm32wb55rg = ["embassy-stm32/stm32wb55rg", "chrono", "not-gpdma", "ble", "mac" , "rng", "hsem", "stop"]
35stm32wba52cg = ["embassy-stm32/stm32wba52cg", "spi-v345", "chrono", "rng", "hash"] 35stm32wba52cg = ["embassy-stm32/stm32wba52cg", "spi-v345", "chrono", "rng", "hash"]
36stm32wl55jc = ["embassy-stm32/stm32wl55jc-cm4", "not-gpdma", "rng", "chrono", "hsem"] 36stm32wl55jc = ["embassy-stm32/stm32wl55jc-cm4", "not-gpdma", "rng", "chrono", "hsem"]
37stm32f091rc = ["embassy-stm32/stm32f091rc", "cm0", "not-gpdma", "chrono"] 37stm32f091rc = ["embassy-stm32/stm32f091rc", "cm0", "not-gpdma", "chrono"]
diff --git a/tests/stm32/src/bin/hsem.rs b/tests/stm32/src/bin/hsem.rs
index 19648997c..fa69f22b2 100644
--- a/tests/stm32/src/bin/hsem.rs
+++ b/tests/stm32/src/bin/hsem.rs
@@ -30,6 +30,9 @@ async fn main(_spawner: Spawner) {
30 // 30 //
31 // hsem.channel_for(SemaphoreNumber::Channel5).unlock(0); 31 // hsem.channel_for(SemaphoreNumber::Channel5).unlock(0);
32 32
33 #[cfg(feature = "stm32wb55rg")]
34 let [_channel1, _channel2, mut channel5, _channel6] = hsem.split();
35 #[cfg(not(feature = "stm32wb55rg"))]
33 let [_channel1, _channel2, _channel3, _channel4, mut channel5, _channel6] = hsem.split(); 36 let [_channel1, _channel2, _channel3, _channel4, mut channel5, _channel6] = hsem.split();
34 37
35 info!("Locking channel 5"); 38 info!("Locking channel 5");