stm32/rtc: enable in rcc mod
This commit is contained in:
parent
766b5fc6f6
commit
66c1712118
@ -73,6 +73,10 @@ pub struct Clocks {
|
|||||||
|
|
||||||
#[cfg(any(rcc_h5, rcc_h50, rcc_h7, rcc_h7ab))]
|
#[cfg(any(rcc_h5, rcc_h50, rcc_h7, rcc_h7ab))]
|
||||||
pub adc: Option<Hertz>,
|
pub adc: Option<Hertz>,
|
||||||
|
|
||||||
|
#[cfg(rcc_wb)]
|
||||||
|
/// Set only if the lsi or lse is configured
|
||||||
|
pub rtc: Option<Hertz>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Frozen clock frequencies
|
/// Frozen clock frequencies
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
pub use super::common::{AHBPrescaler, APBPrescaler};
|
pub use super::common::{AHBPrescaler, APBPrescaler};
|
||||||
use crate::rcc::Clocks;
|
use crate::rcc::Clocks;
|
||||||
|
use crate::rtc::{enable_rtc, RtcClockSource};
|
||||||
use crate::time::{khz, mhz, Hertz};
|
use crate::time::{khz, mhz, Hertz};
|
||||||
|
|
||||||
/// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC,
|
/// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC,
|
||||||
@ -110,6 +111,7 @@ pub struct Config {
|
|||||||
pub sys: Sysclk,
|
pub sys: Sysclk,
|
||||||
pub mux: Option<PllMux>,
|
pub mux: Option<PllMux>,
|
||||||
pub pll48: Option<Pll48Source>,
|
pub pll48: Option<Pll48Source>,
|
||||||
|
pub rtc: Option<RtcClockSource>,
|
||||||
|
|
||||||
pub pll: Option<Pll>,
|
pub pll: Option<Pll>,
|
||||||
pub pllsai: Option<Pll>,
|
pub pllsai: Option<Pll>,
|
||||||
@ -133,6 +135,7 @@ pub const WPAN_DEFAULT: Config = Config {
|
|||||||
prediv: 2,
|
prediv: 2,
|
||||||
}),
|
}),
|
||||||
pll48: None,
|
pll48: None,
|
||||||
|
rtc: None,
|
||||||
|
|
||||||
pll: Some(Pll {
|
pll: Some(Pll {
|
||||||
mul: 12,
|
mul: 12,
|
||||||
@ -160,6 +163,7 @@ impl Default for Config {
|
|||||||
pll48: None,
|
pll48: None,
|
||||||
pll: None,
|
pll: None,
|
||||||
pllsai: None,
|
pllsai: None,
|
||||||
|
rtc: None,
|
||||||
|
|
||||||
ahb1_pre: AHBPrescaler::NotDivided,
|
ahb1_pre: AHBPrescaler::NotDivided,
|
||||||
ahb2_pre: AHBPrescaler::NotDivided,
|
ahb2_pre: AHBPrescaler::NotDivided,
|
||||||
@ -251,6 +255,12 @@ pub(crate) fn compute_clocks(config: &Config) -> Clocks {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let rtc_clk = match config.rtc {
|
||||||
|
Some(RtcClockSource::LSI) => Some(LSI_FREQ),
|
||||||
|
Some(RtcClockSource::LSE) => Some(config.lse.unwrap()),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
|
||||||
Clocks {
|
Clocks {
|
||||||
sys: sys_clk,
|
sys: sys_clk,
|
||||||
ahb1: ahb1_clk,
|
ahb1: ahb1_clk,
|
||||||
@ -260,6 +270,7 @@ pub(crate) fn compute_clocks(config: &Config) -> Clocks {
|
|||||||
apb2: apb2_clk,
|
apb2: apb2_clk,
|
||||||
apb1_tim: apb1_tim_clk,
|
apb1_tim: apb1_tim_clk,
|
||||||
apb2_tim: apb2_tim_clk,
|
apb2_tim: apb2_tim_clk,
|
||||||
|
rtc: rtc_clk,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,6 +292,18 @@ pub(crate) fn configure_clocks(config: &Config) {
|
|||||||
while !rcc.cr().read().hsirdy() {}
|
while !rcc.cr().read().hsirdy() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let needs_lsi = if let Some(rtc_mux) = &config.rtc {
|
||||||
|
*rtc_mux == RtcClockSource::LSI
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
|
if needs_lsi {
|
||||||
|
rcc.csr().modify(|w| w.set_lsi1on(true));
|
||||||
|
|
||||||
|
while !rcc.csr().read().lsi1rdy() {}
|
||||||
|
}
|
||||||
|
|
||||||
match &config.lse {
|
match &config.lse {
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
rcc.cfgr().modify(|w| w.set_stopwuck(true));
|
rcc.cfgr().modify(|w| w.set_stopwuck(true));
|
||||||
@ -351,4 +374,6 @@ pub(crate) fn configure_clocks(config: &Config) {
|
|||||||
w.set_c2hpre(config.ahb2_pre.into());
|
w.set_c2hpre(config.ahb2_pre.into());
|
||||||
w.set_shdhpre(config.ahb3_pre.into());
|
w.set_shdhpre(config.ahb3_pre.into());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
config.rtc.map(|clock_source| enable_rtc(clock_source));
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,21 @@ pub struct Rtc<'d, T: Instance> {
|
|||||||
rtc_config: RtcConfig,
|
rtc_config: RtcConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn enable_rtc(clock_source: RtcClockSource) {
|
||||||
|
// TODO: rewrite the RTC module so that enable is separated from configure
|
||||||
|
|
||||||
|
assert!(clock_source == RtcClockSource::LSI || clock_source == RtcClockSource::LSE);
|
||||||
|
|
||||||
|
let _ = Rtc::new(
|
||||||
|
unsafe { crate::Peripherals::steal().RTC },
|
||||||
|
RtcConfig {
|
||||||
|
clock_config: clock_source,
|
||||||
|
async_prescaler: 1,
|
||||||
|
sync_prescaler: 1,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum RtcClockSource {
|
pub enum RtcClockSource {
|
||||||
|
Loading…
Reference in New Issue
Block a user