From 4e4da7854f8e162f3a8ffa0dae5595a1baf78952 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 4 Nov 2025 13:12:46 +0100 Subject: feat: add nrf54 config to set clock speed --- embassy-nrf/src/lib.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'embassy-nrf/src') diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 530964107..bc386e820 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs @@ -285,6 +285,15 @@ pub use crate::pac::NVIC_PRIO_BITS; pub mod config { //! Configuration options used when initializing the HAL. + /// Clock speed + #[cfg(feature = "_nrf54l")] + pub enum ClockSpeed { + /// Run at 128 MHz. + CK128, + /// Run at 64 MHz. + CK64, + } + /// High frequency clock source. pub enum HfclkSource { /// Internal source @@ -554,6 +563,8 @@ pub mod config { pub time_interrupt_priority: crate::interrupt::Priority, /// Enable or disable the debug port. pub debug: Debug, + #[cfg(feature = "_nrf54l")] + pub clock_speed: ClockSpeed, } impl Default for Config { @@ -594,6 +605,8 @@ pub mod config { debug: Debug::NotConfigured, #[cfg(not(feature = "_ns"))] debug: Debug::Allowed, + #[cfg(feature = "_nrf54l")] + clock_speed: ClockSpeed::CK64, } } } @@ -700,6 +713,23 @@ pub fn init(config: config::Config) -> Peripherals { #[allow(unused_mut)] let mut needs_reset = false; + // set clock speed + #[cfg(feature = "_nrf54l")] + { + #[cfg(feature = "_s")] + let regs = pac::OSCILLATORS_S; + #[cfg(feature = "_ns")] + let regs = pac::OSCILLATORS_NS; + + use pac::oscillators::vals::Freq; + regs.pll().freq().write(|w| { + w.set_freq(match config.clock_speed { + config::ClockSpeed::CK64 => Freq::CK64M, + config::ClockSpeed::CK128 => Freq::CK128M, + }); + }); + } + // Workaround used in the nrf mdk: file system_nrf91.c , function SystemInit(), after `#if !defined(NRF_SKIP_UICR_HFXO_WORKAROUND)` #[cfg(all(feature = "_nrf91", feature = "_s"))] { -- cgit