diff options
| author | James Munns <[email protected]> | 2025-12-18 13:55:57 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-18 13:55:57 +0000 |
| commit | b5b49cbcf3a991bf6d434b0870da50f3ee722612 (patch) | |
| tree | dd1c673cbe1e2512c785173762f8d63e472c5e8b /examples/mcxa/src | |
| parent | f85337064c724f8fdb855e847345908e4c7384e9 (diff) | |
| parent | d6c65cd0e4b651b1b07e1583562dfccfd5db22b1 (diff) | |
Merge pull request #5071 from jamesmunns/james/bad-sosc
[MCXA]: Add support for SOSC/clk_in
Diffstat (limited to 'examples/mcxa/src')
| -rw-r--r-- | examples/mcxa/src/bin/clkout.rs | 84 |
1 files changed, 44 insertions, 40 deletions
diff --git a/examples/mcxa/src/bin/clkout.rs b/examples/mcxa/src/bin/clkout.rs index 1e52912d3..e6e6a2d3d 100644 --- a/examples/mcxa/src/bin/clkout.rs +++ b/examples/mcxa/src/bin/clkout.rs | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 5 | use embassy_mcxa::clkout::{ClockOut, ClockOutSel, Config, Div4}; | 5 | use embassy_mcxa::clkout::{ClockOut, ClockOutSel, Config, Div4}; |
| 6 | use embassy_mcxa::clocks::PoweredClock; | 6 | use embassy_mcxa::clocks::PoweredClock; |
| 7 | use embassy_mcxa::clocks::config::{SoscConfig, SoscMode}; | ||
| 7 | use embassy_mcxa::gpio::{DriveStrength, Level, Output, SlewRate}; | 8 | use embassy_mcxa::gpio::{DriveStrength, Level, Output, SlewRate}; |
| 8 | use embassy_time::Timer; | 9 | use embassy_time::Timer; |
| 9 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; | 10 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; |
| @@ -11,58 +12,61 @@ use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; | |||
| 11 | /// Demonstrate CLKOUT, using Pin P4.2 | 12 | /// Demonstrate CLKOUT, using Pin P4.2 |
| 12 | #[embassy_executor::main] | 13 | #[embassy_executor::main] |
| 13 | async fn main(_spawner: Spawner) { | 14 | async fn main(_spawner: Spawner) { |
| 14 | let p = hal::init(hal::config::Config::default()); | 15 | let mut cfg = hal::config::Config::default(); |
| 16 | cfg.clock_cfg.sosc = Some(SoscConfig { | ||
| 17 | mode: SoscMode::CrystalOscillator, | ||
| 18 | frequency: 8_000_000, | ||
| 19 | power: PoweredClock::NormalEnabledDeepSleepDisabled, | ||
| 20 | }); | ||
| 21 | |||
| 22 | let p = hal::init(cfg); | ||
| 23 | |||
| 15 | let mut pin = p.P4_2; | 24 | let mut pin = p.P4_2; |
| 16 | let mut clkout = p.CLKOUT; | 25 | let mut clkout = p.CLKOUT; |
| 17 | 26 | ||
| 18 | loop { | 27 | const K16_CONFIG: Config = Config { |
| 19 | defmt::info!("Set Low..."); | 28 | sel: ClockOutSel::Clk16K, |
| 20 | let mut output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow); | 29 | div: Div4::no_div(), |
| 21 | Timer::after_millis(500).await; | 30 | level: PoweredClock::NormalEnabledDeepSleepDisabled, |
| 31 | }; | ||
| 32 | const M4_CONFIG: Config = Config { | ||
| 33 | sel: ClockOutSel::Fro12M, | ||
| 34 | div: const { Div4::from_divisor(3).unwrap() }, | ||
| 35 | level: PoweredClock::NormalEnabledDeepSleepDisabled, | ||
| 36 | }; | ||
| 37 | const K512_CONFIG: Config = Config { | ||
| 38 | sel: ClockOutSel::ClkIn, | ||
| 39 | div: const { Div4::from_divisor(16).unwrap() }, | ||
| 40 | level: PoweredClock::NormalEnabledDeepSleepDisabled, | ||
| 41 | }; | ||
| 22 | 42 | ||
| 43 | let configs = [ | ||
| 44 | ("16K -> /1 = 16K", K16_CONFIG), | ||
| 45 | ("12M -> /3 = 4M", M4_CONFIG), | ||
| 46 | ("8M -> /16 = 512K", K512_CONFIG), | ||
| 47 | ]; | ||
| 48 | |||
| 49 | loop { | ||
| 23 | defmt::info!("Set High..."); | 50 | defmt::info!("Set High..."); |
| 24 | output.set_high(); | 51 | let mut output = Output::new(pin.reborrow(), Level::High, DriveStrength::Normal, SlewRate::Slow); |
| 25 | Timer::after_millis(400).await; | 52 | Timer::after_millis(250).await; |
| 26 | 53 | ||
| 27 | defmt::info!("Set Low..."); | 54 | defmt::info!("Set Low..."); |
| 28 | output.set_low(); | 55 | output.set_low(); |
| 29 | Timer::after_millis(500).await; | 56 | Timer::after_millis(750).await; |
| 30 | 57 | ||
| 31 | defmt::info!("16k..."); | 58 | for (name, conf) in configs.iter() { |
| 32 | // Run Clock Out with the 16K clock | 59 | defmt::info!("Running {=str}", name); |
| 33 | let _clock_out = ClockOut::new( | ||
| 34 | clkout.reborrow(), | ||
| 35 | pin.reborrow(), | ||
| 36 | Config { | ||
| 37 | sel: ClockOutSel::Clk16K, | ||
| 38 | div: Div4::no_div(), | ||
| 39 | level: PoweredClock::NormalEnabledDeepSleepDisabled, | ||
| 40 | }, | ||
| 41 | ) | ||
| 42 | .unwrap(); | ||
| 43 | 60 | ||
| 44 | Timer::after_millis(3000).await; | 61 | let _clock_out = ClockOut::new(clkout.reborrow(), pin.reborrow(), *conf).unwrap(); |
| 45 | |||
| 46 | defmt::info!("Set Low..."); | ||
| 47 | drop(_clock_out); | ||
| 48 | 62 | ||
| 49 | let _output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow); | 63 | Timer::after_millis(3000).await; |
| 50 | Timer::after_millis(500).await; | ||
| 51 | 64 | ||
| 52 | // Run Clock Out with the 12M clock, divided by 3 | 65 | defmt::info!("Set Low..."); |
| 53 | defmt::info!("4M..."); | 66 | drop(_clock_out); |
| 54 | let _clock_out = ClockOut::new( | ||
| 55 | clkout.reborrow(), | ||
| 56 | pin.reborrow(), | ||
| 57 | Config { | ||
| 58 | sel: ClockOutSel::Fro12M, | ||
| 59 | div: const { Div4::from_divisor(3).unwrap() }, | ||
| 60 | level: PoweredClock::NormalEnabledDeepSleepDisabled, | ||
| 61 | }, | ||
| 62 | ) | ||
| 63 | .unwrap(); | ||
| 64 | 67 | ||
| 65 | // Let it run for 3 seconds... | 68 | let _output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow); |
| 66 | Timer::after_millis(3000).await; | 69 | Timer::after_millis(500).await; |
| 70 | } | ||
| 67 | } | 71 | } |
| 68 | } | 72 | } |
