diff options
| author | xoviat <[email protected]> | 2023-08-26 19:23:25 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-08-26 19:23:25 -0500 |
| commit | 2897670f2438525bc128cf016ee8f8a948edfbb7 (patch) | |
| tree | 090ec7f938aa81eb455973b029c114544bec2b89 /embassy-stm32/src/rtc/v2.rs | |
| parent | 3023e70ccf14157c6a9c1315b987951cb6138e0d (diff) | |
stm32: get the basic lp working
Diffstat (limited to 'embassy-stm32/src/rtc/v2.rs')
| -rw-r--r-- | embassy-stm32/src/rtc/v2.rs | 55 |
1 files changed, 43 insertions, 12 deletions
diff --git a/embassy-stm32/src/rtc/v2.rs b/embassy-stm32/src/rtc/v2.rs index 197c3b8f9..525dc45a2 100644 --- a/embassy-stm32/src/rtc/v2.rs +++ b/embassy-stm32/src/rtc/v2.rs | |||
| @@ -30,6 +30,8 @@ impl RtcInstant { | |||
| 30 | 30 | ||
| 31 | let _ = RTC::regs().dr().read(); | 31 | let _ = RTC::regs().dr().read(); |
| 32 | 32 | ||
| 33 | trace!("rtc: instant now: st, ssr: {}, {}", st, ssr); | ||
| 34 | |||
| 33 | Self { ssr, st } | 35 | Self { ssr, st } |
| 34 | } | 36 | } |
| 35 | } | 37 | } |
| @@ -146,6 +148,21 @@ impl super::Rtc { | |||
| 146 | } | 148 | } |
| 147 | } | 149 | } |
| 148 | 150 | ||
| 151 | // pub(crate) fn clear_wakeup_alarm(&self) { | ||
| 152 | // use crate::interrupt::typelevel::Interrupt; | ||
| 153 | // | ||
| 154 | // self.write(false, |regs| { | ||
| 155 | // regs.cr().modify(|w| w.set_wutie(false)); | ||
| 156 | // | ||
| 157 | // regs.isr().modify(|w| w.set_wutf(false)); | ||
| 158 | // crate::pac::PWR.cr1().modify(|w| w.set_cwuf(false)); | ||
| 159 | // crate::pac::EXTI.pr(0).modify(|w| w.set_line(22, false)); | ||
| 160 | // crate::interrupt::typelevel::RTC_WKUP::unpend(); | ||
| 161 | // | ||
| 162 | // regs.cr().modify(|w| w.set_wutie(true)); | ||
| 163 | // }); | ||
| 164 | // } | ||
| 165 | |||
| 149 | #[allow(dead_code)] | 166 | #[allow(dead_code)] |
| 150 | #[cfg(all(feature = "time", any(stm32wb, stm32f4)))] | 167 | #[cfg(all(feature = "time", any(stm32wb, stm32f4)))] |
| 151 | /// start the wakeup alarm and return the actual duration of the alarm | 168 | /// start the wakeup alarm and return the actual duration of the alarm |
| @@ -157,6 +174,7 @@ impl super::Rtc { | |||
| 157 | pub(crate) fn start_wakeup_alarm(&self, requested_duration: embassy_time::Duration) -> RtcInstant { | 174 | pub(crate) fn start_wakeup_alarm(&self, requested_duration: embassy_time::Duration) -> RtcInstant { |
| 158 | use embassy_time::{Duration, TICK_HZ}; | 175 | use embassy_time::{Duration, TICK_HZ}; |
| 159 | 176 | ||
| 177 | use crate::interrupt::typelevel::Interrupt; | ||
| 160 | use crate::rcc::get_freqs; | 178 | use crate::rcc::get_freqs; |
| 161 | 179 | ||
| 162 | let rtc_hz = unsafe { get_freqs() }.rtc.unwrap().0 as u64; | 180 | let rtc_hz = unsafe { get_freqs() }.rtc.unwrap().0 as u64; |
| @@ -176,28 +194,40 @@ impl super::Rtc { | |||
| 176 | rtc_ticks as u64 * TICK_HZ * (<WakeupPrescaler as Into<u32>>::into(prescaler) as u64) / rtc_hz, | 194 | rtc_ticks as u64 * TICK_HZ * (<WakeupPrescaler as Into<u32>>::into(prescaler) as u64) / rtc_hz, |
| 177 | ); | 195 | ); |
| 178 | 196 | ||
| 179 | trace!("rtc: set wakeup timer for {} ms", duration.as_millis()); | ||
| 180 | |||
| 181 | self.write(false, |regs| { | 197 | self.write(false, |regs| { |
| 182 | // regs.cr().modify(|w| w.set_wutie(true)); | ||
| 183 | |||
| 184 | regs.cr().modify(|w| w.set_wute(false)); | 198 | regs.cr().modify(|w| w.set_wute(false)); |
| 185 | regs.isr().modify(|w| w.set_wutf(false)); | 199 | regs.isr().modify(|w| w.set_wutf(false)); |
| 186 | while !regs.isr().read().wutwf() {} | 200 | while !regs.isr().read().wutwf() {} |
| 187 | 201 | ||
| 188 | regs.cr().modify(|w| w.set_wucksel(prescaler.into())); | 202 | regs.cr().modify(|w| w.set_wucksel(prescaler.into())); |
| 189 | regs.cr().modify(|w| w.set_wute(true)); | 203 | regs.cr().modify(|w| w.set_wute(true)); |
| 190 | }); | ||
| 191 | |||
| 192 | self.write(false, |regs| { | ||
| 193 | regs.cr().modify(|w| w.set_wutie(false)); | ||
| 194 | |||
| 195 | regs.isr().modify(|w| w.set_wutf(false)); | ||
| 196 | crate::pac::PWR.cr1().modify(|w| w.set_cwuf(false)); | ||
| 197 | |||
| 198 | regs.cr().modify(|w| w.set_wutie(true)); | 204 | regs.cr().modify(|w| w.set_wutie(true)); |
| 199 | }); | 205 | }); |
| 200 | 206 | ||
| 207 | trace!("rtc: start wakeup alarm for {} ms", duration.as_millis()); | ||
| 208 | |||
| 209 | // self.write(false, |regs| { | ||
| 210 | // regs.cr().modify(|w| w.set_wutie(false)); | ||
| 211 | // | ||
| 212 | // regs.isr().modify(|w| w.set_wutf(false)); | ||
| 213 | // | ||
| 214 | // regs.cr().modify(|w| w.set_wutie(true)); | ||
| 215 | // }); | ||
| 216 | // | ||
| 217 | // trace!("rtc: clear wuf..."); | ||
| 218 | // crate::pac::PWR.cr1().modify(|w| w.set_cwuf(true)); | ||
| 219 | // while crate::pac::PWR.csr1().read().wuf() {} | ||
| 220 | // trace!("rtc: clear wuf...done"); | ||
| 221 | // | ||
| 222 | // crate::pac::PWR | ||
| 223 | // .cr1() | ||
| 224 | // .modify(|w| w.set_pdds(crate::pac::pwr::vals::Pdds::STANDBY_MODE)); | ||
| 225 | // | ||
| 226 | // // crate::pac::PWR.cr1().modify(|w| w.set_lpds(true)); | ||
| 227 | // | ||
| 228 | // // crate::pac::EXTI.pr(0).modify(|w| w.set_line(22, true)); | ||
| 229 | // crate::interrupt::typelevel::RTC_WKUP::unpend(); | ||
| 230 | |||
| 201 | RtcInstant::now() | 231 | RtcInstant::now() |
| 202 | } | 232 | } |
| 203 | 233 | ||
| @@ -211,6 +241,7 @@ impl super::Rtc { | |||
| 211 | trace!("rtc: stop wakeup alarm..."); | 241 | trace!("rtc: stop wakeup alarm..."); |
| 212 | 242 | ||
| 213 | self.write(false, |regs| { | 243 | self.write(false, |regs| { |
| 244 | regs.cr().modify(|w| w.set_wutie(false)); | ||
| 214 | regs.cr().modify(|w| w.set_wute(false)); | 245 | regs.cr().modify(|w| w.set_wute(false)); |
| 215 | regs.isr().modify(|w| w.set_wutf(false)); | 246 | regs.isr().modify(|w| w.set_wutf(false)); |
| 216 | }); | 247 | }); |
