diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-09-26 01:14:12 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2025-09-26 01:17:30 +0200 |
| commit | 085ab9f617357cf94b8b4e44424850e48add2fae (patch) | |
| tree | bc30c7c23c77c4f7a30b001f16f58224bf956f57 /embassy-stm32/src/rtc | |
| parent | fc8c3e1e4babaa6344bdbab49a9542a29c88cc25 (diff) | |
stm32: update metapac, add L4+ to CI.
Diffstat (limited to 'embassy-stm32/src/rtc')
| -rw-r--r-- | embassy-stm32/src/rtc/low_power.rs | 36 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/mod.rs | 21 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/v2.rs | 8 |
3 files changed, 23 insertions, 42 deletions
diff --git a/embassy-stm32/src/rtc/low_power.rs b/embassy-stm32/src/rtc/low_power.rs index 78ccd3e6c..a81ac6746 100644 --- a/embassy-stm32/src/rtc/low_power.rs +++ b/embassy-stm32/src/rtc/low_power.rs | |||
| @@ -1,4 +1,8 @@ | |||
| 1 | #[cfg(feature = "time")] | ||
| 2 | use embassy_time::{Duration, TICK_HZ}; | ||
| 3 | |||
| 1 | use super::{bcd2_to_byte, DateTimeError, Rtc, RtcError}; | 4 | use super::{bcd2_to_byte, DateTimeError, Rtc, RtcError}; |
| 5 | use crate::interrupt::typelevel::Interrupt; | ||
| 2 | use crate::peripherals::RTC; | 6 | use crate::peripherals::RTC; |
| 3 | use crate::rtc::SealedInstance; | 7 | use crate::rtc::SealedInstance; |
| 4 | 8 | ||
| @@ -11,7 +15,7 @@ pub(super) struct RtcInstant { | |||
| 11 | } | 15 | } |
| 12 | 16 | ||
| 13 | impl RtcInstant { | 17 | impl RtcInstant { |
| 14 | #[cfg(not(rtc_v2f2))] | 18 | #[cfg(not(rtc_v2_f2))] |
| 15 | const fn from(second: u8, subsecond: u16) -> Result<Self, DateTimeError> { | 19 | const fn from(second: u8, subsecond: u16) -> Result<Self, DateTimeError> { |
| 16 | if second > 59 { | 20 | if second > 59 { |
| 17 | Err(DateTimeError::InvalidSecond) | 21 | Err(DateTimeError::InvalidSecond) |
| @@ -38,8 +42,6 @@ impl core::ops::Sub for RtcInstant { | |||
| 38 | type Output = embassy_time::Duration; | 42 | type Output = embassy_time::Duration; |
| 39 | 43 | ||
| 40 | fn sub(self, rhs: Self) -> Self::Output { | 44 | fn sub(self, rhs: Self) -> Self::Output { |
| 41 | use embassy_time::{Duration, TICK_HZ}; | ||
| 42 | |||
| 43 | let second = if self.second < rhs.second { | 45 | let second = if self.second < rhs.second { |
| 44 | self.second + 60 | 46 | self.second + 60 |
| 45 | } else { | 47 | } else { |
| @@ -129,11 +131,6 @@ impl Rtc { | |||
| 129 | requested_duration: embassy_time::Duration, | 131 | requested_duration: embassy_time::Duration, |
| 130 | cs: critical_section::CriticalSection, | 132 | cs: critical_section::CriticalSection, |
| 131 | ) { | 133 | ) { |
| 132 | use embassy_time::{Duration, TICK_HZ}; | ||
| 133 | |||
| 134 | #[cfg(any(rtc_v3, rtc_v3u5, rtc_v3l5))] | ||
| 135 | use crate::pac::rtc::vals::Calrf; | ||
| 136 | |||
| 137 | // Panic if the rcc mod knows we're not using low-power rtc | 134 | // Panic if the rcc mod knows we're not using low-power rtc |
| 138 | #[cfg(any(rcc_wb, rcc_f4, rcc_f410))] | 135 | #[cfg(any(rcc_wb, rcc_f4, rcc_f410))] |
| 139 | unsafe { crate::rcc::get_freqs() }.rtc.to_hertz().unwrap(); | 136 | unsafe { crate::rcc::get_freqs() }.rtc.to_hertz().unwrap(); |
| @@ -150,17 +147,15 @@ impl Rtc { | |||
| 150 | self.write(false, |regs| { | 147 | self.write(false, |regs| { |
| 151 | regs.cr().modify(|w| w.set_wute(false)); | 148 | regs.cr().modify(|w| w.set_wute(false)); |
| 152 | 149 | ||
| 153 | #[cfg(any( | 150 | #[cfg(rtc_v2)] |
| 154 | rtc_v2f0, rtc_v2f2, rtc_v2f3, rtc_v2f4, rtc_v2f7, rtc_v2h7, rtc_v2l0, rtc_v2l1, rtc_v2l4, rtc_v2wb | ||
| 155 | ))] | ||
| 156 | { | 151 | { |
| 157 | regs.isr().modify(|w| w.set_wutf(false)); | 152 | regs.isr().modify(|w| w.set_wutf(false)); |
| 158 | while !regs.isr().read().wutwf() {} | 153 | while !regs.isr().read().wutwf() {} |
| 159 | } | 154 | } |
| 160 | 155 | ||
| 161 | #[cfg(any(rtc_v3, rtc_v3u5, rtc_v3l5))] | 156 | #[cfg(rtc_v3)] |
| 162 | { | 157 | { |
| 163 | regs.scr().write(|w| w.set_cwutf(Calrf::CLEAR)); | 158 | regs.scr().write(|w| w.set_cwutf(crate::pac::rtc::vals::Calrf::CLEAR)); |
| 164 | while !regs.icsr().read().wutwf() {} | 159 | while !regs.icsr().read().wutwf() {} |
| 165 | } | 160 | } |
| 166 | 161 | ||
| @@ -185,10 +180,6 @@ impl Rtc { | |||
| 185 | /// stop the wakeup alarm and return the time elapsed since `start_wakeup_alarm` | 180 | /// stop the wakeup alarm and return the time elapsed since `start_wakeup_alarm` |
| 186 | /// was called, otherwise none | 181 | /// was called, otherwise none |
| 187 | pub(crate) fn stop_wakeup_alarm(&self, cs: critical_section::CriticalSection) -> Option<embassy_time::Duration> { | 182 | pub(crate) fn stop_wakeup_alarm(&self, cs: critical_section::CriticalSection) -> Option<embassy_time::Duration> { |
| 188 | use crate::interrupt::typelevel::Interrupt; | ||
| 189 | #[cfg(any(rtc_v3, rtc_v3u5, rtc_v3l5))] | ||
| 190 | use crate::pac::rtc::vals::Calrf; | ||
| 191 | |||
| 192 | let instant = self.instant().unwrap(); | 183 | let instant = self.instant().unwrap(); |
| 193 | if RTC::regs().cr().read().wute() { | 184 | if RTC::regs().cr().read().wute() { |
| 194 | trace!("rtc: stop wakeup alarm at {}", instant); | 185 | trace!("rtc: stop wakeup alarm at {}", instant); |
| @@ -197,13 +188,10 @@ impl Rtc { | |||
| 197 | regs.cr().modify(|w| w.set_wutie(false)); | 188 | regs.cr().modify(|w| w.set_wutie(false)); |
| 198 | regs.cr().modify(|w| w.set_wute(false)); | 189 | regs.cr().modify(|w| w.set_wute(false)); |
| 199 | 190 | ||
| 200 | #[cfg(any( | 191 | #[cfg(rtc_v2)] |
| 201 | rtc_v2f0, rtc_v2f2, rtc_v2f3, rtc_v2f4, rtc_v2f7, rtc_v2h7, rtc_v2l0, rtc_v2l1, rtc_v2l4, rtc_v2wb | ||
| 202 | ))] | ||
| 203 | regs.isr().modify(|w| w.set_wutf(false)); | 192 | regs.isr().modify(|w| w.set_wutf(false)); |
| 204 | 193 | #[cfg(rtc_v3)] | |
| 205 | #[cfg(any(rtc_v3, rtc_v3u5, rtc_v3l5))] | 194 | regs.scr().write(|w| w.set_cwutf(crate::pac::rtc::vals::Calrf::CLEAR)); |
| 206 | regs.scr().write(|w| w.set_cwutf(Calrf::CLEAR)); | ||
| 207 | 195 | ||
| 208 | // Check RM for EXTI and/or NVIC section, "Event event input mapping" or "EXTI interrupt/event mapping" or something similar, | 196 | // Check RM for EXTI and/or NVIC section, "Event event input mapping" or "EXTI interrupt/event mapping" or something similar, |
| 209 | // there is a table for every "Event input" / "EXTI Line". | 197 | // there is a table for every "Event input" / "EXTI Line". |
| @@ -222,8 +210,6 @@ impl Rtc { | |||
| 222 | } | 210 | } |
| 223 | 211 | ||
| 224 | pub(crate) fn enable_wakeup_line(&self) { | 212 | pub(crate) fn enable_wakeup_line(&self) { |
| 225 | use crate::interrupt::typelevel::Interrupt; | ||
| 226 | |||
| 227 | <RTC as crate::rtc::SealedInstance>::WakeupInterrupt::unpend(); | 213 | <RTC as crate::rtc::SealedInstance>::WakeupInterrupt::unpend(); |
| 228 | unsafe { <RTC as crate::rtc::SealedInstance>::WakeupInterrupt::enable() }; | 214 | unsafe { <RTC as crate::rtc::SealedInstance>::WakeupInterrupt::enable() }; |
| 229 | 215 | ||
diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs index 449f3008a..92dec0960 100644 --- a/embassy-stm32/src/rtc/mod.rs +++ b/embassy-stm32/src/rtc/mod.rs | |||
| @@ -18,14 +18,9 @@ use crate::pac::rtc::regs::{Dr, Tr}; | |||
| 18 | use crate::time::Hertz; | 18 | use crate::time::Hertz; |
| 19 | 19 | ||
| 20 | /// refer to AN4759 to compare features of RTC2 and RTC3 | 20 | /// refer to AN4759 to compare features of RTC2 and RTC3 |
| 21 | #[cfg_attr(any(rtc_v1), path = "v1.rs")] | 21 | #[cfg_attr(rtc_v1, path = "v1.rs")] |
| 22 | #[cfg_attr( | 22 | #[cfg_attr(rtc_v2, path = "v2.rs")] |
| 23 | any( | 23 | #[cfg_attr(rtc_v3, path = "v3.rs")] |
| 24 | rtc_v2f0, rtc_v2f2, rtc_v2f3, rtc_v2f4, rtc_v2f7, rtc_v2h7, rtc_v2l0, rtc_v2l1, rtc_v2l4, rtc_v2wb | ||
| 25 | ), | ||
| 26 | path = "v2.rs" | ||
| 27 | )] | ||
| 28 | #[cfg_attr(any(rtc_v3, rtc_v3u5, rtc_v3l5, rtc_v3h7rs, rtc_v3c0), path = "v3.rs")] | ||
| 29 | mod _version; | 24 | mod _version; |
| 30 | #[allow(unused_imports)] | 25 | #[allow(unused_imports)] |
| 31 | pub use _version::*; | 26 | pub use _version::*; |
| @@ -72,12 +67,12 @@ impl RtcTimeProvider { | |||
| 72 | 67 | ||
| 73 | // Calculate second fraction and multiply to microseconds | 68 | // Calculate second fraction and multiply to microseconds |
| 74 | // Formula from RM0410 | 69 | // Formula from RM0410 |
| 75 | #[cfg(not(rtc_v2f2))] | 70 | #[cfg(not(rtc_v2_f2))] |
| 76 | let us = { | 71 | let us = { |
| 77 | let prediv = RTC::regs().prer().read().prediv_s() as f32; | 72 | let prediv = RTC::regs().prer().read().prediv_s() as f32; |
| 78 | (((prediv - _ss as f32) / (prediv + 1.0)) * 1e6).min(999_999.0) as u32 | 73 | (((prediv - _ss as f32) / (prediv + 1.0)) * 1e6).min(999_999.0) as u32 |
| 79 | }; | 74 | }; |
| 80 | #[cfg(rtc_v2f2)] | 75 | #[cfg(rtc_v2_f2)] |
| 81 | let us = 0; | 76 | let us = 0; |
| 82 | 77 | ||
| 83 | DateTime::from(year, month, day, weekday, hour, minute, second, us).map_err(RtcError::InvalidDateTime) | 78 | DateTime::from(year, month, day, weekday, hour, minute, second, us).map_err(RtcError::InvalidDateTime) |
| @@ -87,9 +82,9 @@ impl RtcTimeProvider { | |||
| 87 | fn read<R>(&self, mut f: impl FnMut(Dr, Tr, u16) -> Result<R, RtcError>) -> Result<R, RtcError> { | 82 | fn read<R>(&self, mut f: impl FnMut(Dr, Tr, u16) -> Result<R, RtcError>) -> Result<R, RtcError> { |
| 88 | let r = RTC::regs(); | 83 | let r = RTC::regs(); |
| 89 | 84 | ||
| 90 | #[cfg(not(rtc_v2f2))] | 85 | #[cfg(not(rtc_v2_f2))] |
| 91 | let read_ss = || r.ssr().read().ss(); | 86 | let read_ss = || r.ssr().read().ss(); |
| 92 | #[cfg(rtc_v2f2)] | 87 | #[cfg(rtc_v2_f2)] |
| 93 | let read_ss = || 0; | 88 | let read_ss = || 0; |
| 94 | 89 | ||
| 95 | let mut ss = read_ss(); | 90 | let mut ss = read_ss(); |
| @@ -168,7 +163,7 @@ impl Rtc { | |||
| 168 | this.configure(async_psc, sync_psc); | 163 | this.configure(async_psc, sync_psc); |
| 169 | 164 | ||
| 170 | // Wait for the clock to update after initialization | 165 | // Wait for the clock to update after initialization |
| 171 | #[cfg(not(rtc_v2f2))] | 166 | #[cfg(not(rtc_v2_f2))] |
| 172 | { | 167 | { |
| 173 | let now = this.time_provider().read(|_, _, ss| Ok(ss)).unwrap(); | 168 | let now = this.time_provider().read(|_, _, ss| Ok(ss)).unwrap(); |
| 174 | while now == this.time_provider().read(|_, _, ss| Ok(ss)).unwrap() {} | 169 | while now == this.time_provider().read(|_, _, ss| Ok(ss)).unwrap() {} |
diff --git a/embassy-stm32/src/rtc/v2.rs b/embassy-stm32/src/rtc/v2.rs index 28380a3c0..23f6ccb0c 100644 --- a/embassy-stm32/src/rtc/v2.rs +++ b/embassy-stm32/src/rtc/v2.rs | |||
| @@ -11,11 +11,11 @@ impl super::Rtc { | |||
| 11 | pub(super) fn configure(&mut self, async_psc: u8, sync_psc: u16) { | 11 | pub(super) fn configure(&mut self, async_psc: u8, sync_psc: u16) { |
| 12 | self.write(true, |rtc| { | 12 | self.write(true, |rtc| { |
| 13 | rtc.cr().modify(|w| { | 13 | rtc.cr().modify(|w| { |
| 14 | #[cfg(not(rtc_v2f2))] | 14 | #[cfg(not(rtc_v2_f2))] |
| 15 | w.set_bypshad(true); | 15 | w.set_bypshad(true); |
| 16 | #[cfg(rtc_v2f2)] | 16 | #[cfg(rtc_v2_f2)] |
| 17 | w.set_fmt(false); | 17 | w.set_fmt(false); |
| 18 | #[cfg(not(rtc_v2f2))] | 18 | #[cfg(not(rtc_v2_f2))] |
| 19 | w.set_fmt(stm32_metapac::rtc::vals::Fmt::TWENTY_FOUR_HOUR); | 19 | w.set_fmt(stm32_metapac::rtc::vals::Fmt::TWENTY_FOUR_HOUR); |
| 20 | w.set_osel(Osel::DISABLED); | 20 | w.set_osel(Osel::DISABLED); |
| 21 | w.set_pol(Pol::HIGH); | 21 | w.set_pol(Pol::HIGH); |
| @@ -36,7 +36,7 @@ impl super::Rtc { | |||
| 36 | /// | 36 | /// |
| 37 | /// To perform a calibration when `async_prescaler` is less then 3, `sync_prescaler` | 37 | /// To perform a calibration when `async_prescaler` is less then 3, `sync_prescaler` |
| 38 | /// has to be reduced accordingly (see RM0351 Rev 9, sec 38.3.12). | 38 | /// has to be reduced accordingly (see RM0351 Rev 9, sec 38.3.12). |
| 39 | #[cfg(not(rtc_v2f2))] | 39 | #[cfg(not(rtc_v2_f2))] |
| 40 | pub fn calibrate(&mut self, mut clock_drift: f32, period: super::RtcCalibrationCyclePeriod) { | 40 | pub fn calibrate(&mut self, mut clock_drift: f32, period: super::RtcCalibrationCyclePeriod) { |
| 41 | const RTC_CALR_MIN_PPM: f32 = -487.1; | 41 | const RTC_CALR_MIN_PPM: f32 = -487.1; |
| 42 | const RTC_CALR_MAX_PPM: f32 = 488.5; | 42 | const RTC_CALR_MAX_PPM: f32 = 488.5; |
