aboutsummaryrefslogtreecommitdiff
path: root/examples/mcxa/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'examples/mcxa/src/bin')
-rw-r--r--examples/mcxa/src/bin/clkout.rs104
-rw-r--r--examples/mcxa/src/bin/reset-reason.rs4
2 files changed, 67 insertions, 41 deletions
diff --git a/examples/mcxa/src/bin/clkout.rs b/examples/mcxa/src/bin/clkout.rs
index 1e52912d3..c0e8c330d 100644
--- a/examples/mcxa/src/bin/clkout.rs
+++ b/examples/mcxa/src/bin/clkout.rs
@@ -4,6 +4,7 @@
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_mcxa::clkout::{ClockOut, ClockOutSel, Config, Div4}; 5use embassy_mcxa::clkout::{ClockOut, ClockOutSel, Config, Div4};
6use embassy_mcxa::clocks::PoweredClock; 6use embassy_mcxa::clocks::PoweredClock;
7use embassy_mcxa::clocks::config::{SoscConfig, SoscMode, SpllConfig, SpllMode, SpllSource};
7use embassy_mcxa::gpio::{DriveStrength, Level, Output, SlewRate}; 8use embassy_mcxa::gpio::{DriveStrength, Level, Output, SlewRate};
8use embassy_time::Timer; 9use embassy_time::Timer;
9use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; 10use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
@@ -11,58 +12,81 @@ 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]
13async fn main(_spawner: Spawner) { 14async 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 cfg.clock_cfg.spll = Some(SpllConfig {
22 source: SpllSource::Sirc,
23 // 12MHz
24 // 12 x 32 => 384MHz
25 // 384 / (16 x 2) => 12.0MHz
26 mode: SpllMode::Mode1b {
27 m_mult: 32,
28 p_div: 16,
29 bypass_p2_div: false,
30 },
31 power: PoweredClock::NormalEnabledDeepSleepDisabled,
32 pll1_clk_div: None,
33 });
34
35 let p = hal::init(cfg);
36
15 let mut pin = p.P4_2; 37 let mut pin = p.P4_2;
16 let mut clkout = p.CLKOUT; 38 let mut clkout = p.CLKOUT;
17 39
18 loop { 40 const K16_CONFIG: Config = Config {
19 defmt::info!("Set Low..."); 41 sel: ClockOutSel::Clk16K,
20 let mut output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow); 42 div: Div4::no_div(),
21 Timer::after_millis(500).await; 43 level: PoweredClock::NormalEnabledDeepSleepDisabled,
44 };
45 const M4_CONFIG: Config = Config {
46 sel: ClockOutSel::Fro12M,
47 div: const { Div4::from_divisor(3).unwrap() },
48 level: PoweredClock::NormalEnabledDeepSleepDisabled,
49 };
50 const K512_CONFIG: Config = Config {
51 sel: ClockOutSel::ClkIn,
52 div: const { Div4::from_divisor(16).unwrap() },
53 level: PoweredClock::NormalEnabledDeepSleepDisabled,
54 };
55 const M1_CONFIG: Config = Config {
56 sel: ClockOutSel::Pll1Clk,
57 div: const { Div4::from_divisor(12).unwrap() },
58 level: PoweredClock::NormalEnabledDeepSleepDisabled,
59 };
22 60
61 #[rustfmt::skip]
62 let configs = [
63 ("16K -> /1 = 16K", K16_CONFIG),
64 ("12M -> /3 = 4M", M4_CONFIG),
65 ("8M -> /16 = 512K", K512_CONFIG),
66 ("12M-> /12 = 1M", M1_CONFIG),
67 ];
68
69 loop {
23 defmt::info!("Set High..."); 70 defmt::info!("Set High...");
24 output.set_high(); 71 let mut output = Output::new(pin.reborrow(), Level::High, DriveStrength::Normal, SlewRate::Slow);
25 Timer::after_millis(400).await; 72 Timer::after_millis(250).await;
26 73
27 defmt::info!("Set Low..."); 74 defmt::info!("Set Low...");
28 output.set_low(); 75 output.set_low();
29 Timer::after_millis(500).await; 76 Timer::after_millis(750).await;
30 77
31 defmt::info!("16k..."); 78 for (name, conf) in configs.iter() {
32 // Run Clock Out with the 16K clock 79 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 80
44 Timer::after_millis(3000).await; 81 let _clock_out = ClockOut::new(clkout.reborrow(), pin.reborrow(), *conf).unwrap();
45
46 defmt::info!("Set Low...");
47 drop(_clock_out);
48 82
49 let _output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow); 83 Timer::after_millis(3000).await;
50 Timer::after_millis(500).await;
51 84
52 // Run Clock Out with the 12M clock, divided by 3 85 defmt::info!("Set Low...");
53 defmt::info!("4M..."); 86 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 87
65 // Let it run for 3 seconds... 88 let _output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow);
66 Timer::after_millis(3000).await; 89 Timer::after_millis(500).await;
90 }
67 } 91 }
68} 92}
diff --git a/examples/mcxa/src/bin/reset-reason.rs b/examples/mcxa/src/bin/reset-reason.rs
index c244fbe04..2d48a92b1 100644
--- a/examples/mcxa/src/bin/reset-reason.rs
+++ b/examples/mcxa/src/bin/reset-reason.rs
@@ -11,5 +11,7 @@ async fn main(_spawner: Spawner) {
11 let config = Config::default(); 11 let config = Config::default();
12 let _p = hal::init(config); 12 let _p = hal::init(config);
13 13
14 defmt::info!("Reset Reason: '{}'", reset_reason()); 14 for reason in reset_reason().into_iter() {
15 defmt::info!("Reset Reason: '{}'", reason);
16 }
15} 17}