From 30023c3bcccaffe4ff16d6600ba5ff80cf1ee488 Mon Sep 17 00:00:00 2001 From: Christian Enderle Date: Tue, 26 Dec 2023 11:58:38 +0100 Subject: [PATCH] Add low-power support for stm32l5 --- embassy-stm32/src/rtc/mod.rs | 20 +++++++++++++------- embassy-stm32/src/rtc/v3.rs | 6 ++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs index 65e8713f0..1ffb567b3 100644 --- a/embassy-stm32/src/rtc/mod.rs +++ b/embassy-stm32/src/rtc/mod.rs @@ -24,7 +24,7 @@ use crate::time::Hertz; ), path = "v2.rs" )] -#[cfg_attr(any(rtc_v3, rtc_v3u5), path = "v3.rs")] +#[cfg_attr(any(rtc_v3, rtc_v3u5, rtc_v3l5), path = "v3.rs")] mod _version; #[allow(unused_imports)] pub use _version::*; @@ -43,7 +43,7 @@ pub(crate) enum WakeupPrescaler { Div16 = 16, } -#[cfg(any(stm32wb, stm32f4, stm32l0, stm32g4))] +#[cfg(any(stm32wb, stm32f4, stm32l0, stm32g4, stm32l5))] impl From for crate::pac::rtc::vals::Wucksel { fn from(val: WakeupPrescaler) -> Self { use crate::pac::rtc::vals::Wucksel; @@ -57,7 +57,7 @@ impl From for crate::pac::rtc::vals::Wucksel { } } -#[cfg(any(stm32wb, stm32f4, stm32l0, stm32g4))] +#[cfg(any(stm32wb, stm32f4, stm32l0, stm32g4, stm32l5))] impl From for WakeupPrescaler { fn from(val: crate::pac::rtc::vals::Wucksel) -> Self { use crate::pac::rtc::vals::Wucksel; @@ -348,7 +348,7 @@ impl Rtc { ) { use embassy_time::{Duration, TICK_HZ}; - #[cfg(any(rtc_v3, rtc_v3u5))] + #[cfg(any(rtc_v3, rtc_v3u5, rtc_v3l5))] use crate::pac::rtc::vals::Calrf; // Panic if the rcc mod knows we're not using low-power rtc @@ -375,7 +375,7 @@ impl Rtc { while !regs.isr().read().wutwf() {} } - #[cfg(any(rtc_v3, rtc_v3u5))] + #[cfg(any(rtc_v3, rtc_v3u5, rtc_v3l5))] { regs.scr().write(|w| w.set_cwutf(Calrf::CLEAR)); while !regs.icsr().read().wutwf() {} @@ -404,7 +404,7 @@ impl Rtc { /// was called, otherwise none pub(crate) fn stop_wakeup_alarm(&self, cs: critical_section::CriticalSection) -> Option { use crate::interrupt::typelevel::Interrupt; - #[cfg(any(rtc_v3, rtc_v3u5))] + #[cfg(any(rtc_v3, rtc_v3u5, rtc_v3l5))] use crate::pac::rtc::vals::Calrf; let instant = self.instant().unwrap(); @@ -420,13 +420,19 @@ impl Rtc { ))] regs.isr().modify(|w| w.set_wutf(false)); - #[cfg(any(rtc_v3, rtc_v3u5))] + #[cfg(any(rtc_v3, rtc_v3u5, rtc_v3l5))] regs.scr().write(|w| w.set_cwutf(Calrf::CLEAR)); + #[cfg(not(stm32l5))] crate::pac::EXTI .pr(0) .modify(|w| w.set_line(RTC::EXTI_WAKEUP_LINE, true)); + #[cfg(stm32l5)] + crate::pac::EXTI + .fpr(0) + .modify(|w| w.set_line(RTC::EXTI_WAKEUP_LINE, true)); + ::WakeupInterrupt::unpend(); }); } diff --git a/embassy-stm32/src/rtc/v3.rs b/embassy-stm32/src/rtc/v3.rs index 902776b0a..114141b64 100644 --- a/embassy-stm32/src/rtc/v3.rs +++ b/embassy-stm32/src/rtc/v3.rs @@ -135,6 +135,12 @@ impl sealed::Instance for crate::peripherals::RTC { #[cfg(all(feature = "low-power", stm32g4))] type WakeupInterrupt = crate::interrupt::typelevel::RTC_WKUP; + #[cfg(all(feature = "low-power", stm32l5))] + const EXTI_WAKEUP_LINE: usize = 17; + + #[cfg(all(feature = "low-power", stm32l5))] + type WakeupInterrupt = crate::interrupt::typelevel::RTC; + fn read_backup_register(_rtc: &Rtc, register: usize) -> Option { #[allow(clippy::if_same_then_else)] if register < Self::BACKUP_REGISTER_COUNT {