debug/fix frequency changes into and out of WFI

I am now confident that the FCLK frequency is correct
going into WFI.
This commit is contained in:
bunnie 2026-05-08 03:12:47 +08:00
parent b48df7182b
commit d30ef2f197
3 changed files with 17 additions and 5 deletions

View file

@ -134,10 +134,16 @@ impl<'a> BioApi<'a> for Bio {
}
}
fn prep_freq_change(&mut self) {
fn prep_freq_change(&mut self, into_wfi: bool) {
send_message(
self.conn,
Message::new_blocking_scalar(BioOp::PrepFreqChange.to_usize().unwrap(), 0, 0, 0, 0),
Message::new_blocking_scalar(
BioOp::PrepFreqChange.to_usize().unwrap(),
if into_wfi { 1 } else { 0 },
0,
0,
0,
),
)
.ok();
}

View file

@ -405,10 +405,12 @@ impl BioSharedState {
// mask in the core that is now listening to the clock
let existing_extclk = self.bio.rf(bio_bdma::SFR_EXTCLOCK_USE_EXTCLK);
self.bio.rmwf(bio_bdma::SFR_EXTCLOCK_USE_EXTCLK, (1 << core as u32) | existing_extclk);
crate::println!("core: {:?} - extclock {:x}", core, self.bio.r(bio_bdma::SFR_EXTCLOCK));
// crate::println!("core: {:?} - extclock {:x}", core, self.bio.r(bio_bdma::SFR_EXTCLOCK));
return None;
}
};
#[cfg(feature = "std")]
log::debug!("config: {:?}, int {}, fraq {}, actual {}", config, div_int, div_frac, actual_freq);
let sfr_value = (div_int as u32) << 16 | (div_frac as u32) << 8;
match core {
BioCore::Core0 => {
@ -494,6 +496,8 @@ impl<'a> BioApi<'a> for BioSharedState {
fn update_bio_freq(&mut self, freq: u32) -> u32 {
let prev_freq = self.fclk_freq_hz;
self.fclk_freq_hz = freq;
#[cfg(feature = "std")]
log::debug!("new freq: {}, old freq: {}", freq, prev_freq);
for (i, config) in self.core_config.clone().iter().enumerate() {
if let Some(config) = config {
self.apply_config(config, i.into());
@ -502,7 +506,7 @@ impl<'a> BioApi<'a> for BioSharedState {
prev_freq
}
fn prep_freq_change(&mut self) {
fn prep_freq_change(&mut self, _wfi: bool) {
// at the hw level, there's nothing to do; a handler at the `std` level is invoked instead
}

View file

@ -637,7 +637,9 @@ impl ClockManagerImpl {
self.sysctrl.wo(utra::sysctrl::SFR_CGUSET, 0x32);
wfi_debug("internal osc");
// don't divide fclk -- allows BIO to keep operating at 48MHz rate
self.sysctrl.wo(utra::sysctrl::SFR_CGUFD_CFGFDCR_0_4_0, 0x0700_01ff);
self.sysctrl.wo(utra::sysctrl::SFR_CGUFD_CFGFDCR_0_4_0, 0x0000_ffff);
self.sysctrl.wo(utra::sysctrl::SFR_CGUFD_CFGFDCR_0_4_0, 0x0000_ffff);
self.sysctrl.wo(utra::sysctrl::SFR_CGUSET, 0x32);
// lower core voltage to 0.7v
self.ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUTRM0CSR, 0x08420002);