aboutsummaryrefslogtreecommitdiff
path: root/examples/src/bin/ostimer_async.rs
diff options
context:
space:
mode:
authorJames Munns <[email protected]>2025-11-18 14:19:09 +0100
committerGitHub <[email protected]>2025-11-18 14:19:09 +0100
commit5b1149a52dbec9e3bdd10dc341dc0751ab4798a6 (patch)
tree3ff7098471cf660a54a707464a0e2feb2080b09e /examples/src/bin/ostimer_async.rs
parent62e297c130ac26afe4d7d5752bb79709bd370e39 (diff)
parentc8942aec2478ff077b55da0e86801f8a6a88a7de (diff)
Merge pull request #11 from jamesmunns/james/impl-clocks
Implement initial `clock` driver. This PR introduces an initial two-phase clock driver system: 1. The first stage is responsible for initializing the core/system clocks at the time of `embassy_mcxa::init()` 2. The second stage is done on creation of peripherals This work is limited to currently used clocks and peripherals, but has room for expansion for later peripherals. This model is based on the preliminary refactoring performed for the `embassy-imxrt` crate.
Diffstat (limited to 'examples/src/bin/ostimer_async.rs')
-rw-r--r--examples/src/bin/ostimer_async.rs30
1 files changed, 21 insertions, 9 deletions
diff --git a/examples/src/bin/ostimer_async.rs b/examples/src/bin/ostimer_async.rs
index 34862b61f..881f09374 100644
--- a/examples/src/bin/ostimer_async.rs
+++ b/examples/src/bin/ostimer_async.rs
@@ -3,9 +3,9 @@
3 3
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_mcxa::bind_interrupts; 5use embassy_mcxa::bind_interrupts;
6use embassy_mcxa_examples::{init_ostimer0, init_uart2}; 6use embassy_mcxa_examples::init_uart2_pins;
7use embassy_time::{Duration, Timer}; 7use embassy_time::{Duration, Timer};
8use hal::uart; 8use hal::lpuart::{Config, Lpuart};
9use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; 9use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
10 10
11// Bind only OS_EVENT, and retain the symbol explicitly so it can’t be GC’ed. 11// Bind only OS_EVENT, and retain the symbol explicitly so it can’t be GC’ed.
@@ -19,16 +19,28 @@ static KEEP_OS_EVENT: unsafe extern "C" fn() = OS_EVENT;
19 19
20#[embassy_executor::main] 20#[embassy_executor::main]
21async fn main(_spawner: Spawner) { 21async fn main(_spawner: Spawner) {
22 let _p = hal::init(hal::config::Config::default()); 22 let p = hal::init(hal::config::Config::default());
23 23
24 // Enable/clock OSTIMER0 and UART2 before touching their registers 24 // Create UART configuration
25 let config = Config {
26 baudrate_bps: 115_200,
27 enable_tx: true,
28 enable_rx: true,
29 ..Default::default()
30 };
31
32 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX
25 unsafe { 33 unsafe {
26 init_ostimer0(hal::pac()); 34 init_uart2_pins(hal::pac());
27 init_uart2(hal::pac());
28 } 35 }
29 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) }; 36 let mut uart = Lpuart::new_blocking(
30 let uart = uart::Uart::<uart::Lpuart2>::new(_p.LPUART2, uart::Config::new(src)); 37 p.LPUART2, // Peripheral
31 uart.write_str_blocking("boot\n"); 38 p.PIO2_2, // TX pin
39 p.PIO2_3, // RX pin
40 config,
41 )
42 .unwrap();
43 uart.blocking_write(b"boot\n").unwrap();
32 44
33 // Avoid mass NVIC writes here; DefaultHandler now safely returns. 45 // Avoid mass NVIC writes here; DefaultHandler now safely returns.
34 46