aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/rcc/wl.rs20
-rw-r--r--examples/stm32wl/src/bin/rtc.rs6
2 files changed, 11 insertions, 15 deletions
diff --git a/embassy-stm32/src/rcc/wl.rs b/embassy-stm32/src/rcc/wl.rs
index 8a9b24c91..5b1909659 100644
--- a/embassy-stm32/src/rcc/wl.rs
+++ b/embassy-stm32/src/rcc/wl.rs
@@ -1,7 +1,7 @@
1pub use super::bus::{AHBPrescaler, APBPrescaler, VoltageScale}; 1pub use super::bus::{AHBPrescaler, APBPrescaler, VoltageScale};
2use crate::pac::pwr::vals::Dbp; 2use crate::pac::pwr::vals::Dbp;
3use crate::pac::{FLASH, PWR, RCC}; 3use crate::pac::{FLASH, PWR, RCC};
4use crate::rcc::bd::{BackupDomain, RtcClockSource as RCS}; 4use crate::rcc::bd::{BackupDomain, RtcClockSource};
5use crate::rcc::{set_freqs, Clocks}; 5use crate::rcc::{set_freqs, Clocks};
6use crate::time::Hertz; 6use crate::time::Hertz;
7 7
@@ -130,16 +130,11 @@ impl Default for Config {
130 apb2_pre: APBPrescaler::NotDivided, 130 apb2_pre: APBPrescaler::NotDivided,
131 enable_lsi: false, 131 enable_lsi: false,
132 enable_rtc_apb: false, 132 enable_rtc_apb: false,
133 rtc_mux: RtcClockSource::LSI32, 133 rtc_mux: RtcClockSource::LSI,
134 } 134 }
135 } 135 }
136} 136}
137 137
138pub enum RtcClockSource {
139 LSE32,
140 LSI32,
141}
142
143#[repr(u8)] 138#[repr(u8)]
144pub enum Lsedrv { 139pub enum Lsedrv {
145 Low = 0, 140 Low = 0,
@@ -215,7 +210,7 @@ pub(crate) unsafe fn init(config: Config) {
215 while FLASH.acr().read().latency() != ws {} 210 while FLASH.acr().read().latency() != ws {}
216 211
217 match config.rtc_mux { 212 match config.rtc_mux {
218 RtcClockSource::LSE32 => { 213 RtcClockSource::LSE => {
219 // 1. Unlock the backup domain 214 // 1. Unlock the backup domain
220 PWR.cr1().modify(|w| w.set_dbp(Dbp::ENABLED)); 215 PWR.cr1().modify(|w| w.set_dbp(Dbp::ENABLED));
221 216
@@ -231,17 +226,18 @@ pub(crate) unsafe fn init(config: Config) {
231 // Wait until LSE is running 226 // Wait until LSE is running
232 while !RCC.bdcr().read().lserdy() {} 227 while !RCC.bdcr().read().lserdy() {}
233 228
234 BackupDomain::set_rtc_clock_source(RCS::LSE); 229 BackupDomain::set_rtc_clock_source(RtcClockSource::LSE);
235 } 230 }
236 RtcClockSource::LSI32 => { 231 RtcClockSource::LSI => {
237 // Turn on the internal 32 kHz LSI oscillator 232 // Turn on the internal 32 kHz LSI oscillator
238 RCC.csr().modify(|w| w.set_lsion(true)); 233 RCC.csr().modify(|w| w.set_lsion(true));
239 234
240 // Wait until LSI is running 235 // Wait until LSI is running
241 while !RCC.csr().read().lsirdy() {} 236 while !RCC.csr().read().lsirdy() {}
242 237
243 BackupDomain::set_rtc_clock_source(RCS::LSI); 238 BackupDomain::set_rtc_clock_source(RtcClockSource::LSI);
244 } 239 }
240 _ => unreachable!(),
245 } 241 }
246 242
247 match config.mux { 243 match config.mux {
@@ -266,7 +262,7 @@ pub(crate) unsafe fn init(config: Config) {
266 w.set_msirange(range.into()); 262 w.set_msirange(range.into());
267 w.set_msion(true); 263 w.set_msion(true);
268 264
269 if let RtcClockSource::LSE32 = config.rtc_mux { 265 if let RtcClockSource::LSE = config.rtc_mux {
270 // If LSE is enabled, enable calibration of MSI 266 // If LSE is enabled, enable calibration of MSI
271 w.set_msipllen(true); 267 w.set_msipllen(true);
272 } else { 268 } else {
diff --git a/examples/stm32wl/src/bin/rtc.rs b/examples/stm32wl/src/bin/rtc.rs
index fb1bc6e3d..2be6c7b93 100644
--- a/examples/stm32wl/src/bin/rtc.rs
+++ b/examples/stm32wl/src/bin/rtc.rs
@@ -5,8 +5,8 @@
5use chrono::{NaiveDate, NaiveDateTime}; 5use chrono::{NaiveDate, NaiveDateTime};
6use defmt::*; 6use defmt::*;
7use embassy_executor::Spawner; 7use embassy_executor::Spawner;
8use embassy_stm32::rcc::{self, ClockSrc}; 8use embassy_stm32::rcc::ClockSrc;
9use embassy_stm32::rtc::{Rtc, RtcConfig}; 9use embassy_stm32::rtc::{Rtc, RtcClockSource, RtcConfig};
10use embassy_stm32::Config; 10use embassy_stm32::Config;
11use embassy_time::{Duration, Timer}; 11use embassy_time::{Duration, Timer};
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
@@ -16,7 +16,7 @@ async fn main(_spawner: Spawner) {
16 let p = { 16 let p = {
17 let mut config = Config::default(); 17 let mut config = Config::default();
18 config.rcc.mux = ClockSrc::HSE32; 18 config.rcc.mux = ClockSrc::HSE32;
19 config.rcc.rtc_mux = rcc::RtcClockSource::LSE32; 19 config.rcc.rtc_mux = RtcClockSource::LSE;
20 config.rcc.enable_rtc_apb = true; 20 config.rcc.enable_rtc_apb = true;
21 embassy_stm32::init(config) 21 embassy_stm32::init(config)
22 }; 22 };