From e1951f3ddffdeffab03bd0d20ebc1f7210738002 Mon Sep 17 00:00:00 2001 From: Mateusz Butkiewicz Date: Wed, 27 Sep 2023 15:13:43 +0200 Subject: [PATCH] feat(stm32f7): restore rtc configuration for stm32f7 series --- embassy-stm32/src/rcc/f7.rs | 18 ++++++++++++++++++ embassy-stm32/src/rcc/mod.rs | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/embassy-stm32/src/rcc/f7.rs b/embassy-stm32/src/rcc/f7.rs index 234511b00..f32559e26 100644 --- a/embassy-stm32/src/rcc/f7.rs +++ b/embassy-stm32/src/rcc/f7.rs @@ -1,6 +1,7 @@ use crate::pac::pwr::vals::Vos; use crate::pac::rcc::vals::{Hpre, Ppre, Sw}; use crate::pac::{FLASH, PWR, RCC}; +use crate::rcc::bd::{BackupDomain, RtcClockSource}; use crate::rcc::{set_freqs, Clocks}; use crate::time::Hertz; @@ -22,6 +23,9 @@ pub struct Config { pub pclk2: Option, pub pll48: bool, + pub rtc: Option, + pub lsi: bool, + pub lse: Option, } fn setup_pll(pllsrcclk: u32, use_hse: bool, pllsysclk: Option, pll48clk: bool) -> PllResults { @@ -259,6 +263,18 @@ pub(crate) unsafe fn init(config: Config) { }) }); + BackupDomain::configure_ls( + config.rtc.unwrap_or(RtcClockSource::NOCLOCK), + config.lsi, + config.lse.map(|_| Default::default()), + ); + + let rtc = match config.rtc { + Some(RtcClockSource::LSI) => Some(LSI_FREQ), + Some(RtcClockSource::LSE) => Some(config.lse.unwrap()), + _ => None, + }; + set_freqs(Clocks { sys: Hertz(sysclk), apb1: Hertz(pclk1), @@ -272,6 +288,8 @@ pub(crate) unsafe fn init(config: Config) { ahb3: Hertz(hclk), pll48: plls.pll48clk.map(Hertz), + + rtc, }); } diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 0d6b0e308..9ccf2ac4f 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs @@ -97,7 +97,7 @@ pub struct Clocks { #[cfg(stm32f334)] pub hrtim: Option, - #[cfg(any(rcc_wb, rcc_f4, rcc_f410))] + #[cfg(any(rcc_wb, rcc_f4, rcc_f410, rcc_f7))] /// Set only if the lsi or lse is configured, indicates stop is supported pub rtc: Option,