From 5f366957f31d87030182f80dd2d39dc8a8496883 Mon Sep 17 00:00:00 2001 From: James Munns Date: Fri, 12 Dec 2025 20:45:15 +0100 Subject: Add SOSC support --- examples/mcxa/src/bin/clkout.rs | 85 ++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 40 deletions(-) (limited to 'examples/mcxa/src/bin') diff --git a/examples/mcxa/src/bin/clkout.rs b/examples/mcxa/src/bin/clkout.rs index 1e52912d3..ba7c8185e 100644 --- a/examples/mcxa/src/bin/clkout.rs +++ b/examples/mcxa/src/bin/clkout.rs @@ -4,6 +4,7 @@ use embassy_executor::Spawner; use embassy_mcxa::clkout::{ClockOut, ClockOutSel, Config, Div4}; use embassy_mcxa::clocks::PoweredClock; +use embassy_mcxa::clocks::config::{SoscConfig, SoscMode, SoscRange}; use embassy_mcxa::gpio::{DriveStrength, Level, Output, SlewRate}; use embassy_time::Timer; use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; @@ -11,58 +12,62 @@ use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; /// Demonstrate CLKOUT, using Pin P4.2 #[embassy_executor::main] async fn main(_spawner: Spawner) { - let p = hal::init(hal::config::Config::default()); + let mut cfg = hal::config::Config::default(); + cfg.clock_cfg.sosc = Some(SoscConfig { + mode: SoscMode::CrystalOscillator, + frequency: 8_000_000, + range: SoscRange::Mhz8To16, + power: PoweredClock::NormalEnabledDeepSleepDisabled, + }); + + let p = hal::init(cfg); + let mut pin = p.P4_2; let mut clkout = p.CLKOUT; - loop { - defmt::info!("Set Low..."); - let mut output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow); - Timer::after_millis(500).await; + const K16_CONFIG: Config = Config { + sel: ClockOutSel::Clk16K, + div: Div4::no_div(), + level: PoweredClock::NormalEnabledDeepSleepDisabled, + }; + const M4_CONFIG: Config = Config { + sel: ClockOutSel::Fro12M, + div: const { Div4::from_divisor(3).unwrap() }, + level: PoweredClock::NormalEnabledDeepSleepDisabled, + }; + const K512_CONFIG: Config = Config { + sel: ClockOutSel::ClkIn, + div: const { Div4::from_divisor(16).unwrap() }, + level: PoweredClock::NormalEnabledDeepSleepDisabled, + }; + let configs = [ + ("16K -> /1 = 16K", K16_CONFIG), + ("12M -> /3 = 4M", M4_CONFIG), + ("8M -> /16 = 512K", K512_CONFIG), + ]; + + loop { defmt::info!("Set High..."); - output.set_high(); - Timer::after_millis(400).await; + let mut output = Output::new(pin.reborrow(), Level::High, DriveStrength::Normal, SlewRate::Slow); + Timer::after_millis(250).await; defmt::info!("Set Low..."); output.set_low(); - Timer::after_millis(500).await; + Timer::after_millis(750).await; - defmt::info!("16k..."); - // Run Clock Out with the 16K clock - let _clock_out = ClockOut::new( - clkout.reborrow(), - pin.reborrow(), - Config { - sel: ClockOutSel::Clk16K, - div: Div4::no_div(), - level: PoweredClock::NormalEnabledDeepSleepDisabled, - }, - ) - .unwrap(); + for (name, conf) in configs.iter() { + defmt::info!("Running {=str}", name); - Timer::after_millis(3000).await; - - defmt::info!("Set Low..."); - drop(_clock_out); + let _clock_out = ClockOut::new(clkout.reborrow(), pin.reborrow(), *conf).unwrap(); - let _output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow); - Timer::after_millis(500).await; + Timer::after_millis(3000).await; - // Run Clock Out with the 12M clock, divided by 3 - defmt::info!("4M..."); - let _clock_out = ClockOut::new( - clkout.reborrow(), - pin.reborrow(), - Config { - sel: ClockOutSel::Fro12M, - div: const { Div4::from_divisor(3).unwrap() }, - level: PoweredClock::NormalEnabledDeepSleepDisabled, - }, - ) - .unwrap(); + defmt::info!("Set Low..."); + drop(_clock_out); - // Let it run for 3 seconds... - Timer::after_millis(3000).await; + let _output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow); + Timer::after_millis(500).await; + } } } -- cgit From d6c65cd0e4b651b1b07e1583562dfccfd5db22b1 Mon Sep 17 00:00:00 2001 From: James Munns Date: Mon, 15 Dec 2025 14:33:47 +0100 Subject: Update example to not explicitly configure range --- examples/mcxa/src/bin/clkout.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples/mcxa/src/bin') diff --git a/examples/mcxa/src/bin/clkout.rs b/examples/mcxa/src/bin/clkout.rs index ba7c8185e..e6e6a2d3d 100644 --- a/examples/mcxa/src/bin/clkout.rs +++ b/examples/mcxa/src/bin/clkout.rs @@ -4,7 +4,7 @@ use embassy_executor::Spawner; use embassy_mcxa::clkout::{ClockOut, ClockOutSel, Config, Div4}; use embassy_mcxa::clocks::PoweredClock; -use embassy_mcxa::clocks::config::{SoscConfig, SoscMode, SoscRange}; +use embassy_mcxa::clocks::config::{SoscConfig, SoscMode}; use embassy_mcxa::gpio::{DriveStrength, Level, Output, SlewRate}; use embassy_time::Timer; use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; @@ -16,7 +16,6 @@ async fn main(_spawner: Spawner) { cfg.clock_cfg.sosc = Some(SoscConfig { mode: SoscMode::CrystalOscillator, frequency: 8_000_000, - range: SoscRange::Mhz8To16, power: PoweredClock::NormalEnabledDeepSleepDisabled, }); -- cgit