aboutsummaryrefslogtreecommitdiff
path: root/embassy-imxrt
diff options
context:
space:
mode:
authorFelipe Balbi <[email protected]>2025-05-07 12:56:58 -0700
committerFelipe Balbi <[email protected]>2025-05-07 12:57:49 -0700
commit297ff3d03229bedb2582c171be23b488ecc4e520 (patch)
tree7f63ba0e224b63228ad100a2e88fcbe45bc528a4 /embassy-imxrt
parent64ce271af526a9311b0c1c251b19b5ce79032551 (diff)
clocks: remove defmt messages
Whenever any of the defmt-timestamp-uptime* features is enabled, defmt will insert code that reads the timestamp in order to embed it into the format string. This means that we *must* have a functional time driver by the time the very first defmt message is printed. Because clocks.rs is the part of the code setting up clocks that may, indeed, be required by the chosen clock driver, it cannot contain any defmt messages, otherwise it will trigger a read to a function that does not yet exist. Signed-off-by: Felipe Balbi <[email protected]>
Diffstat (limited to 'embassy-imxrt')
-rw-r--r--embassy-imxrt/src/clocks.rs42
1 files changed, 1 insertions, 41 deletions
diff --git a/embassy-imxrt/src/clocks.rs b/embassy-imxrt/src/clocks.rs
index 5be5f3925..39c3e6238 100644
--- a/embassy-imxrt/src/clocks.rs
+++ b/embassy-imxrt/src/clocks.rs
@@ -1,8 +1,6 @@
1//! Clock configuration for the `RT6xx` 1//! Clock configuration for the `RT6xx`
2use core::sync::atomic::{AtomicU32, AtomicU8, Ordering}; 2use core::sync::atomic::{AtomicU32, AtomicU8, Ordering};
3 3
4#[cfg(feature = "defmt")]
5use defmt;
6use paste::paste; 4use paste::paste;
7 5
8use crate::pac; 6use crate::pac;
@@ -503,7 +501,6 @@ impl ConfigurableClock for LposcConfig {
503 } 501 }
504 } 502 }
505 } else { 503 } else {
506 error!("failed to convert desired clock rate, {:#}, to LPOSC Freq", freq);
507 Err(ClockError::InvalidFrequency) 504 Err(ClockError::InvalidFrequency)
508 } 505 }
509 } 506 }
@@ -549,7 +546,6 @@ impl ConfigurableClock for FfroConfig {
549 Ok(()) 546 Ok(())
550 } 547 }
551 fn get_clock_rate(&self) -> Result<u32, ClockError> { 548 fn get_clock_rate(&self) -> Result<u32, ClockError> {
552 trace!("getting ffro clock rate");
553 Ok(self.freq.load(Ordering::Relaxed)) 549 Ok(self.freq.load(Ordering::Relaxed))
554 } 550 }
555 fn set_clock_rate(&mut self, _div: u8, _mult: u8, freq: u32) -> Result<(), ClockError> { 551 fn set_clock_rate(&mut self, _div: u8, _mult: u8, freq: u32) -> Result<(), ClockError> {
@@ -616,7 +612,6 @@ impl ConfigurableClock for SfroConfig {
616 fn set_clock_rate(&mut self, _div: u8, _mult: u8, freq: u32) -> Result<(), ClockError> { 612 fn set_clock_rate(&mut self, _div: u8, _mult: u8, freq: u32) -> Result<(), ClockError> {
617 if self.state == State::Enabled { 613 if self.state == State::Enabled {
618 if freq == SFRO_FREQ { 614 if freq == SFRO_FREQ {
619 trace!("Sfro frequency is already set at 16MHz");
620 Ok(()) 615 Ok(())
621 } else { 616 } else {
622 Err(ClockError::InvalidFrequency) 617 Err(ClockError::InvalidFrequency)
@@ -677,7 +672,6 @@ impl MultiSourceClock for MainPllClkConfig {
677 } 672 }
678 MainPllClkSrc::SFRO => { 673 MainPllClkSrc::SFRO => {
679 if !clock_src_config.is_enabled() { 674 if !clock_src_config.is_enabled() {
680 error!("Can't set SFRO as source for MainPll as it's not enabled");
681 return Err(ClockError::ClockNotEnabled); 675 return Err(ClockError::ClockNotEnabled);
682 } 676 }
683 // check if desired frequency is a valid multiple of 16m SFRO clock 677 // check if desired frequency is a valid multiple of 16m SFRO clock
@@ -703,7 +697,6 @@ impl ConfigurableClock for MainPllClkConfig {
703 } 697 }
704 fn disable(&self) -> Result<(), ClockError> { 698 fn disable(&self) -> Result<(), ClockError> {
705 if self.is_enabled() { 699 if self.is_enabled() {
706 error!("Attempting to reset the Main Pll Clock, should be resetting its source");
707 Err(ClockError::ClockNotSupported) 700 Err(ClockError::ClockNotSupported)
708 } else { 701 } else {
709 Err(ClockError::ClockNotEnabled) 702 Err(ClockError::ClockNotEnabled)
@@ -719,7 +712,6 @@ impl ConfigurableClock for MainPllClkConfig {
719 } 712 }
720 fn set_clock_rate(&mut self, div: u8, mult: u8, freq: u32) -> Result<(), ClockError> { 713 fn set_clock_rate(&mut self, div: u8, mult: u8, freq: u32) -> Result<(), ClockError> {
721 if self.is_enabled() { 714 if self.is_enabled() {
722 trace!("attempting to set main pll clock rate");
723 // SAFETY: unsafe needed to take pointers to Sysctl0 and Clkctl0 715 // SAFETY: unsafe needed to take pointers to Sysctl0 and Clkctl0
724 let clkctl0 = unsafe { crate::pac::Clkctl0::steal() }; 716 let clkctl0 = unsafe { crate::pac::Clkctl0::steal() };
725 let sysctl0 = unsafe { crate::pac::Sysctl0::steal() }; 717 let sysctl0 = unsafe { crate::pac::Sysctl0::steal() };
@@ -741,15 +733,12 @@ impl ConfigurableClock for MainPllClkConfig {
741 base_rate = r; 733 base_rate = r;
742 } 734 }
743 MainPllClkSrc::FFRO => { 735 MainPllClkSrc::FFRO => {
744 trace!("found FFRO as source, wait a bit");
745 delay_loop_clocks(1000, desired_freq); 736 delay_loop_clocks(1000, desired_freq);
746 match clkctl0.ffroctl0().read().trim_range().is_ffro_48mhz() { 737 match clkctl0.ffroctl0().read().trim_range().is_ffro_48mhz() {
747 true => base_rate = Into::into(FfroFreq::Ffro48m), 738 true => base_rate = Into::into(FfroFreq::Ffro48m),
748 false => base_rate = Into::into(FfroFreq::Ffro60m), 739 false => base_rate = Into::into(FfroFreq::Ffro60m),
749 } 740 }
750 trace!("found ffro rate to be: {:#}", base_rate);
751 if div == 2 { 741 if div == 2 {
752 trace!("dividing FFRO rate by 2");
753 clkctl0.syspll0clksel().write(|w| w.sel().ffro_div_2()); 742 clkctl0.syspll0clksel().write(|w| w.sel().ffro_div_2());
754 delay_loop_clocks(150, desired_freq); 743 delay_loop_clocks(150, desired_freq);
755 base_rate /= 2; 744 base_rate /= 2;
@@ -763,10 +752,8 @@ impl ConfigurableClock for MainPllClkConfig {
763 } 752 }
764 }; 753 };
765 base_rate *= u32::from(mult); 754 base_rate *= u32::from(mult);
766 trace!("calculated base rate at: {:#}", base_rate);
767 if base_rate != freq { 755 if base_rate != freq {
768 // make sure to power syspll back up before returning the error 756 // make sure to power syspll back up before returning the error
769 error!("invalid frequency found, powering syspll back up before returning error. Check div and mult");
770 // Clear System PLL reset 757 // Clear System PLL reset
771 clkctl0.syspll0ctl0().write(|w| w.reset().normal()); 758 clkctl0.syspll0ctl0().write(|w| w.reset().normal());
772 // Power up SYSPLL 759 // Power up SYSPLL
@@ -775,13 +762,11 @@ impl ConfigurableClock for MainPllClkConfig {
775 .write(|w| w.syspllana_pd().clr_pdruncfg0().syspllldo_pd().clr_pdruncfg0()); 762 .write(|w| w.syspllana_pd().clr_pdruncfg0().syspllldo_pd().clr_pdruncfg0());
776 return Err(ClockError::InvalidFrequency); 763 return Err(ClockError::InvalidFrequency);
777 } 764 }
778 trace!("setting default num and denom");
779 // SAFETY: unsafe needed to write the bits for the num and demon fields 765 // SAFETY: unsafe needed to write the bits for the num and demon fields
780 clkctl0.syspll0num().write(|w| unsafe { w.num().bits(0b0) }); 766 clkctl0.syspll0num().write(|w| unsafe { w.num().bits(0b0) });
781 clkctl0.syspll0denom().write(|w| unsafe { w.denom().bits(0b1) }); 767 clkctl0.syspll0denom().write(|w| unsafe { w.denom().bits(0b1) });
782 delay_loop_clocks(30, desired_freq); 768 delay_loop_clocks(30, desired_freq);
783 self.mult.store(mult, Ordering::Relaxed); 769 self.mult.store(mult, Ordering::Relaxed);
784 trace!("setting self.mult as: {:#}", mult);
785 match mult { 770 match mult {
786 16 => { 771 16 => {
787 clkctl0.syspll0ctl0().modify(|_r, w| w.mult().div_16()); 772 clkctl0.syspll0ctl0().modify(|_r, w| w.mult().div_16());
@@ -803,7 +788,6 @@ impl ConfigurableClock for MainPllClkConfig {
803 } 788 }
804 _ => return Err(ClockError::InvalidMult), 789 _ => return Err(ClockError::InvalidMult),
805 } 790 }
806 trace!("clear syspll reset");
807 // Clear System PLL reset 791 // Clear System PLL reset
808 clkctl0.syspll0ctl0().modify(|_r, w| w.reset().normal()); 792 clkctl0.syspll0ctl0().modify(|_r, w| w.reset().normal());
809 // Power up SYSPLL 793 // Power up SYSPLL
@@ -819,7 +803,6 @@ impl ConfigurableClock for MainPllClkConfig {
819 clkctl0.syspll0ctl0().modify(|_, w| w.holdringoff_ena().dsiable()); 803 clkctl0.syspll0ctl0().modify(|_, w| w.holdringoff_ena().dsiable());
820 delay_loop_clocks(15, desired_freq); 804 delay_loop_clocks(15, desired_freq);
821 805
822 trace!("setting new PFD0 bits");
823 // gate the output and clear bits. 806 // gate the output and clear bits.
824 // SAFETY: unsafe needed to write the bits for pfd0 807 // SAFETY: unsafe needed to write the bits for pfd0
825 clkctl0 808 clkctl0
@@ -833,7 +816,6 @@ impl ConfigurableClock for MainPllClkConfig {
833 .modify(|_r, w| unsafe { w.pfd0_clkgate().not_gated().pfd0().bits(0x12) }); 816 .modify(|_r, w| unsafe { w.pfd0_clkgate().not_gated().pfd0().bits(0x12) });
834 // wait for ready bit to be set 817 // wait for ready bit to be set
835 delay_loop_clocks(50, desired_freq); 818 delay_loop_clocks(50, desired_freq);
836 trace!("waiting for mainpll clock to be ready");
837 while clkctl0.syspll0pfd().read().pfd0_clkrdy().bit_is_clear() {} 819 while clkctl0.syspll0pfd().read().pfd0_clkrdy().bit_is_clear() {}
838 // clear by writing a 1 820 // clear by writing a 1
839 clkctl0.syspll0pfd().modify(|_, w| w.pfd0_clkrdy().set_bit()); 821 clkctl0.syspll0pfd().modify(|_, w| w.pfd0_clkrdy().set_bit());
@@ -854,11 +836,9 @@ impl ConfigurableClock for MainPllClkConfig {
854impl MainPllClkConfig { 836impl MainPllClkConfig {
855 /// Calculate the mult value of a desired frequency, return error if invalid 837 /// Calculate the mult value of a desired frequency, return error if invalid
856 pub(self) fn calc_mult(rate: u32, base_freq: u32) -> Result<u8, ClockError> { 838 pub(self) fn calc_mult(rate: u32, base_freq: u32) -> Result<u8, ClockError> {
857 trace!("calculating mult for {:#} / {:#}", rate, base_freq);
858 const VALIDMULTS: [u8; 6] = [16, 17, 20, 22, 27, 33]; 839 const VALIDMULTS: [u8; 6] = [16, 17, 20, 22, 27, 33];
859 if rate > base_freq && rate % base_freq == 0 { 840 if rate > base_freq && rate % base_freq == 0 {
860 let mult = (rate / base_freq) as u8; 841 let mult = (rate / base_freq) as u8;
861 trace!("verifying that calculated mult {:#} is a valid one", mult);
862 if VALIDMULTS.into_iter().any(|i| i == mult) { 842 if VALIDMULTS.into_iter().any(|i| i == mult) {
863 Ok(mult) 843 Ok(mult)
864 } else { 844 } else {
@@ -1112,7 +1092,6 @@ impl ConfigurableClock for MainClkConfig {
1112 Ok(()) 1092 Ok(())
1113 } 1093 }
1114 fn disable(&self) -> Result<(), ClockError> { 1094 fn disable(&self) -> Result<(), ClockError> {
1115 error!("Attempting to reset the main clock, should NOT happen during runtime");
1116 Err(ClockError::ClockNotSupported) 1095 Err(ClockError::ClockNotSupported)
1117 } 1096 }
1118 fn get_clock_rate(&self) -> Result<u32, ClockError> { 1097 fn get_clock_rate(&self) -> Result<u32, ClockError> {
@@ -1120,7 +1099,6 @@ impl ConfigurableClock for MainClkConfig {
1120 Ok(rate) 1099 Ok(rate)
1121 } 1100 }
1122 fn set_clock_rate(&mut self, _div: u8, _mult: u8, _freq: u32) -> Result<(), ClockError> { 1101 fn set_clock_rate(&mut self, _div: u8, _mult: u8, _freq: u32) -> Result<(), ClockError> {
1123 error!("The multi-source set_clock_rate_and_source method should be used instead of set_clock_rate");
1124 Err(ClockError::ClockNotSupported) 1102 Err(ClockError::ClockNotSupported)
1125 } 1103 }
1126 fn is_enabled(&self) -> bool { 1104 fn is_enabled(&self) -> bool {
@@ -1145,7 +1123,6 @@ impl ConfigurableClock for ClkInConfig {
1145 } 1123 }
1146 } 1124 }
1147 fn set_clock_rate(&mut self, _div: u8, _mult: u8, freq: u32) -> Result<(), ClockError> { 1125 fn set_clock_rate(&mut self, _div: u8, _mult: u8, freq: u32) -> Result<(), ClockError> {
1148 trace!("Setting value of clk in config, this won't change the clock itself");
1149 self.freq.as_ref().unwrap().store(freq, Ordering::Relaxed); 1126 self.freq.as_ref().unwrap().store(freq, Ordering::Relaxed);
1150 Ok(()) 1127 Ok(())
1151 } 1128 }
@@ -1188,7 +1165,6 @@ impl ConfigurableClock for RtcClkConfig {
1188 Ok(()) 1165 Ok(())
1189 } 1166 }
1190 fn disable(&self) -> Result<(), ClockError> { 1167 fn disable(&self) -> Result<(), ClockError> {
1191 error!("Resetting the RTC clock, this should NOT happen during runtime");
1192 Err(ClockError::ClockNotSupported) 1168 Err(ClockError::ClockNotSupported)
1193 } 1169 }
1194 fn set_clock_rate(&mut self, _div: u8, _mult: u8, freq: u32) -> Result<(), ClockError> { 1170 fn set_clock_rate(&mut self, _div: u8, _mult: u8, freq: u32) -> Result<(), ClockError> {
@@ -1199,7 +1175,6 @@ impl ConfigurableClock for RtcClkConfig {
1199 match r { 1175 match r {
1200 RtcFreq::Default1Hz => { 1176 RtcFreq::Default1Hz => {
1201 if rtc.ctrl().read().rtc_en().is_enable() { 1177 if rtc.ctrl().read().rtc_en().is_enable() {
1202 trace!("Attempting to enable an already enabled clock, RTC 1Hz");
1203 } else { 1178 } else {
1204 rtc.ctrl().modify(|_r, w| w.rtc_en().enable()); 1179 rtc.ctrl().modify(|_r, w| w.rtc_en().enable());
1205 } 1180 }
@@ -1207,7 +1182,6 @@ impl ConfigurableClock for RtcClkConfig {
1207 } 1182 }
1208 RtcFreq::HighResolution1khz => { 1183 RtcFreq::HighResolution1khz => {
1209 if rtc.ctrl().read().rtc1khz_en().is_enable() { 1184 if rtc.ctrl().read().rtc1khz_en().is_enable() {
1210 trace!("Attempting to enable an already enabled clock, RTC 1Hz");
1211 } else { 1185 } else {
1212 rtc.ctrl().modify(|_r, w| w.rtc1khz_en().enable()); 1186 rtc.ctrl().modify(|_r, w| w.rtc1khz_en().enable());
1213 } 1187 }
@@ -1215,7 +1189,6 @@ impl ConfigurableClock for RtcClkConfig {
1215 } 1189 }
1216 RtcFreq::SubSecond32kHz => { 1190 RtcFreq::SubSecond32kHz => {
1217 if rtc.ctrl().read().rtc_subsec_ena().is_enable() { 1191 if rtc.ctrl().read().rtc_subsec_ena().is_enable() {
1218 trace!("Attempting to enable an already enabled clock, RTC 1Hz");
1219 } else { 1192 } else {
1220 rtc.ctrl().modify(|_r, w| w.rtc_subsec_ena().enable()); 1193 rtc.ctrl().modify(|_r, w| w.rtc_subsec_ena().enable());
1221 } 1194 }
@@ -1245,18 +1218,12 @@ impl ConfigurableClock for RtcClkConfig {
1245 1218
1246impl SysClkConfig { 1219impl SysClkConfig {
1247 /// Updates the system core clock frequency, SW concept used for systick 1220 /// Updates the system core clock frequency, SW concept used for systick
1248 fn update_sys_core_clock(&self) { 1221 fn update_sys_core_clock(&self) {}
1249 trace!(
1250 "System core clock has been updated to {:?}, this involves no HW reg writes",
1251 self.sysclkfreq.load(Ordering::Relaxed)
1252 );
1253 }
1254} 1222}
1255 1223
1256impl ConfigurableClock for SysOscConfig { 1224impl ConfigurableClock for SysOscConfig {
1257 fn enable_and_reset(&self) -> Result<(), ClockError> { 1225 fn enable_and_reset(&self) -> Result<(), ClockError> {
1258 if self.state == State::Enabled { 1226 if self.state == State::Enabled {
1259 trace!("SysOsc was already enabled");
1260 return Ok(()); 1227 return Ok(());
1261 } 1228 }
1262 1229
@@ -1498,32 +1465,26 @@ impl ClockOutConfig {
1498/// Using the config, enables all desired clocks to desired clock rates 1465/// Using the config, enables all desired clocks to desired clock rates
1499fn init_clock_hw(config: ClockConfig) -> Result<(), ClockError> { 1466fn init_clock_hw(config: ClockConfig) -> Result<(), ClockError> {
1500 if let Err(e) = config.rtc.enable_and_reset() { 1467 if let Err(e) = config.rtc.enable_and_reset() {
1501 error!("couldn't Power on OSC for RTC, result: {:?}", e);
1502 return Err(e); 1468 return Err(e);
1503 } 1469 }
1504 1470
1505 if let Err(e) = config.lposc.enable_and_reset() { 1471 if let Err(e) = config.lposc.enable_and_reset() {
1506 error!("couldn't Power on LPOSC, result: {:?}", e);
1507 return Err(e); 1472 return Err(e);
1508 } 1473 }
1509 1474
1510 if let Err(e) = config.ffro.enable_and_reset() { 1475 if let Err(e) = config.ffro.enable_and_reset() {
1511 error!("couldn't Power on FFRO, result: {:?}", e);
1512 return Err(e); 1476 return Err(e);
1513 } 1477 }
1514 1478
1515 if let Err(e) = config.sfro.enable_and_reset() { 1479 if let Err(e) = config.sfro.enable_and_reset() {
1516 error!("couldn't Power on SFRO, result: {:?}", e);
1517 return Err(e); 1480 return Err(e);
1518 } 1481 }
1519 1482
1520 if let Err(e) = config.sys_osc.enable_and_reset() { 1483 if let Err(e) = config.sys_osc.enable_and_reset() {
1521 error!("Couldn't enable sys oscillator {:?}", e);
1522 return Err(e); 1484 return Err(e);
1523 } 1485 }
1524 1486
1525 if let Err(e) = config.main_pll_clk.enable_and_reset() { 1487 if let Err(e) = config.main_pll_clk.enable_and_reset() {
1526 error!("Couldn't enable main pll clock {:?}", e);
1527 return Err(e); 1488 return Err(e);
1528 } 1489 }
1529 1490
@@ -1542,7 +1503,6 @@ fn init_clock_hw(config: ClockConfig) -> Result<(), ClockError> {
1542 init_syscpuahb_clk(); 1503 init_syscpuahb_clk();
1543 1504
1544 if let Err(e) = config.main_clk.enable_and_reset() { 1505 if let Err(e) = config.main_clk.enable_and_reset() {
1545 error!("Couldn't enable main clock {:?}", e);
1546 return Err(e); 1506 return Err(e);
1547 } 1507 }
1548 1508