aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-11-18 11:36:05 +0000
committerGitHub <[email protected]>2024-11-18 11:36:05 +0000
commit050d3d1a092eca69b14bd07cd5ca8496a0f09f2d (patch)
treecda09d117aabd6230d0a16c58f7534c8fe92f43c
parentb793d31f25cbf2388f6073cd795ddda996829335 (diff)
parente76473ae95b24d9772711ab4ece464e44e9558f6 (diff)
Merge pull request #3518 from chrenderle/lse-peripherals-clocked
Enable user to choose to pass lse clock to peripherals
-rw-r--r--embassy-stm32/src/rcc/bd.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/embassy-stm32/src/rcc/bd.rs b/embassy-stm32/src/rcc/bd.rs
index 9ccca8a2a..4aec3756f 100644
--- a/embassy-stm32/src/rcc/bd.rs
+++ b/embassy-stm32/src/rcc/bd.rs
@@ -20,6 +20,9 @@ pub enum LseMode {
20pub struct LseConfig { 20pub struct LseConfig {
21 pub frequency: Hertz, 21 pub frequency: Hertz,
22 pub mode: LseMode, 22 pub mode: LseMode,
23 /// If peripherals other than RTC/TAMP or RCC functions need the lse this bit must be set
24 #[cfg(any(rcc_l5, rcc_u5, rcc_wle, rcc_wl5, rcc_wba))]
25 pub peripherals_clocked: bool,
23} 26}
24 27
25#[allow(dead_code)] 28#[allow(dead_code)]
@@ -95,6 +98,8 @@ impl LsConfig {
95 lse: Some(LseConfig { 98 lse: Some(LseConfig {
96 frequency: Hertz(32_768), 99 frequency: Hertz(32_768),
97 mode: LseMode::Oscillator(LseDrive::MediumHigh), 100 mode: LseMode::Oscillator(LseDrive::MediumHigh),
101 #[cfg(any(rcc_l5, rcc_u5, rcc_wle, rcc_wl5, rcc_wba))]
102 peripherals_clocked: false,
98 }), 103 }),
99 lsi: false, 104 lsi: false,
100 } 105 }
@@ -148,6 +153,12 @@ impl LsConfig {
148 }, 153 },
149 None => (false, false, None), 154 None => (false, false, None),
150 }; 155 };
156 #[cfg(any(rcc_l5, rcc_u5, rcc_wle, rcc_wl5, rcc_wba))]
157 let lse_sysen = if let Some(lse) = self.lse {
158 Some(lse.peripherals_clocked)
159 } else {
160 None
161 };
151 _ = lse_drv; // not all chips have it. 162 _ = lse_drv; // not all chips have it.
152 163
153 // Disable backup domain write protection 164 // Disable backup domain write protection
@@ -188,6 +199,10 @@ impl LsConfig {
188 } 199 }
189 ok &= reg.lseon() == lse_en; 200 ok &= reg.lseon() == lse_en;
190 ok &= reg.lsebyp() == lse_byp; 201 ok &= reg.lsebyp() == lse_byp;
202 #[cfg(any(rcc_l5, rcc_u5, rcc_wle, rcc_wl5, rcc_wba))]
203 if let Some(lse_sysen) = lse_sysen {
204 ok &= reg.lsesysen() == lse_sysen;
205 }
191 #[cfg(not(any(rcc_f1, rcc_f1cl, rcc_f100, rcc_f2, rcc_f4, rcc_f410, rcc_l1)))] 206 #[cfg(not(any(rcc_f1, rcc_f1cl, rcc_f100, rcc_f2, rcc_f4, rcc_f410, rcc_l1)))]
192 if let Some(lse_drv) = lse_drv { 207 if let Some(lse_drv) = lse_drv {
193 ok &= reg.lsedrv() == lse_drv.into(); 208 ok &= reg.lsedrv() == lse_drv.into();
@@ -235,6 +250,17 @@ impl LsConfig {
235 }); 250 });
236 251
237 while !bdcr().read().lserdy() {} 252 while !bdcr().read().lserdy() {}
253
254 #[cfg(any(rcc_l5, rcc_u5, rcc_wle, rcc_wl5, rcc_wba))]
255 if let Some(lse_sysen) = lse_sysen {
256 bdcr().modify(|w| {
257 w.set_lsesysen(lse_sysen);
258 });
259
260 if lse_sysen {
261 while !bdcr().read().lsesysrdy() {}
262 }
263 }
238 } 264 }
239 265
240 if self.rtc != RtcClockSource::DISABLE { 266 if self.rtc != RtcClockSource::DISABLE {