Skip to content

Commit bf0e92e

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
1 parent 0ddadeb commit bf0e92e

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-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: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ impl MultiSourceClock for MainPllClkConfig {
711711

712712
impl ConfigurableClock for MainPllClkConfig {
713713
fn enable_and_reset(&self) -> Result<(), ClockError> {
714-
MainPllClkConfig::init_syspll();
714+
MainPllClkConfig::init_syspll(&self);
715715

716716
MainPllClkConfig::init_syspll_pfd0(self.pfd0);
717717

@@ -874,7 +874,7 @@ impl MainPllClkConfig {
874874
}
875875
}
876876

877-
pub(self) fn init_syspll() {
877+
pub(self) fn init_syspll(&self) {
878878
// SAFETY: unsafe needed to take pointers to Sysctl0 and Clkctl0
879879
let clkctl0 = unsafe { crate::pac::Clkctl0::steal() };
880880
let sysctl0 = unsafe { crate::pac::Sysctl0::steal() };
@@ -884,20 +884,35 @@ impl MainPllClkConfig {
884884
.pdruncfg0_set()
885885
.write(|w| w.syspllldo_pd().set_pdruncfg0().syspllana_pd().set_pdruncfg0());
886886

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());
887+
match self.src {
888+
MainPllClkSrc::ClkIn => {
889+
clkctl0.syspll0clksel().write(|w| w.sel().sysxtal_clk());
890+
}
891+
MainPllClkSrc::FFRO => {
892+
// FFRO Clock is divided by 2
893+
clkctl0.syspll0clksel().write(|w| w.sel().ffro_div_2());
894+
}
895+
MainPllClkSrc::SFRO => {
896+
clkctl0.syspll0clksel().write(|w| w.sel().sfro_clk());
897+
}
898+
}
899+
891900
// SAFETY: unsafe needed to write the bits for both num and denom
892901
clkctl0.syspll0num().write(|w| unsafe { w.num().bits(0x0) });
893902
clkctl0.syspll0denom().write(|w| unsafe { w.denom().bits(0x1) });
894903

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());
904+
// kCLOCK_SetSysPll<Mult>
905+
// Use the mult defined in main pll config
906+
// if invalid, use 22 as default instead of panicking
907+
match self.mult.load(Ordering::Relaxed) {
908+
16 => clkctl0.syspll0ctl0().modify(|_, w| w.mult().div_16()),
909+
17 => clkctl0.syspll0ctl0().modify(|_, w| w.mult().div_17()),
910+
20 => clkctl0.syspll0ctl0().modify(|_, w| w.mult().div_20()),
911+
22 => clkctl0.syspll0ctl0().modify(|_, w| w.mult().div_22()),
912+
27 => clkctl0.syspll0ctl0().modify(|_, w| w.mult().div_27()),
913+
33 => clkctl0.syspll0ctl0().modify(|_, w| w.mult().div_33()),
914+
_ => clkctl0.syspll0ctl0().modify(|_, w| w.mult().div_22()),
915+
};
901916

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

15491564
config.main_pll_clk.enable_and_reset()?;
15501565

1551-
#[cfg(feature = "slow-clocks")]
15521566
fsl_power::set_ldo_voltage_for_freq(
15531567
fsl_power::TempRange::TempN20CtoP85C,
15541568
fsl_power::VoltOpRange::Low,
1555-
140_000_000,
1569+
config.main_clk.freq.load(Ordering::Relaxed),
15561570
0,
15571571
);
15581572

0 commit comments

Comments
 (0)