aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/rtc
diff options
context:
space:
mode:
authorxoviat <[email protected]>2023-09-25 16:26:29 -0500
committerxoviat <[email protected]>2023-09-25 16:26:29 -0500
commit04b09a2acb465dbb87dfc4e8b24b4c587f21b472 (patch)
tree726bc7b14d1acf6e9c4d18ac035da782ccd94d9d /embassy-stm32/src/rtc
parent481d2998ef49ef550f6fcf4e8a815b6170aed23b (diff)
stm32/rtc: use rccperi enable
Diffstat (limited to 'embassy-stm32/src/rtc')
-rw-r--r--embassy-stm32/src/rtc/mod.rs10
-rw-r--r--embassy-stm32/src/rtc/v2.rs11
-rw-r--r--embassy-stm32/src/rtc/v3.rs17
3 files changed, 7 insertions, 31 deletions
diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs
index 7eafedec4..b26b5ef35 100644
--- a/embassy-stm32/src/rtc/mod.rs
+++ b/embassy-stm32/src/rtc/mod.rs
@@ -10,6 +10,7 @@ use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
10use embassy_sync::blocking_mutex::Mutex; 10use embassy_sync::blocking_mutex::Mutex;
11 11
12pub use self::datetime::{DateTime, DayOfWeek, Error as DateTimeError}; 12pub use self::datetime::{DateTime, DayOfWeek, Error as DateTimeError};
13use crate::rcc::sealed::RccPeripheral;
13pub use crate::rcc::RtcClockSource; 14pub use crate::rcc::RtcClockSource;
14use crate::time::Hertz; 15use crate::time::Hertz;
15 16
@@ -111,11 +112,12 @@ impl RtcTimeProvider {
111 } 112 }
112} 113}
113 114
114#[non_exhaustive]
115/// RTC Abstraction 115/// RTC Abstraction
116pub struct Rtc { 116pub struct Rtc {
117 #[cfg(feature = "low-power")] 117 #[cfg(feature = "low-power")]
118 stop_time: Mutex<CriticalSectionRawMutex, Cell<Option<RtcInstant>>>, 118 stop_time: Mutex<CriticalSectionRawMutex, Cell<Option<RtcInstant>>>,
119 #[cfg(not(feature = "low-power"))]
120 _private: (),
119} 121}
120 122
121#[non_exhaustive] 123#[non_exhaustive]
@@ -154,9 +156,13 @@ impl Default for RtcCalibrationCyclePeriod {
154 156
155impl Rtc { 157impl Rtc {
156 pub fn new(_rtc: impl Peripheral<P = RTC>, rtc_config: RtcConfig) -> Self { 158 pub fn new(_rtc: impl Peripheral<P = RTC>, rtc_config: RtcConfig) -> Self {
159 RTC::enable();
160
157 let mut this = Self { 161 let mut this = Self {
158 #[cfg(feature = "low-power")] 162 #[cfg(feature = "low-power")]
159 stop_time: Mutex::const_new(CriticalSectionRawMutex::new(), Cell::new(None)), 163 stop_time: Mutex::const_new(CriticalSectionRawMutex::new(), Cell::new(None)),
164 #[cfg(not(feature = "low-power"))]
165 _private: (),
160 }; 166 };
161 167
162 let frequency = Self::frequency(); 168 let frequency = Self::frequency();
@@ -292,8 +298,6 @@ pub(crate) mod sealed {
292 crate::pac::RTC 298 crate::pac::RTC
293 } 299 }
294 300
295 fn enable_peripheral_clk();
296
297 /// Read content of the backup register. 301 /// Read content of the backup register.
298 /// 302 ///
299 /// The registers retain their values during wakes from standby mode or system resets. They also 303 /// The registers retain their values during wakes from standby mode or system resets. They also
diff --git a/embassy-stm32/src/rtc/v2.rs b/embassy-stm32/src/rtc/v2.rs
index ab562d2b6..331792a04 100644
--- a/embassy-stm32/src/rtc/v2.rs
+++ b/embassy-stm32/src/rtc/v2.rs
@@ -286,17 +286,6 @@ impl sealed::Instance for crate::peripherals::RTC {
286 #[cfg(all(feature = "low-power", stm32l0))] 286 #[cfg(all(feature = "low-power", stm32l0))]
287 type WakeupInterrupt = crate::interrupt::typelevel::RTC; 287 type WakeupInterrupt = crate::interrupt::typelevel::RTC;
288 288
289 fn enable_peripheral_clk() {
290 #[cfg(any(rtc_v2l4, rtc_v2wb))]
291 {
292 // enable peripheral clock for communication
293 crate::pac::RCC.apb1enr1().modify(|w| w.set_rtcapben(true));
294
295 // read to allow the pwr clock to enable
296 crate::pac::PWR.cr1().read();
297 }
298 }
299
300 fn read_backup_register(rtc: &Rtc, register: usize) -> Option<u32> { 289 fn read_backup_register(rtc: &Rtc, register: usize) -> Option<u32> {
301 if register < Self::BACKUP_REGISTER_COUNT { 290 if register < Self::BACKUP_REGISTER_COUNT {
302 Some(rtc.bkpr(register).read().bkp()) 291 Some(rtc.bkpr(register).read().bkp())
diff --git a/embassy-stm32/src/rtc/v3.rs b/embassy-stm32/src/rtc/v3.rs
index 9ac9f9f85..a6b2655d8 100644
--- a/embassy-stm32/src/rtc/v3.rs
+++ b/embassy-stm32/src/rtc/v3.rs
@@ -128,23 +128,6 @@ impl super::Rtc {
128impl sealed::Instance for crate::peripherals::RTC { 128impl sealed::Instance for crate::peripherals::RTC {
129 const BACKUP_REGISTER_COUNT: usize = 32; 129 const BACKUP_REGISTER_COUNT: usize = 32;
130 130
131 fn enable_peripheral_clk() {
132 #[cfg(any(rcc_wle, rcc_wl5, rcc_g4))]
133 {
134 // enable peripheral clock for communication
135 crate::pac::RCC.apb1enr1().modify(|w| w.set_rtcapben(true));
136 }
137
138 #[cfg(rcc_g0)]
139 {
140 // enable peripheral clock for communication
141 crate::pac::RCC.apbenr1().modify(|w| w.set_rtcapben(true));
142 }
143
144 // read to allow the pwr clock to enable
145 crate::pac::PWR.cr1().read();
146 }
147
148 fn read_backup_register(_rtc: &Rtc, register: usize) -> Option<u32> { 131 fn read_backup_register(_rtc: &Rtc, register: usize) -> Option<u32> {
149 #[allow(clippy::if_same_then_else)] 132 #[allow(clippy::if_same_then_else)]
150 if register < Self::BACKUP_REGISTER_COUNT { 133 if register < Self::BACKUP_REGISTER_COUNT {