From bcb4f0a43548a5842aaa3b734998b2e7b25f5188 Mon Sep 17 00:00:00 2001 From: xoviat Date: Mon, 15 Dec 2025 09:15:14 -0600 Subject: stm32: block stop2 for wle and misc fixes --- embassy-stm32/src/i2c/mod.rs | 2 +- embassy-stm32/src/rcc/mod.rs | 28 ++++++++++++++++++++++++++-- embassy-stm32/src/sdmmc/mod.rs | 13 +++++++------ embassy-stm32/src/spi/mod.rs | 2 +- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index 0bf430ffc..0aa2d1da9 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs @@ -129,7 +129,7 @@ impl<'d> Drop for I2CDropGuard<'d> { x.set_as_disconnected() } - self.info.rcc.disable(); + self.info.rcc.disable_without_stop(); } } diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 2a9a1595a..d25c922d8 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs @@ -311,6 +311,15 @@ impl RccInfo { increment_stop_refcount(_cs, self.stop_mode); } + #[allow(dead_code)] + fn increment_minimum_stop_refcount_with_cs(&self, _cs: CriticalSection) { + #[cfg(all(stm32wlex, feature = "low-power"))] + match self.stop_mode { + StopMode::Stop1 | StopMode::Stop2 => increment_stop_refcount(_cs, StopMode::Stop2), + _ => {} + } + } + #[allow(dead_code)] pub(crate) fn increment_stop_refcount(&self) { #[cfg(feature = "low-power")] @@ -323,6 +332,15 @@ impl RccInfo { decrement_stop_refcount(_cs, self.stop_mode); } + #[allow(dead_code)] + fn decrement_minimum_stop_refcount_with_cs(&self, _cs: CriticalSection) { + #[cfg(all(stm32wlex, feature = "low-power"))] + match self.stop_mode { + StopMode::Stop1 | StopMode::Stop2 => decrement_stop_refcount(_cs, StopMode::Stop2), + _ => {} + } + } + #[allow(dead_code)] pub(crate) fn decrement_stop_refcount(&self) { #[cfg(feature = "low-power")] @@ -339,7 +357,10 @@ impl RccInfo { #[allow(dead_code)] pub(crate) fn enable_and_reset_without_stop(&self) { - critical_section::with(|cs| self.enable_and_reset_with_cs(cs)) + critical_section::with(|cs| { + self.enable_and_reset_with_cs(cs); + self.increment_minimum_stop_refcount_with_cs(cs); + }) } // TODO: should this be `unsafe`? @@ -353,7 +374,10 @@ impl RccInfo { // TODO: should this be `unsafe`? #[allow(dead_code)] pub(crate) fn disable_without_stop(&self) { - critical_section::with(|cs| self.disable_with_cs(cs)) + critical_section::with(|cs| { + self.disable_with_cs(cs); + self.decrement_minimum_stop_refcount_with_cs(cs); + }) } #[allow(dead_code)] diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index e716fc348..cfe18ef52 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs @@ -142,34 +142,34 @@ impl Default for Signalling { const fn aligned_mut(x: &mut [u32]) -> &mut Aligned { let len = x.len() * 4; - unsafe { core::mem::transmute(slice::from_raw_parts_mut(x.as_mut_ptr() as _, len)) } + unsafe { core::mem::transmute(slice::from_raw_parts_mut(x.as_mut_ptr() as *mut u8, len)) } } const fn slice8_mut(x: &mut [u32]) -> &mut [u8] { let len = x.len() * 4; - unsafe { slice::from_raw_parts_mut(x.as_mut_ptr() as _, len) } + unsafe { slice::from_raw_parts_mut(x.as_mut_ptr() as *mut u8, len) } } #[allow(unused)] const fn slice32_mut(x: &mut Aligned) -> &mut [u32] { let len = (size_of_val(x) + 4 - 1) / 4; - unsafe { slice::from_raw_parts_mut(x as *mut Aligned as *mut _, len) } + unsafe { slice::from_raw_parts_mut(x as *mut Aligned as *mut u32, len) } } const fn aligned_ref(x: &[u32]) -> &Aligned { let len = x.len() * 4; - unsafe { core::mem::transmute(slice::from_raw_parts(x.as_ptr() as _, len)) } + unsafe { core::mem::transmute(slice::from_raw_parts(x.as_ptr() as *const u8, len)) } } const fn slice8_ref(x: &[u32]) -> &[u8] { let len = x.len() * 4; - unsafe { slice::from_raw_parts(x.as_ptr() as _, len) } + unsafe { slice::from_raw_parts(x.as_ptr() as *const u8, len) } } #[allow(unused)] const fn slice32_ref(x: &Aligned) -> &[u32] { let len = (size_of_val(x) + 4 - 1) / 4; - unsafe { slice::from_raw_parts(x as *const Aligned as *const _, len) } + unsafe { slice::from_raw_parts(x as *const Aligned as *const u32, len) } } /// Errors @@ -1179,6 +1179,7 @@ impl<'d> Drop for Sdmmc<'d> { fn drop(&mut self) { // T::Interrupt::disable(); self.on_drop(); + self.info.rcc.disable_without_stop(); critical_section::with(|_| { self.clk.set_as_disconnected(); diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index af51b79b4..13ff31a34 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs @@ -1126,7 +1126,7 @@ impl<'d, M: PeriMode, CM: CommunicationMode> Drop for Spi<'d, M, CM> { self.miso.as_ref().map(|x| x.set_as_disconnected()); self.nss.as_ref().map(|x| x.set_as_disconnected()); - self.info.rcc.disable(); + self.info.rcc.disable_without_stop(); } } -- cgit