Skip to content

Commit 530fc00

Browse files
committed
Remove slow-clocks from default features in toml file as well as improperly hard-coded clock reg values
Remove some hardcoded clock reg settings and use the config blob fields instead. Remove slow-clocks feature from default as clock config passed into init function should be fully utilized now. Pending full removal of slow-clocks feature after more thorough validation Add default impl for ClockConfig
1 parent 0ddadeb commit 530fc00

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ flavors = [
2121
features = ["time", "defmt", "unstable-pac", "time-driver-os-timer"]
2222

2323
[features]
24-
default = ["rt", "time", "slow-clocks"]
24+
default = ["rt", "time"]
2525

2626
## Cortex-M runtime (enabled by default)
2727
rt = ["mimxrt685s-pac?/rt", "mimxrt633s-pac?/rt"]

src/clocks.rs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ impl ClockConfig {
143143
}
144144
}
145145

146+
impl Default for ClockConfig {
147+
fn default() -> Self {
148+
Self::crystal()
149+
}
150+
}
151+
146152
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
147153
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
148154
/// Clock state enum
@@ -711,7 +717,7 @@ impl MultiSourceClock for MainPllClkConfig {
711717

712718
impl ConfigurableClock for MainPllClkConfig {
713719
fn enable_and_reset(&self) -> Result<(), ClockError> {
714-
MainPllClkConfig::init_syspll();
720+
MainPllClkConfig::init_syspll(&self);
715721

716722
MainPllClkConfig::init_syspll_pfd0(self.pfd0);
717723

@@ -874,7 +880,7 @@ impl MainPllClkConfig {
874880
}
875881
}
876882

877-
pub(self) fn init_syspll() {
883+
pub(self) fn init_syspll(&self) {
878884
// SAFETY: unsafe needed to take pointers to Sysctl0 and Clkctl0
879885
let clkctl0 = unsafe { crate::pac::Clkctl0::steal() };
880886
let sysctl0 = unsafe { crate::pac::Sysctl0::steal() };
@@ -884,20 +890,35 @@ impl MainPllClkConfig {
884890
.pdruncfg0_set()
885891
.write(|w| w.syspllldo_pd().set_pdruncfg0().syspllana_pd().set_pdruncfg0());
886892

887-
#[cfg(not(feature = "slow-clocks"))]
888-
clkctl0.syspll0clksel().write(|w| w.sel().ffro_div_2());
889-
#[cfg(feature = "slow-clocks")]
890-
clkctl0.syspll0clksel().write(|w| w.sel().sfro_clk());
893+
match self.src {
894+
MainPllClkSrc::ClkIn => {
895+
clkctl0.syspll0clksel().write(|w| w.sel().sysxtal_clk());
896+
}
897+
MainPllClkSrc::FFRO => {
898+
// FFRO Clock is divided by 2
899+
clkctl0.syspll0clksel().write(|w| w.sel().ffro_div_2());
900+
}
901+
MainPllClkSrc::SFRO => {
902+
clkctl0.syspll0clksel().write(|w| w.sel().sfro_clk());
903+
}
904+
}
905+
891906
// SAFETY: unsafe needed to write the bits for both num and denom
892907
clkctl0.syspll0num().write(|w| unsafe { w.num().bits(0x0) });
893908
clkctl0.syspll0denom().write(|w| unsafe { w.denom().bits(0x1) });
894909

895-
// kCLOCK_SysPllMult22
896-
// really should be using the mult defined in main pll config
897-
#[cfg(feature = "slow-clocks")]
898-
clkctl0.syspll0ctl0().modify(|_, w| w.mult().div_16());
899-
#[cfg(not(feature = "slow-clocks"))]
900-
clkctl0.syspll0ctl0().modify(|_, w| w.mult().div_22());
910+
// kCLOCK_SetSysPll<Mult>
911+
// Use the mult defined in main pll config
912+
// if invalid, use 22 as default instead of panicking
913+
match self.mult.load(Ordering::Relaxed) {
914+
16 => clkctl0.syspll0ctl0().modify(|_, w| w.mult().div_16()),
915+
17 => clkctl0.syspll0ctl0().modify(|_, w| w.mult().div_17()),
916+
20 => clkctl0.syspll0ctl0().modify(|_, w| w.mult().div_20()),
917+
22 => clkctl0.syspll0ctl0().modify(|_, w| w.mult().div_22()),
918+
27 => clkctl0.syspll0ctl0().modify(|_, w| w.mult().div_27()),
919+
33 => clkctl0.syspll0ctl0().modify(|_, w| w.mult().div_33()),
920+
_ => clkctl0.syspll0ctl0().modify(|_, w| w.mult().div_22()),
921+
};
901922

902923
// Clear System PLL reset
903924
clkctl0.syspll0ctl0().modify(|_, w| w.reset().normal());
@@ -1548,11 +1569,10 @@ fn init_clock_hw(config: ClockConfig) -> Result<(), ClockError> {
15481569

15491570
config.main_pll_clk.enable_and_reset()?;
15501571

1551-
#[cfg(feature = "slow-clocks")]
15521572
fsl_power::set_ldo_voltage_for_freq(
15531573
fsl_power::TempRange::TempN20CtoP85C,
15541574
fsl_power::VoltOpRange::Low,
1555-
140_000_000,
1575+
config.main_clk.freq.load(Ordering::Relaxed),
15561576
0,
15571577
);
15581578

0 commit comments

Comments
 (0)