From 24105e7b22b44d5a7d26ff286b4ee2abc6155674 Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 14 Jan 2026 03:20:27 +0800 Subject: [PATCH] add the default perclk speed as a public constant instead of just hard-coding it in the clock setting routine --- libs/bao1x-hal/src/clocks.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/bao1x-hal/src/clocks.rs b/libs/bao1x-hal/src/clocks.rs index 931fe4422..1020f99f9 100644 --- a/libs/bao1x-hal/src/clocks.rs +++ b/libs/bao1x-hal/src/clocks.rs @@ -12,6 +12,11 @@ use crate::i2c::I2c; #[cfg(feature = "std")] const MHZ: u32 = 1_000_000; +/// This is always the default target rate for peripheral clock, regardless of the pll setting +/// It's not always achievable - for example, when the PLL is turned off, which is why the actual +/// perclk is returned by the clock setting routines. +pub const PERCLK_HZ: u32 = 100_000_000; + #[bitfield(u32)] #[derive(PartialEq, Eq, Debug)] pub struct PmuControl { @@ -86,7 +91,7 @@ where daric_cgu.add(utra::sysctrl::SFR_CGUFD_CFGFDCR_0_4_4.offset()).write_volatile(0x7f00_010f); // pclk // peripheral clock should always target 100MHz regardless of the top frequency - let peri_params = bao1x_api::find_optimal_divider(freq_hz / 2, 100_000_000).unwrap(); + let peri_params = bao1x_api::find_optimal_divider(freq_hz / 2, PERCLK_HZ).unwrap(); let fd0 = peri_params.fd0; let fd2 = peri_params.fd2; daric_cgu.add(utra::sysctrl::SFR_CGUFDPER.offset()).write_volatile(