diff options
| author | xoviat <[email protected]> | 2025-12-19 17:56:09 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-19 17:56:09 +0000 |
| commit | ecb395e9334360994a9201c0ad3e7e921aa2d81a (patch) | |
| tree | 77fe36797942a3f1bba868bb3fd7229077bef528 /embassy-stm32/src/low_power.rs | |
| parent | 905bdfa7662c2ac5d2dfc81219c9704955473253 (diff) | |
| parent | 941707372099ae5b82e8adf48ec4d0470a1642de (diff) | |
Merge pull request #5108 from liebman/low-power-stm32wl5x
low-power: stm32wl5x
Diffstat (limited to 'embassy-stm32/src/low_power.rs')
| -rw-r--r-- | embassy-stm32/src/low_power.rs | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/embassy-stm32/src/low_power.rs b/embassy-stm32/src/low_power.rs index 02116e08a..71befcf34 100644 --- a/embassy-stm32/src/low_power.rs +++ b/embassy-stm32/src/low_power.rs | |||
| @@ -136,10 +136,10 @@ pub fn stop_ready(stop_mode: StopMode) -> bool { | |||
| 136 | }) | 136 | }) |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | #[cfg(any(stm32l4, stm32l5, stm32u5, stm32wba, stm32wb, stm32wlex, stm32u0))] | 139 | #[cfg(any(stm32l4, stm32l5, stm32u5, stm32wba, stm32wb, stm32wl, stm32u0))] |
| 140 | use crate::pac::pwr::vals::Lpms; | 140 | use crate::pac::pwr::vals::Lpms; |
| 141 | 141 | ||
| 142 | #[cfg(any(stm32l4, stm32l5, stm32u5, stm32wba, stm32wb, stm32wlex, stm32u0))] | 142 | #[cfg(any(stm32l4, stm32l5, stm32u5, stm32wba, stm32wb, stm32wl, stm32u0))] |
| 143 | impl Into<Lpms> for StopMode { | 143 | impl Into<Lpms> for StopMode { |
| 144 | fn into(self) -> Lpms { | 144 | fn into(self) -> Lpms { |
| 145 | match self { | 145 | match self { |
| @@ -184,19 +184,28 @@ impl Executor { | |||
| 184 | 184 | ||
| 185 | pub(crate) unsafe fn on_wakeup_irq_or_event() { | 185 | pub(crate) unsafe fn on_wakeup_irq_or_event() { |
| 186 | if !get_driver().is_stopped() { | 186 | if !get_driver().is_stopped() { |
| 187 | trace!("low power: time driver not stopped!"); | ||
| 187 | return; | 188 | return; |
| 188 | } | 189 | } |
| 189 | 190 | ||
| 190 | critical_section::with(|cs| { | 191 | critical_section::with(|cs| { |
| 191 | #[cfg(any(stm32wlex, stm32wb))] | 192 | #[cfg(any(stm32wl, stm32wb))] |
| 192 | { | 193 | { |
| 193 | let es = crate::pac::PWR.extscr().read(); | 194 | let es = crate::pac::PWR.extscr().read(); |
| 194 | #[cfg(stm32wlex)] | 195 | #[cfg(stm32wl)] |
| 195 | match (es.c1stopf(), es.c1stop2f()) { | 196 | match (es.c1stopf(), es.c1stop2f()) { |
| 196 | (true, false) => debug!("low power: wake from STOP1"), | 197 | (true, false) => debug!("low power: cpu1 wake from STOP1"), |
| 197 | (false, true) => debug!("low power: wake from STOP2"), | 198 | (false, true) => debug!("low power: cpu1 wake from STOP2"), |
| 198 | (true, true) => debug!("low power: wake from STOP1 and STOP2 ???"), | 199 | (true, true) => debug!("low power: cpu1 wake from STOP1 and STOP2 ???"), |
| 199 | (false, false) => trace!("low power: stop mode not entered"), | 200 | (false, false) => trace!("low power: cpu1 stop mode not entered"), |
| 201 | }; | ||
| 202 | #[cfg(stm32wl5x)] | ||
| 203 | // TODO: only for the current cpu | ||
| 204 | match (es.c2stopf(), es.c2stop2f()) { | ||
| 205 | (true, false) => debug!("low power: cpu2 wake from STOP1"), | ||
| 206 | (false, true) => debug!("low power: cpu2 wake from STOP2"), | ||
| 207 | (true, true) => debug!("low power: cpu2 wake from STOP1 and STOP2 ???"), | ||
| 208 | (false, false) => trace!("low power: cpu2 stop mode not entered"), | ||
| 200 | }; | 209 | }; |
| 201 | 210 | ||
| 202 | #[cfg(stm32wb)] | 211 | #[cfg(stm32wb)] |
| @@ -206,9 +215,6 @@ impl Executor { | |||
| 206 | (true, true) => debug!("low power: cpu1 and cpu2 wake from STOP"), | 215 | (true, true) => debug!("low power: cpu1 and cpu2 wake from STOP"), |
| 207 | (false, false) => trace!("low power: stop mode not entered"), | 216 | (false, false) => trace!("low power: stop mode not entered"), |
| 208 | }; | 217 | }; |
| 209 | crate::pac::PWR.extscr().modify(|w| { | ||
| 210 | w.set_c1cssf(false); | ||
| 211 | }); | ||
| 212 | 218 | ||
| 213 | let _has_stopped2 = { | 219 | let _has_stopped2 = { |
| 214 | #[cfg(stm32wb)] | 220 | #[cfg(stm32wb)] |
| @@ -220,6 +226,12 @@ impl Executor { | |||
| 220 | { | 226 | { |
| 221 | es.c1stop2f() | 227 | es.c1stop2f() |
| 222 | } | 228 | } |
| 229 | |||
| 230 | #[cfg(stm32wl5x)] | ||
| 231 | { | ||
| 232 | // TODO: I think we could just use c1stop2f() here as it won't enter a stop mode unless BOTH cpus will enter it. | ||
| 233 | es.c1stop2f() | es.c2stop2f() | ||
| 234 | } | ||
| 223 | }; | 235 | }; |
| 224 | 236 | ||
| 225 | #[cfg(not(stm32wb))] | 237 | #[cfg(not(stm32wb))] |
| @@ -235,6 +247,13 @@ impl Executor { | |||
| 235 | REFCOUNT_STOP1 = 0; | 247 | REFCOUNT_STOP1 = 0; |
| 236 | } | 248 | } |
| 237 | } | 249 | } |
| 250 | // Clear all stop flags | ||
| 251 | #[cfg(stm32wl)] | ||
| 252 | crate::pac::PWR.extscr().modify(|w| { | ||
| 253 | w.set_c1cssf(true); | ||
| 254 | #[cfg(stm32wl5x)] | ||
| 255 | w.set_c2cssf(true); | ||
| 256 | }); | ||
| 238 | } | 257 | } |
| 239 | get_driver().resume_time(cs); | 258 | get_driver().resume_time(cs); |
| 240 | 259 | ||
| @@ -337,7 +356,7 @@ impl Executor { | |||
| 337 | #[cfg(all(stm32wb, feature = "low-power"))] | 356 | #[cfg(all(stm32wb, feature = "low-power"))] |
| 338 | self.configure_stop_stm32wb(_cs)?; | 357 | self.configure_stop_stm32wb(_cs)?; |
| 339 | 358 | ||
| 340 | #[cfg(any(stm32l4, stm32l5, stm32u5, stm32u0, stm32wb, stm32wba, stm32wlex))] | 359 | #[cfg(any(stm32l4, stm32l5, stm32u5, stm32u0, stm32wb, stm32wba, stm32wl))] |
| 341 | crate::pac::PWR.cr1().modify(|m| m.set_lpms(stop_mode.into())); | 360 | crate::pac::PWR.cr1().modify(|m| m.set_lpms(stop_mode.into())); |
| 342 | #[cfg(stm32h5)] | 361 | #[cfg(stm32h5)] |
| 343 | crate::pac::PWR.pmcr().modify(|v| { | 362 | crate::pac::PWR.pmcr().modify(|v| { |
| @@ -352,9 +371,11 @@ impl Executor { | |||
| 352 | fn configure_pwr(&self) { | 371 | fn configure_pwr(&self) { |
| 353 | Self::get_scb().clear_sleepdeep(); | 372 | Self::get_scb().clear_sleepdeep(); |
| 354 | // Clear any previous stop flags | 373 | // Clear any previous stop flags |
| 355 | #[cfg(stm32wlex)] | 374 | #[cfg(stm32wl)] |
| 356 | crate::pac::PWR.extscr().modify(|w| { | 375 | crate::pac::PWR.extscr().modify(|w| { |
| 357 | w.set_c1cssf(true); | 376 | w.set_c1cssf(true); |
| 377 | #[cfg(stm32wl5x)] | ||
| 378 | w.set_c2cssf(true); | ||
| 358 | }); | 379 | }); |
| 359 | 380 | ||
| 360 | #[cfg(feature = "low-power-pender")] | 381 | #[cfg(feature = "low-power-pender")] |
