diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-11-25 14:00:28 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-11-25 14:00:28 +0000 |
| commit | 37111a891ca0e55efc6326e518f423e5fc677839 (patch) | |
| tree | 46e665559d8a7b4f48e0efc5dc70f69b07c17098 | |
| parent | 63ac22d8dadc4307fdcc594efa1ec8d70fadd33d (diff) | |
| parent | 1fbb419f72a2663b472f31ae1e172bec0e4e6d1a (diff) | |
Merge pull request #3556 from chrenderle/low-power
low-power: add support for stm32u0
| -rw-r--r-- | embassy-stm32/src/low_power.rs | 18 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/bd.rs | 7 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/low_power.rs | 10 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/mod.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/v3.rs | 14 |
5 files changed, 38 insertions, 13 deletions
diff --git a/embassy-stm32/src/low_power.rs b/embassy-stm32/src/low_power.rs index d74221864..0b87bd95a 100644 --- a/embassy-stm32/src/low_power.rs +++ b/embassy-stm32/src/low_power.rs | |||
| @@ -70,6 +70,7 @@ use crate::rtc::Rtc; | |||
| 70 | 70 | ||
| 71 | static mut EXECUTOR: Option<Executor> = None; | 71 | static mut EXECUTOR: Option<Executor> = None; |
| 72 | 72 | ||
| 73 | #[cfg(not(stm32u0))] | ||
| 73 | foreach_interrupt! { | 74 | foreach_interrupt! { |
| 74 | (RTC, rtc, $block:ident, WKUP, $irq:ident) => { | 75 | (RTC, rtc, $block:ident, WKUP, $irq:ident) => { |
| 75 | #[interrupt] | 76 | #[interrupt] |
| @@ -80,6 +81,17 @@ foreach_interrupt! { | |||
| 80 | }; | 81 | }; |
| 81 | } | 82 | } |
| 82 | 83 | ||
| 84 | #[cfg(stm32u0)] | ||
| 85 | foreach_interrupt! { | ||
| 86 | (RTC, rtc, $block:ident, TAMP, $irq:ident) => { | ||
| 87 | #[interrupt] | ||
| 88 | #[allow(non_snake_case)] | ||
| 89 | unsafe fn $irq() { | ||
| 90 | EXECUTOR.as_mut().unwrap().on_wakeup_irq(); | ||
| 91 | } | ||
| 92 | }; | ||
| 93 | } | ||
| 94 | |||
| 83 | #[allow(dead_code)] | 95 | #[allow(dead_code)] |
| 84 | pub(crate) unsafe fn on_wakeup_irq() { | 96 | pub(crate) unsafe fn on_wakeup_irq() { |
| 85 | EXECUTOR.as_mut().unwrap().on_wakeup_irq(); | 97 | EXECUTOR.as_mut().unwrap().on_wakeup_irq(); |
| @@ -112,10 +124,10 @@ pub enum StopMode { | |||
| 112 | Stop2, | 124 | Stop2, |
| 113 | } | 125 | } |
| 114 | 126 | ||
| 115 | #[cfg(any(stm32l4, stm32l5, stm32u5))] | 127 | #[cfg(any(stm32l4, stm32l5, stm32u5, stm32u0))] |
| 116 | use stm32_metapac::pwr::vals::Lpms; | 128 | use stm32_metapac::pwr::vals::Lpms; |
| 117 | 129 | ||
| 118 | #[cfg(any(stm32l4, stm32l5, stm32u5))] | 130 | #[cfg(any(stm32l4, stm32l5, stm32u5, stm32u0))] |
| 119 | impl Into<Lpms> for StopMode { | 131 | impl Into<Lpms> for StopMode { |
| 120 | fn into(self) -> Lpms { | 132 | fn into(self) -> Lpms { |
| 121 | match self { | 133 | match self { |
| @@ -186,7 +198,7 @@ impl Executor { | |||
| 186 | 198 | ||
| 187 | #[allow(unused_variables)] | 199 | #[allow(unused_variables)] |
| 188 | fn configure_stop(&mut self, stop_mode: StopMode) { | 200 | fn configure_stop(&mut self, stop_mode: StopMode) { |
| 189 | #[cfg(any(stm32l4, stm32l5, stm32u5))] | 201 | #[cfg(any(stm32l4, stm32l5, stm32u5, stm32u0))] |
| 190 | crate::pac::PWR.cr1().modify(|m| m.set_lpms(stop_mode.into())); | 202 | crate::pac::PWR.cr1().modify(|m| m.set_lpms(stop_mode.into())); |
| 191 | #[cfg(stm32h5)] | 203 | #[cfg(stm32h5)] |
| 192 | crate::pac::PWR.pmcr().modify(|v| { | 204 | crate::pac::PWR.pmcr().modify(|v| { |
diff --git a/embassy-stm32/src/rcc/bd.rs b/embassy-stm32/src/rcc/bd.rs index 4aec3756f..791367954 100644 --- a/embassy-stm32/src/rcc/bd.rs +++ b/embassy-stm32/src/rcc/bd.rs | |||
| @@ -159,6 +159,9 @@ impl LsConfig { | |||
| 159 | } else { | 159 | } else { |
| 160 | None | 160 | None |
| 161 | }; | 161 | }; |
| 162 | #[cfg(rcc_u0)] | ||
| 163 | let lse_sysen = Some(lse_en); | ||
| 164 | |||
| 162 | _ = lse_drv; // not all chips have it. | 165 | _ = lse_drv; // not all chips have it. |
| 163 | 166 | ||
| 164 | // Disable backup domain write protection | 167 | // Disable backup domain write protection |
| @@ -199,7 +202,7 @@ impl LsConfig { | |||
| 199 | } | 202 | } |
| 200 | ok &= reg.lseon() == lse_en; | 203 | ok &= reg.lseon() == lse_en; |
| 201 | ok &= reg.lsebyp() == lse_byp; | 204 | ok &= reg.lsebyp() == lse_byp; |
| 202 | #[cfg(any(rcc_l5, rcc_u5, rcc_wle, rcc_wl5, rcc_wba))] | 205 | #[cfg(any(rcc_l5, rcc_u5, rcc_wle, rcc_wl5, rcc_wba, rcc_u0))] |
| 203 | if let Some(lse_sysen) = lse_sysen { | 206 | if let Some(lse_sysen) = lse_sysen { |
| 204 | ok &= reg.lsesysen() == lse_sysen; | 207 | ok &= reg.lsesysen() == lse_sysen; |
| 205 | } | 208 | } |
| @@ -251,7 +254,7 @@ impl LsConfig { | |||
| 251 | 254 | ||
| 252 | while !bdcr().read().lserdy() {} | 255 | while !bdcr().read().lserdy() {} |
| 253 | 256 | ||
| 254 | #[cfg(any(rcc_l5, rcc_u5, rcc_wle, rcc_wl5, rcc_wba))] | 257 | #[cfg(any(rcc_l5, rcc_u5, rcc_wle, rcc_wl5, rcc_wba, rcc_u0))] |
| 255 | if let Some(lse_sysen) = lse_sysen { | 258 | if let Some(lse_sysen) = lse_sysen { |
| 256 | bdcr().modify(|w| { | 259 | bdcr().modify(|w| { |
| 257 | w.set_lsesysen(lse_sysen); | 260 | w.set_lsesysen(lse_sysen); |
diff --git a/embassy-stm32/src/rtc/low_power.rs b/embassy-stm32/src/rtc/low_power.rs index bba359f31..cf7c4bb28 100644 --- a/embassy-stm32/src/rtc/low_power.rs +++ b/embassy-stm32/src/rtc/low_power.rs | |||
| @@ -65,7 +65,9 @@ pub(crate) enum WakeupPrescaler { | |||
| 65 | Div16 = 16, | 65 | Div16 = 16, |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | #[cfg(any(stm32f4, stm32l0, stm32g4, stm32l4, stm32l5, stm32wb, stm32h5, stm32g0, stm32u5))] | 68 | #[cfg(any( |
| 69 | stm32f4, stm32l0, stm32g4, stm32l4, stm32l5, stm32wb, stm32h5, stm32g0, stm32u5, stm32u0 | ||
| 70 | ))] | ||
| 69 | impl From<WakeupPrescaler> for crate::pac::rtc::vals::Wucksel { | 71 | impl From<WakeupPrescaler> for crate::pac::rtc::vals::Wucksel { |
| 70 | fn from(val: WakeupPrescaler) -> Self { | 72 | fn from(val: WakeupPrescaler) -> Self { |
| 71 | use crate::pac::rtc::vals::Wucksel; | 73 | use crate::pac::rtc::vals::Wucksel; |
| @@ -79,7 +81,9 @@ impl From<WakeupPrescaler> for crate::pac::rtc::vals::Wucksel { | |||
| 79 | } | 81 | } |
| 80 | } | 82 | } |
| 81 | 83 | ||
| 82 | #[cfg(any(stm32f4, stm32l0, stm32g4, stm32l4, stm32l5, stm32wb, stm32h5, stm32g0, stm32u5))] | 84 | #[cfg(any( |
| 85 | stm32f4, stm32l0, stm32g4, stm32l4, stm32l5, stm32wb, stm32h5, stm32g0, stm32u5, stm32u0 | ||
| 86 | ))] | ||
| 83 | impl From<crate::pac::rtc::vals::Wucksel> for WakeupPrescaler { | 87 | impl From<crate::pac::rtc::vals::Wucksel> for WakeupPrescaler { |
| 84 | fn from(val: crate::pac::rtc::vals::Wucksel) -> Self { | 88 | fn from(val: crate::pac::rtc::vals::Wucksel) -> Self { |
| 85 | use crate::pac::rtc::vals::Wucksel; | 89 | use crate::pac::rtc::vals::Wucksel; |
| @@ -223,7 +227,7 @@ impl Rtc { | |||
| 223 | <RTC as crate::rtc::SealedInstance>::WakeupInterrupt::unpend(); | 227 | <RTC as crate::rtc::SealedInstance>::WakeupInterrupt::unpend(); |
| 224 | unsafe { <RTC as crate::rtc::SealedInstance>::WakeupInterrupt::enable() }; | 228 | unsafe { <RTC as crate::rtc::SealedInstance>::WakeupInterrupt::enable() }; |
| 225 | 229 | ||
| 226 | #[cfg(not(stm32u5))] | 230 | #[cfg(not(any(stm32u5, stm32u0)))] |
| 227 | { | 231 | { |
| 228 | use crate::pac::EXTI; | 232 | use crate::pac::EXTI; |
| 229 | EXTI.rtsr(0).modify(|w| w.set_line(RTC::EXTI_WAKEUP_LINE, true)); | 233 | EXTI.rtsr(0).modify(|w| w.set_line(RTC::EXTI_WAKEUP_LINE, true)); |
diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs index 3722d11ab..1a668cb37 100644 --- a/embassy-stm32/src/rtc/mod.rs +++ b/embassy-stm32/src/rtc/mod.rs | |||
| @@ -285,7 +285,7 @@ trait SealedInstance { | |||
| 285 | const BACKUP_REGISTER_COUNT: usize; | 285 | const BACKUP_REGISTER_COUNT: usize; |
| 286 | 286 | ||
| 287 | #[cfg(feature = "low-power")] | 287 | #[cfg(feature = "low-power")] |
| 288 | #[cfg(not(stm32u5))] | 288 | #[cfg(not(any(stm32u5, stm32u0)))] |
| 289 | const EXTI_WAKEUP_LINE: usize; | 289 | const EXTI_WAKEUP_LINE: usize; |
| 290 | 290 | ||
| 291 | #[cfg(feature = "low-power")] | 291 | #[cfg(feature = "low-power")] |
diff --git a/embassy-stm32/src/rtc/v3.rs b/embassy-stm32/src/rtc/v3.rs index 12cb10bc7..de2c202bc 100644 --- a/embassy-stm32/src/rtc/v3.rs +++ b/embassy-stm32/src/rtc/v3.rs | |||
| @@ -133,14 +133,20 @@ impl SealedInstance for crate::peripherals::RTC { | |||
| 133 | cfg_if::cfg_if!( | 133 | cfg_if::cfg_if!( |
| 134 | if #[cfg(stm32g4)] { | 134 | if #[cfg(stm32g4)] { |
| 135 | const EXTI_WAKEUP_LINE: usize = 20; | 135 | const EXTI_WAKEUP_LINE: usize = 20; |
| 136 | type WakeupInterrupt = crate::interrupt::typelevel::RTC_WKUP; | ||
| 137 | } else if #[cfg(stm32g0)] { | 136 | } else if #[cfg(stm32g0)] { |
| 138 | const EXTI_WAKEUP_LINE: usize = 19; | 137 | const EXTI_WAKEUP_LINE: usize = 19; |
| 139 | type WakeupInterrupt = crate::interrupt::typelevel::RTC_TAMP; | ||
| 140 | } else if #[cfg(any(stm32l5, stm32h5))] { | 138 | } else if #[cfg(any(stm32l5, stm32h5))] { |
| 141 | const EXTI_WAKEUP_LINE: usize = 17; | 139 | const EXTI_WAKEUP_LINE: usize = 17; |
| 142 | type WakeupInterrupt = crate::interrupt::typelevel::RTC; | 140 | } |
| 143 | } else if #[cfg(stm32u5)] { | 141 | ); |
| 142 | |||
| 143 | #[cfg(feature = "low-power")] | ||
| 144 | cfg_if::cfg_if!( | ||
| 145 | if #[cfg(stm32g4)] { | ||
| 146 | type WakeupInterrupt = crate::interrupt::typelevel::RTC_WKUP; | ||
| 147 | } else if #[cfg(any(stm32g0, stm32u0))] { | ||
| 148 | type WakeupInterrupt = crate::interrupt::typelevel::RTC_TAMP; | ||
| 149 | } else if #[cfg(any(stm32l5, stm32h5, stm32u5))] { | ||
| 144 | type WakeupInterrupt = crate::interrupt::typelevel::RTC; | 150 | type WakeupInterrupt = crate::interrupt::typelevel::RTC; |
| 145 | } | 151 | } |
| 146 | ); | 152 | ); |
