diff options
| author | xoviat <[email protected]> | 2023-09-18 00:04:32 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-18 00:04:32 +0000 |
| commit | 0da793e5de229eb7ff2e50da69b95c435f4e45a9 (patch) | |
| tree | 26f1f7c2e538bb9a23452407960e69a01315c235 | |
| parent | daeb497045d47db3afa926b4e0e9e17973a544d5 (diff) | |
| parent | 0dcb34fc7d6134ff8d8c4795209d2feb217920dc (diff) | |
Merge pull request #1921 from xoviat/rtc
stm32: update configure_ls and misc cleanup
| -rw-r--r-- | embassy-stm32-wpan/src/sub/ble.rs | 5 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/sub/mac.rs | 5 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/sub/mm.rs | 5 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/sub/sys.rs | 5 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/bd.rs | 58 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/f2.rs | 12 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/f4.rs | 11 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/l0.rs | 12 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/l4.rs | 6 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/mod.rs | 10 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/wb.rs | 11 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/wl.rs | 6 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/mod.rs | 11 | ||||
| -rw-r--r-- | tests/stm32/src/bin/rtc.rs | 4 | ||||
| -rw-r--r-- | tests/stm32/src/bin/stop.rs | 4 |
15 files changed, 104 insertions, 61 deletions
diff --git a/embassy-stm32-wpan/src/sub/ble.rs b/embassy-stm32-wpan/src/sub/ble.rs index cd32692e1..c5f2334f4 100644 --- a/embassy-stm32-wpan/src/sub/ble.rs +++ b/embassy-stm32-wpan/src/sub/ble.rs | |||
| @@ -1,4 +1,3 @@ | |||
| 1 | use core::marker::PhantomData; | ||
| 2 | use core::ptr; | 1 | use core::ptr; |
| 3 | 2 | ||
| 4 | use embassy_stm32::ipcc::Ipcc; | 3 | use embassy_stm32::ipcc::Ipcc; |
| @@ -13,7 +12,7 @@ use crate::unsafe_linked_list::LinkedListNode; | |||
| 13 | use crate::{channels, evt}; | 12 | use crate::{channels, evt}; |
| 14 | 13 | ||
| 15 | pub struct Ble { | 14 | pub struct Ble { |
| 16 | phantom: PhantomData<Ble>, | 15 | _private: (), |
| 17 | } | 16 | } |
| 18 | 17 | ||
| 19 | impl Ble { | 18 | impl Ble { |
| @@ -29,7 +28,7 @@ impl Ble { | |||
| 29 | }); | 28 | }); |
| 30 | } | 29 | } |
| 31 | 30 | ||
| 32 | Self { phantom: PhantomData } | 31 | Self { _private: () } |
| 33 | } | 32 | } |
| 34 | /// `HW_IPCC_BLE_EvtNot` | 33 | /// `HW_IPCC_BLE_EvtNot` |
| 35 | pub async fn tl_read(&self) -> EvtBox<Self> { | 34 | pub async fn tl_read(&self) -> EvtBox<Self> { |
diff --git a/embassy-stm32-wpan/src/sub/mac.rs b/embassy-stm32-wpan/src/sub/mac.rs index b0cf0248a..baf4da979 100644 --- a/embassy-stm32-wpan/src/sub/mac.rs +++ b/embassy-stm32-wpan/src/sub/mac.rs | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | use core::future::poll_fn; | 1 | use core::future::poll_fn; |
| 2 | use core::marker::PhantomData; | ||
| 3 | use core::ptr; | 2 | use core::ptr; |
| 4 | use core::sync::atomic::{AtomicBool, Ordering}; | 3 | use core::sync::atomic::{AtomicBool, Ordering}; |
| 5 | use core::task::Poll; | 4 | use core::task::Poll; |
| @@ -21,12 +20,12 @@ static MAC_WAKER: AtomicWaker = AtomicWaker::new(); | |||
| 21 | static MAC_EVT_OUT: AtomicBool = AtomicBool::new(false); | 20 | static MAC_EVT_OUT: AtomicBool = AtomicBool::new(false); |
| 22 | 21 | ||
| 23 | pub struct Mac { | 22 | pub struct Mac { |
| 24 | phantom: PhantomData<Mac>, | 23 | _private: (), |
| 25 | } | 24 | } |
| 26 | 25 | ||
| 27 | impl Mac { | 26 | impl Mac { |
| 28 | pub(crate) fn new() -> Self { | 27 | pub(crate) fn new() -> Self { |
| 29 | Self { phantom: PhantomData } | 28 | Self { _private: () } |
| 30 | } | 29 | } |
| 31 | 30 | ||
| 32 | /// `HW_IPCC_MAC_802_15_4_EvtNot` | 31 | /// `HW_IPCC_MAC_802_15_4_EvtNot` |
diff --git a/embassy-stm32-wpan/src/sub/mm.rs b/embassy-stm32-wpan/src/sub/mm.rs index da05ad1dd..4e4d2f854 100644 --- a/embassy-stm32-wpan/src/sub/mm.rs +++ b/embassy-stm32-wpan/src/sub/mm.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | //! Memory manager routines | 1 | //! Memory manager routines |
| 2 | use core::future::poll_fn; | 2 | use core::future::poll_fn; |
| 3 | use core::marker::PhantomData; | ||
| 4 | use core::mem::MaybeUninit; | 3 | use core::mem::MaybeUninit; |
| 5 | use core::task::Poll; | 4 | use core::task::Poll; |
| 6 | 5 | ||
| @@ -21,7 +20,7 @@ static MM_WAKER: AtomicWaker = AtomicWaker::new(); | |||
| 21 | static mut LOCAL_FREE_BUF_QUEUE: Aligned<A4, MaybeUninit<LinkedListNode>> = Aligned(MaybeUninit::uninit()); | 20 | static mut LOCAL_FREE_BUF_QUEUE: Aligned<A4, MaybeUninit<LinkedListNode>> = Aligned(MaybeUninit::uninit()); |
| 22 | 21 | ||
| 23 | pub struct MemoryManager { | 22 | pub struct MemoryManager { |
| 24 | phantom: PhantomData<MemoryManager>, | 23 | _private: (), |
| 25 | } | 24 | } |
| 26 | 25 | ||
| 27 | impl MemoryManager { | 26 | impl MemoryManager { |
| @@ -44,7 +43,7 @@ impl MemoryManager { | |||
| 44 | }); | 43 | }); |
| 45 | } | 44 | } |
| 46 | 45 | ||
| 47 | Self { phantom: PhantomData } | 46 | Self { _private: () } |
| 48 | } | 47 | } |
| 49 | 48 | ||
| 50 | pub async fn run_queue(&self) { | 49 | pub async fn run_queue(&self) { |
diff --git a/embassy-stm32-wpan/src/sub/sys.rs b/embassy-stm32-wpan/src/sub/sys.rs index c17fd531d..bd2ea3f74 100644 --- a/embassy-stm32-wpan/src/sub/sys.rs +++ b/embassy-stm32-wpan/src/sub/sys.rs | |||
| @@ -1,4 +1,3 @@ | |||
| 1 | use core::marker::PhantomData; | ||
| 2 | use core::ptr; | 1 | use core::ptr; |
| 3 | 2 | ||
| 4 | use crate::cmd::CmdPacket; | 3 | use crate::cmd::CmdPacket; |
| @@ -12,7 +11,7 @@ use crate::unsafe_linked_list::LinkedListNode; | |||
| 12 | use crate::{channels, Ipcc, SYSTEM_EVT_QUEUE, SYS_CMD_BUF, TL_DEVICE_INFO_TABLE, TL_SYS_TABLE}; | 11 | use crate::{channels, Ipcc, SYSTEM_EVT_QUEUE, SYS_CMD_BUF, TL_DEVICE_INFO_TABLE, TL_SYS_TABLE}; |
| 13 | 12 | ||
| 14 | pub struct Sys { | 13 | pub struct Sys { |
| 15 | phantom: PhantomData<Sys>, | 14 | _private: (), |
| 16 | } | 15 | } |
| 17 | 16 | ||
| 18 | impl Sys { | 17 | impl Sys { |
| @@ -27,7 +26,7 @@ impl Sys { | |||
| 27 | }); | 26 | }); |
| 28 | } | 27 | } |
| 29 | 28 | ||
| 30 | Self { phantom: PhantomData } | 29 | Self { _private: () } |
| 31 | } | 30 | } |
| 32 | 31 | ||
| 33 | /// Returns CPU2 wireless firmware information (if present). | 32 | /// Returns CPU2 wireless firmware information (if present). |
diff --git a/embassy-stm32/src/rcc/bd.rs b/embassy-stm32/src/rcc/bd.rs index d774b993b..762e84355 100644 --- a/embassy-stm32/src/rcc/bd.rs +++ b/embassy-stm32/src/rcc/bd.rs | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | #[allow(dead_code)] | 1 | #[allow(dead_code)] |
| 2 | #[derive(Default)] | 2 | #[derive(Default, Clone, Copy)] |
| 3 | pub enum LseDrive { | 3 | pub enum LseDrive { |
| 4 | #[cfg(any(rtc_v2f7, rtc_v2l4))] | 4 | #[cfg(any(rtc_v2f7, rtc_v2l4))] |
| 5 | Low = 0, | 5 | Low = 0, |
| @@ -87,40 +87,42 @@ impl BackupDomain { | |||
| 87 | rtc_v3u5 | 87 | rtc_v3u5 |
| 88 | ))] | 88 | ))] |
| 89 | #[allow(dead_code, unused_variables)] | 89 | #[allow(dead_code, unused_variables)] |
| 90 | pub fn configure_ls(clock_source: RtcClockSource, lse_drive: Option<LseDrive>) { | 90 | pub fn configure_ls(clock_source: RtcClockSource, lsi: bool, lse: Option<LseDrive>) { |
| 91 | match clock_source { | 91 | if lsi { |
| 92 | RtcClockSource::LSI => { | 92 | #[cfg(rtc_v3u5)] |
| 93 | #[cfg(rtc_v3u5)] | 93 | let csr = crate::pac::RCC.bdcr(); |
| 94 | let csr = crate::pac::RCC.bdcr(); | ||
| 95 | |||
| 96 | #[cfg(not(rtc_v3u5))] | ||
| 97 | let csr = crate::pac::RCC.csr(); | ||
| 98 | 94 | ||
| 99 | Self::modify(|_| { | 95 | #[cfg(not(rtc_v3u5))] |
| 100 | #[cfg(not(any(rcc_wb, rcc_wba)))] | 96 | let csr = crate::pac::RCC.csr(); |
| 101 | csr.modify(|w| w.set_lsion(true)); | ||
| 102 | |||
| 103 | #[cfg(any(rcc_wb, rcc_wba))] | ||
| 104 | csr.modify(|w| w.set_lsi1on(true)); | ||
| 105 | }); | ||
| 106 | 97 | ||
| 98 | Self::modify(|_| { | ||
| 107 | #[cfg(not(any(rcc_wb, rcc_wba)))] | 99 | #[cfg(not(any(rcc_wb, rcc_wba)))] |
| 108 | while !csr.read().lsirdy() {} | 100 | csr.modify(|w| w.set_lsion(true)); |
| 109 | 101 | ||
| 110 | #[cfg(any(rcc_wb, rcc_wba))] | 102 | #[cfg(any(rcc_wb, rcc_wba))] |
| 111 | while !csr.read().lsi1rdy() {} | 103 | csr.modify(|w| w.set_lsi1on(true)); |
| 112 | } | 104 | }); |
| 113 | RtcClockSource::LSE => { | ||
| 114 | let lse_drive = lse_drive.unwrap_or_default(); | ||
| 115 | 105 | ||
| 116 | Self::modify(|w| { | 106 | #[cfg(not(any(rcc_wb, rcc_wba)))] |
| 117 | #[cfg(any(rtc_v2f7, rtc_v2h7, rtc_v2l0, rtc_v2l4))] | 107 | while !csr.read().lsirdy() {} |
| 118 | w.set_lsedrv(lse_drive.into()); | ||
| 119 | w.set_lseon(true); | ||
| 120 | }); | ||
| 121 | 108 | ||
| 122 | while !Self::read().lserdy() {} | 109 | #[cfg(any(rcc_wb, rcc_wba))] |
| 123 | } | 110 | while !csr.read().lsi1rdy() {} |
| 111 | } | ||
| 112 | |||
| 113 | if let Some(lse_drive) = lse { | ||
| 114 | Self::modify(|w| { | ||
| 115 | #[cfg(any(rtc_v2f7, rtc_v2h7, rtc_v2l0, rtc_v2l4))] | ||
| 116 | w.set_lsedrv(lse_drive.into()); | ||
| 117 | w.set_lseon(true); | ||
| 118 | }); | ||
| 119 | |||
| 120 | while !Self::read().lserdy() {} | ||
| 121 | } | ||
| 122 | |||
| 123 | match clock_source { | ||
| 124 | RtcClockSource::LSI => assert!(lsi), | ||
| 125 | RtcClockSource::LSE => assert!(&lse.is_some()), | ||
| 124 | _ => {} | 126 | _ => {} |
| 125 | }; | 127 | }; |
| 126 | 128 | ||
diff --git a/embassy-stm32/src/rcc/f2.rs b/embassy-stm32/src/rcc/f2.rs index da88e44dc..56ccdcbd8 100644 --- a/embassy-stm32/src/rcc/f2.rs +++ b/embassy-stm32/src/rcc/f2.rs | |||
| @@ -291,6 +291,8 @@ pub struct Config { | |||
| 291 | pub pll: PLLConfig, | 291 | pub pll: PLLConfig, |
| 292 | pub mux: ClockSrc, | 292 | pub mux: ClockSrc, |
| 293 | pub rtc: Option<RtcClockSource>, | 293 | pub rtc: Option<RtcClockSource>, |
| 294 | pub lsi: bool, | ||
| 295 | pub lse: Option<Hertz>, | ||
| 294 | pub voltage: VoltageScale, | 296 | pub voltage: VoltageScale, |
| 295 | pub ahb_pre: AHBPrescaler, | 297 | pub ahb_pre: AHBPrescaler, |
| 296 | pub apb1_pre: APBPrescaler, | 298 | pub apb1_pre: APBPrescaler, |
| @@ -308,6 +310,8 @@ impl Default for Config { | |||
| 308 | voltage: VoltageScale::Scale3, | 310 | voltage: VoltageScale::Scale3, |
| 309 | mux: ClockSrc::HSI, | 311 | mux: ClockSrc::HSI, |
| 310 | rtc: None, | 312 | rtc: None, |
| 313 | lsi: false, | ||
| 314 | lse: None, | ||
| 311 | ahb_pre: AHBPrescaler::DIV1, | 315 | ahb_pre: AHBPrescaler::DIV1, |
| 312 | apb1_pre: APBPrescaler::DIV1, | 316 | apb1_pre: APBPrescaler::DIV1, |
| 313 | apb2_pre: APBPrescaler::DIV1, | 317 | apb2_pre: APBPrescaler::DIV1, |
| @@ -421,9 +425,11 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 421 | RCC.apb1enr().modify(|w| w.set_pwren(true)); | 425 | RCC.apb1enr().modify(|w| w.set_pwren(true)); |
| 422 | PWR.cr().read(); | 426 | PWR.cr().read(); |
| 423 | 427 | ||
| 424 | config | 428 | BackupDomain::configure_ls( |
| 425 | .rtc | 429 | config.rtc.unwrap_or(RtcClockSource::NOCLOCK), |
| 426 | .map(|clock_source| BackupDomain::configure_ls(clock_source, None)); | 430 | config.lsi, |
| 431 | config.lse.map(|_| Default::default()), | ||
| 432 | ); | ||
| 427 | 433 | ||
| 428 | set_freqs(Clocks { | 434 | set_freqs(Clocks { |
| 429 | sys: sys_clk, | 435 | sys: sys_clk, |
diff --git a/embassy-stm32/src/rcc/f4.rs b/embassy-stm32/src/rcc/f4.rs index f7bc0d99a..d8d0312bc 100644 --- a/embassy-stm32/src/rcc/f4.rs +++ b/embassy-stm32/src/rcc/f4.rs | |||
| @@ -35,6 +35,8 @@ pub struct Config { | |||
| 35 | 35 | ||
| 36 | pub pll48: bool, | 36 | pub pll48: bool, |
| 37 | pub rtc: Option<RtcClockSource>, | 37 | pub rtc: Option<RtcClockSource>, |
| 38 | pub lsi: bool, | ||
| 39 | pub lse: Option<Hertz>, | ||
| 38 | } | 40 | } |
| 39 | 41 | ||
| 40 | #[cfg(stm32f410)] | 42 | #[cfg(stm32f410)] |
| @@ -461,12 +463,15 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 461 | }) | 463 | }) |
| 462 | }); | 464 | }); |
| 463 | 465 | ||
| 464 | config | 466 | BackupDomain::configure_ls( |
| 465 | .rtc | 467 | config.rtc.unwrap_or(RtcClockSource::NOCLOCK), |
| 466 | .map(|clock_source| BackupDomain::configure_ls(clock_source, None)); | 468 | config.lsi, |
| 469 | config.lse.map(|_| Default::default()), | ||
| 470 | ); | ||
| 467 | 471 | ||
| 468 | let rtc = match config.rtc { | 472 | let rtc = match config.rtc { |
| 469 | Some(RtcClockSource::LSI) => Some(LSI_FREQ), | 473 | Some(RtcClockSource::LSI) => Some(LSI_FREQ), |
| 474 | Some(RtcClockSource::LSE) => Some(config.lse.unwrap()), | ||
| 470 | _ => None, | 475 | _ => None, |
| 471 | }; | 476 | }; |
| 472 | 477 | ||
diff --git a/embassy-stm32/src/rcc/l0.rs b/embassy-stm32/src/rcc/l0.rs index 2dfd0232c..1c655592e 100644 --- a/embassy-stm32/src/rcc/l0.rs +++ b/embassy-stm32/src/rcc/l0.rs | |||
| @@ -138,6 +138,8 @@ pub struct Config { | |||
| 138 | #[cfg(crs)] | 138 | #[cfg(crs)] |
| 139 | pub enable_hsi48: bool, | 139 | pub enable_hsi48: bool, |
| 140 | pub rtc: Option<RtcClockSource>, | 140 | pub rtc: Option<RtcClockSource>, |
| 141 | pub lse: Option<Hertz>, | ||
| 142 | pub lsi: bool, | ||
| 141 | } | 143 | } |
| 142 | 144 | ||
| 143 | impl Default for Config { | 145 | impl Default for Config { |
| @@ -151,6 +153,8 @@ impl Default for Config { | |||
| 151 | #[cfg(crs)] | 153 | #[cfg(crs)] |
| 152 | enable_hsi48: false, | 154 | enable_hsi48: false, |
| 153 | rtc: None, | 155 | rtc: None, |
| 156 | lse: None, | ||
| 157 | lsi: false, | ||
| 154 | } | 158 | } |
| 155 | } | 159 | } |
| 156 | } | 160 | } |
| @@ -235,9 +239,11 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 235 | } | 239 | } |
| 236 | }; | 240 | }; |
| 237 | 241 | ||
| 238 | config.rtc.map(|rtc| { | 242 | BackupDomain::configure_ls( |
| 239 | BackupDomain::configure_ls(rtc, None); | 243 | config.rtc.unwrap_or(RtcClockSource::NOCLOCK), |
| 240 | }); | 244 | config.lsi, |
| 245 | config.lse.map(|_| Default::default()), | ||
| 246 | ); | ||
| 241 | 247 | ||
| 242 | RCC.cfgr().modify(|w| { | 248 | RCC.cfgr().modify(|w| { |
| 243 | w.set_sw(sw); | 249 | w.set_sw(sw); |
diff --git a/embassy-stm32/src/rcc/l4.rs b/embassy-stm32/src/rcc/l4.rs index 447a57b2c..f7b9354a6 100644 --- a/embassy-stm32/src/rcc/l4.rs +++ b/embassy-stm32/src/rcc/l4.rs | |||
| @@ -241,6 +241,8 @@ pub struct Config { | |||
| 241 | #[cfg(not(any(stm32l471, stm32l475, stm32l476, stm32l486)))] | 241 | #[cfg(not(any(stm32l471, stm32l475, stm32l476, stm32l486)))] |
| 242 | pub hsi48: bool, | 242 | pub hsi48: bool, |
| 243 | pub rtc_mux: RtcClockSource, | 243 | pub rtc_mux: RtcClockSource, |
| 244 | pub lse: Option<Hertz>, | ||
| 245 | pub lsi: bool, | ||
| 244 | } | 246 | } |
| 245 | 247 | ||
| 246 | impl Default for Config { | 248 | impl Default for Config { |
| @@ -255,6 +257,8 @@ impl Default for Config { | |||
| 255 | #[cfg(not(any(stm32l471, stm32l475, stm32l476, stm32l486)))] | 257 | #[cfg(not(any(stm32l471, stm32l475, stm32l476, stm32l486)))] |
| 256 | hsi48: false, | 258 | hsi48: false, |
| 257 | rtc_mux: RtcClockSource::LSI, | 259 | rtc_mux: RtcClockSource::LSI, |
| 260 | lsi: true, | ||
| 261 | lse: None, | ||
| 258 | } | 262 | } |
| 259 | } | 263 | } |
| 260 | } | 264 | } |
| @@ -407,7 +411,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 407 | 411 | ||
| 408 | RCC.apb1enr1().modify(|w| w.set_pwren(true)); | 412 | RCC.apb1enr1().modify(|w| w.set_pwren(true)); |
| 409 | 413 | ||
| 410 | BackupDomain::configure_ls(config.rtc_mux, None); | 414 | BackupDomain::configure_ls(config.rtc_mux, config.lsi, config.lse.map(|_| Default::default())); |
| 411 | 415 | ||
| 412 | let (sys_clk, sw) = match config.mux { | 416 | let (sys_clk, sw) = match config.mux { |
| 413 | ClockSrc::MSI(range) => { | 417 | ClockSrc::MSI(range) => { |
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 892dcf937..ff9b9bac8 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs | |||
| @@ -31,6 +31,16 @@ pub use _version::*; | |||
| 31 | #[cfg(feature = "low-power")] | 31 | #[cfg(feature = "low-power")] |
| 32 | use atomic_polyfill::{AtomicU32, Ordering}; | 32 | use atomic_polyfill::{AtomicU32, Ordering}; |
| 33 | 33 | ||
| 34 | // Model Clock Configuration | ||
| 35 | // | ||
| 36 | // pub struct Clocks { | ||
| 37 | // hse: Option<Hertz>, | ||
| 38 | // hsi: bool, | ||
| 39 | // lse: Option<Hertz>, | ||
| 40 | // lsi: bool, | ||
| 41 | // rtc: RtcSource, | ||
| 42 | // } | ||
| 43 | |||
| 34 | #[derive(Clone, Copy, Debug)] | 44 | #[derive(Clone, Copy, Debug)] |
| 35 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 45 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 36 | pub struct Clocks { | 46 | pub struct Clocks { |
diff --git a/embassy-stm32/src/rcc/wb.rs b/embassy-stm32/src/rcc/wb.rs index 3f4c37429..ee45a342b 100644 --- a/embassy-stm32/src/rcc/wb.rs +++ b/embassy-stm32/src/rcc/wb.rs | |||
| @@ -108,6 +108,7 @@ pub struct Pll { | |||
| 108 | pub struct Config { | 108 | pub struct Config { |
| 109 | pub hse: Option<Hse>, | 109 | pub hse: Option<Hse>, |
| 110 | pub lse: Option<Hertz>, | 110 | pub lse: Option<Hertz>, |
| 111 | pub lsi: bool, | ||
| 111 | pub sys: Sysclk, | 112 | pub sys: Sysclk, |
| 112 | pub mux: Option<PllMux>, | 113 | pub mux: Option<PllMux>, |
| 113 | pub pll48: Option<Pll48Source>, | 114 | pub pll48: Option<Pll48Source>, |
| @@ -136,6 +137,7 @@ pub const WPAN_DEFAULT: Config = Config { | |||
| 136 | }), | 137 | }), |
| 137 | pll48: None, | 138 | pll48: None, |
| 138 | rtc: Some(RtcClockSource::LSE), | 139 | rtc: Some(RtcClockSource::LSE), |
| 140 | lsi: false, | ||
| 139 | 141 | ||
| 140 | pll: Some(Pll { | 142 | pll: Some(Pll { |
| 141 | mul: 12, | 143 | mul: 12, |
| @@ -164,6 +166,7 @@ impl Default for Config { | |||
| 164 | pll: None, | 166 | pll: None, |
| 165 | pllsai: None, | 167 | pllsai: None, |
| 166 | rtc: None, | 168 | rtc: None, |
| 169 | lsi: false, | ||
| 167 | 170 | ||
| 168 | ahb1_pre: AHBPrescaler::DIV1, | 171 | ahb1_pre: AHBPrescaler::DIV1, |
| 169 | ahb2_pre: AHBPrescaler::DIV1, | 172 | ahb2_pre: AHBPrescaler::DIV1, |
| @@ -294,9 +297,11 @@ pub(crate) fn configure_clocks(config: &Config) { | |||
| 294 | 297 | ||
| 295 | rcc.cfgr().modify(|w| w.set_stopwuck(true)); | 298 | rcc.cfgr().modify(|w| w.set_stopwuck(true)); |
| 296 | 299 | ||
| 297 | config | 300 | BackupDomain::configure_ls( |
| 298 | .rtc | 301 | config.rtc.unwrap_or(RtcClockSource::NOCLOCK), |
| 299 | .map(|clock_source| BackupDomain::configure_ls(clock_source, None)); | 302 | config.lsi, |
| 303 | config.lse.map(|_| Default::default()), | ||
| 304 | ); | ||
| 300 | 305 | ||
| 301 | match &config.hse { | 306 | match &config.hse { |
| 302 | Some(hse) => { | 307 | Some(hse) => { |
diff --git a/embassy-stm32/src/rcc/wl.rs b/embassy-stm32/src/rcc/wl.rs index 07856a28c..5db942fca 100644 --- a/embassy-stm32/src/rcc/wl.rs +++ b/embassy-stm32/src/rcc/wl.rs | |||
| @@ -138,6 +138,8 @@ pub struct Config { | |||
| 138 | pub apb1_pre: APBPrescaler, | 138 | pub apb1_pre: APBPrescaler, |
| 139 | pub apb2_pre: APBPrescaler, | 139 | pub apb2_pre: APBPrescaler, |
| 140 | pub rtc_mux: RtcClockSource, | 140 | pub rtc_mux: RtcClockSource, |
| 141 | pub lse: Option<Hertz>, | ||
| 142 | pub lsi: bool, | ||
| 141 | pub adc_clock_source: AdcClockSource, | 143 | pub adc_clock_source: AdcClockSource, |
| 142 | } | 144 | } |
| 143 | 145 | ||
| @@ -151,6 +153,8 @@ impl Default for Config { | |||
| 151 | apb1_pre: APBPrescaler::DIV1, | 153 | apb1_pre: APBPrescaler::DIV1, |
| 152 | apb2_pre: APBPrescaler::DIV1, | 154 | apb2_pre: APBPrescaler::DIV1, |
| 153 | rtc_mux: RtcClockSource::LSI, | 155 | rtc_mux: RtcClockSource::LSI, |
| 156 | lsi: true, | ||
| 157 | lse: None, | ||
| 154 | adc_clock_source: AdcClockSource::default(), | 158 | adc_clock_source: AdcClockSource::default(), |
| 155 | } | 159 | } |
| 156 | } | 160 | } |
| @@ -231,7 +235,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 231 | while FLASH.acr().read().latency() != ws {} | 235 | while FLASH.acr().read().latency() != ws {} |
| 232 | 236 | ||
| 233 | // Enables the LSI if configured | 237 | // Enables the LSI if configured |
| 234 | BackupDomain::configure_ls(config.rtc_mux, None); | 238 | BackupDomain::configure_ls(config.rtc_mux, config.lsi, config.lse.map(|_| Default::default())); |
| 235 | 239 | ||
| 236 | match config.mux { | 240 | match config.mux { |
| 237 | ClockSrc::HSI16 => { | 241 | ClockSrc::HSI16 => { |
diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs index a588c8b18..07b4fe1f0 100644 --- a/embassy-stm32/src/rtc/mod.rs +++ b/embassy-stm32/src/rtc/mod.rs | |||
| @@ -82,8 +82,9 @@ impl core::ops::Sub for RtcInstant { | |||
| 82 | } | 82 | } |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | #[non_exhaustive] | 85 | pub struct RtcTimeProvider { |
| 86 | pub struct RtcTimeProvider; | 86 | _private: (), |
| 87 | } | ||
| 87 | 88 | ||
| 88 | impl RtcTimeProvider { | 89 | impl RtcTimeProvider { |
| 89 | /// Return the current datetime. | 90 | /// Return the current datetime. |
| @@ -186,8 +187,8 @@ impl Rtc { | |||
| 186 | } | 187 | } |
| 187 | 188 | ||
| 188 | /// Acquire a [`RtcTimeProvider`] instance. | 189 | /// Acquire a [`RtcTimeProvider`] instance. |
| 189 | pub fn time_provider(&self) -> RtcTimeProvider { | 190 | pub const fn time_provider(&self) -> RtcTimeProvider { |
| 190 | RtcTimeProvider | 191 | RtcTimeProvider { _private: () } |
| 191 | } | 192 | } |
| 192 | 193 | ||
| 193 | /// Set the datetime to a new value. | 194 | /// Set the datetime to a new value. |
| @@ -222,7 +223,7 @@ impl Rtc { | |||
| 222 | /// | 223 | /// |
| 223 | /// Will return an `RtcError::InvalidDateTime` if the stored value in the system is not a valid [`DayOfWeek`]. | 224 | /// Will return an `RtcError::InvalidDateTime` if the stored value in the system is not a valid [`DayOfWeek`]. |
| 224 | pub fn now(&self) -> Result<DateTime, RtcError> { | 225 | pub fn now(&self) -> Result<DateTime, RtcError> { |
| 225 | RtcTimeProvider.now() | 226 | self.time_provider().now() |
| 226 | } | 227 | } |
| 227 | 228 | ||
| 228 | /// Check if daylight savings time is active. | 229 | /// Check if daylight savings time is active. |
diff --git a/tests/stm32/src/bin/rtc.rs b/tests/stm32/src/bin/rtc.rs index 1a64dd387..22be6fac5 100644 --- a/tests/stm32/src/bin/rtc.rs +++ b/tests/stm32/src/bin/rtc.rs | |||
| @@ -12,13 +12,15 @@ use defmt::assert; | |||
| 12 | use embassy_executor::Spawner; | 12 | use embassy_executor::Spawner; |
| 13 | use embassy_stm32::rcc::RtcClockSource; | 13 | use embassy_stm32::rcc::RtcClockSource; |
| 14 | use embassy_stm32::rtc::{Rtc, RtcConfig}; | 14 | use embassy_stm32::rtc::{Rtc, RtcConfig}; |
| 15 | use embassy_stm32::time::Hertz; | ||
| 15 | use embassy_time::{Duration, Timer}; | 16 | use embassy_time::{Duration, Timer}; |
| 16 | 17 | ||
| 17 | #[embassy_executor::main] | 18 | #[embassy_executor::main] |
| 18 | async fn main(_spawner: Spawner) { | 19 | async fn main(_spawner: Spawner) { |
| 19 | let mut config = config(); | 20 | let mut config = config(); |
| 20 | 21 | ||
| 21 | config.rcc.rtc = Some(RtcClockSource::LSI); | 22 | config.rcc.lse = Some(Hertz(32_768)); |
| 23 | config.rcc.rtc = Some(RtcClockSource::LSE); | ||
| 22 | 24 | ||
| 23 | let p = embassy_stm32::init(config); | 25 | let p = embassy_stm32::init(config); |
| 24 | info!("Hello World!"); | 26 | info!("Hello World!"); |
diff --git a/tests/stm32/src/bin/stop.rs b/tests/stm32/src/bin/stop.rs index a490d7b8c..f60ab271a 100644 --- a/tests/stm32/src/bin/stop.rs +++ b/tests/stm32/src/bin/stop.rs | |||
| @@ -13,6 +13,7 @@ use embassy_executor::Spawner; | |||
| 13 | use embassy_stm32::low_power::{stop_with_rtc, Executor}; | 13 | use embassy_stm32::low_power::{stop_with_rtc, Executor}; |
| 14 | use embassy_stm32::rcc::RtcClockSource; | 14 | use embassy_stm32::rcc::RtcClockSource; |
| 15 | use embassy_stm32::rtc::{Rtc, RtcConfig}; | 15 | use embassy_stm32::rtc::{Rtc, RtcConfig}; |
| 16 | use embassy_stm32::time::Hertz; | ||
| 16 | use embassy_time::{Duration, Timer}; | 17 | use embassy_time::{Duration, Timer}; |
| 17 | use static_cell::make_static; | 18 | use static_cell::make_static; |
| 18 | 19 | ||
| @@ -28,7 +29,8 @@ fn main() -> ! { | |||
| 28 | async fn async_main(_spawner: Spawner) { | 29 | async fn async_main(_spawner: Spawner) { |
| 29 | let mut config = config(); | 30 | let mut config = config(); |
| 30 | 31 | ||
| 31 | config.rcc.rtc = Some(RtcClockSource::LSI); | 32 | config.rcc.lse = Some(Hertz(32_768)); |
| 33 | config.rcc.rtc = Some(RtcClockSource::LSE); | ||
| 32 | 34 | ||
| 33 | let p = embassy_stm32::init(config); | 35 | let p = embassy_stm32::init(config); |
| 34 | info!("Hello World!"); | 36 | info!("Hello World!"); |
