aboutsummaryrefslogtreecommitdiff
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
parent481d2998ef49ef550f6fcf4e8a815b6170aed23b (diff)
stm32/rtc: use rccperi enable
-rw-r--r--embassy-stm32/Cargo.toml4
-rw-r--r--embassy-stm32/src/rcc/bd.rs5
-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
5 files changed, 9 insertions, 38 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index ef0ef229b..660ab0532 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -59,7 +59,7 @@ sdio-host = "0.5.0"
59embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } 59embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true }
60critical-section = "1.1" 60critical-section = "1.1"
61atomic-polyfill = "1.0.1" 61atomic-polyfill = "1.0.1"
62stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-74025d56c0ba061703f360558ce80f51d1165060" } 62stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-1551a1c01a993bb5ffc603311f80097c14e03f85" }
63vcell = "0.1.3" 63vcell = "0.1.3"
64bxcan = "0.7.0" 64bxcan = "0.7.0"
65nb = "1.0.0" 65nb = "1.0.0"
@@ -78,7 +78,7 @@ critical-section = { version = "1.1", features = ["std"] }
78[build-dependencies] 78[build-dependencies]
79proc-macro2 = "1.0.36" 79proc-macro2 = "1.0.36"
80quote = "1.0.15" 80quote = "1.0.15"
81stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-74025d56c0ba061703f360558ce80f51d1165060", default-features = false, features = ["metadata"]} 81stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-1551a1c01a993bb5ffc603311f80097c14e03f85", default-features = false, features = ["metadata"]}
82 82
83[features] 83[features]
84default = ["rt"] 84default = ["rt"]
diff --git a/embassy-stm32/src/rcc/bd.rs b/embassy-stm32/src/rcc/bd.rs
index 5bae3edd9..de27130f2 100644
--- a/embassy-stm32/src/rcc/bd.rs
+++ b/embassy-stm32/src/rcc/bd.rs
@@ -88,11 +88,6 @@ impl BackupDomain {
88 ))] 88 ))]
89 #[allow(dead_code, unused_variables)] 89 #[allow(dead_code, unused_variables)]
90 pub fn configure_ls(clock_source: RtcClockSource, lsi: bool, lse: Option<LseDrive>) { 90 pub fn configure_ls(clock_source: RtcClockSource, lsi: bool, lse: Option<LseDrive>) {
91 if lsi || lse.is_some() {
92 use crate::rtc::sealed::Instance;
93 crate::peripherals::RTC::enable_peripheral_clk();
94 }
95
96 if lsi { 91 if lsi {
97 #[cfg(rtc_v3u5)] 92 #[cfg(rtc_v3u5)]
98 let csr = crate::pac::RCC.bdcr(); 93 let csr = crate::pac::RCC.bdcr();
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 {