aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/rtc/mod.rs
diff options
context:
space:
mode:
authorMatteo Meluzzi <[email protected]>2025-10-02 10:53:31 +0200
committerMatteo Meluzzi <[email protected]>2025-10-02 10:53:31 +0200
commit828a8df18d04877df1f55f04354980b28ff2f2f8 (patch)
treec4fa405f5eba7a14b6d435d6cc746c9e0dc52632 /embassy-stm32/src/rtc/mod.rs
parent176649e71ad442ca9856af6c11989b0b2f228c4b (diff)
parent194a721d0eab929a2af0a2a4e45ca8e70e0d3f0a (diff)
Merge branch 'main' into 17-add-support-for-boot-protocol
Diffstat (limited to 'embassy-stm32/src/rtc/mod.rs')
-rw-r--r--embassy-stm32/src/rtc/mod.rs21
1 files changed, 8 insertions, 13 deletions
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};
18use crate::time::Hertz; 18use 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")]
29mod _version; 24mod _version;
30#[allow(unused_imports)] 25#[allow(unused_imports)]
31pub use _version::*; 26pub 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() {}