From b69861013aaacad913d99268fa6da634ab7e0c10 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 10 Aug 2023 19:13:48 -0500 Subject: [PATCH] stm32/rtc: implement stop_wakeup_alarm --- embassy-stm32/src/rtc/v2.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/embassy-stm32/src/rtc/v2.rs b/embassy-stm32/src/rtc/v2.rs index 32ccb845..5cd5adef 100644 --- a/embassy-stm32/src/rtc/v2.rs +++ b/embassy-stm32/src/rtc/v2.rs @@ -137,20 +137,24 @@ impl super::Rtc { use crate::interrupt::typelevel::Interrupt; use crate::rcc::get_freqs; - crate::interrupt::typelevel::RTC_WKUP::disable(); - RTC::regs().cr().modify(|w| { w.set_wute(false); }); - let rtc_hz = unsafe { get_freqs() }.rtc.unwrap().0 as u64; + // Wait for the wakeup timer to stop + while !RTC::regs().isr().read().wutf() {} - // Choose the lowest prescaler available - #[cfg(stm32wb)] - let rtc_hz = rtc_hz / 2; + RTC::regs().isr().modify(|w| w.set_wutf(false)); + + crate::interrupt::typelevel::RTC_WKUP::disable(); + + let rtc_hz = unsafe { get_freqs() }.rtc.unwrap().0 as u64; + let prescaler: WakeupPrescaler = RTC::regs().cr().read().wucksel().into(); let rtc_ticks = RTC::regs().wutr().read().wut(); - Duration::from_ticks(rtc_ticks as u64 * TICK_HZ / rtc_hz) + Duration::from_ticks( + rtc_ticks as u64 * TICK_HZ * (>::into(prescaler) as u64) / rtc_hz, + ) } #[allow(dead_code)]