aboutsummaryrefslogtreecommitdiff
path: root/examples/src/bin/ostimer_async.rs
diff options
context:
space:
mode:
authorJames Munns <[email protected]>2025-11-14 19:03:26 +0100
committerJames Munns <[email protected]>2025-11-14 19:03:26 +0100
commit0bae6aa5aaab5d0f3a3e7e1ec83a0cee909de115 (patch)
tree1740876a3af2f06bcc129b62e3a6e87f4472d5f3 /examples/src/bin/ostimer_async.rs
parent8cdccae3c6c4a805cf5003b1a859734c105d76e8 (diff)
parent77b2c602a60e41c7c977003a6d40367ac285930e (diff)
Merge remote-tracking branch 'origin/main' into james/impl-clocks
Diffstat (limited to 'examples/src/bin/ostimer_async.rs')
-rw-r--r--examples/src/bin/ostimer_async.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/examples/src/bin/ostimer_async.rs b/examples/src/bin/ostimer_async.rs
new file mode 100644
index 000000000..4e692a744
--- /dev/null
+++ b/examples/src/bin/ostimer_async.rs
@@ -0,0 +1,63 @@
1#![no_std]
2#![no_main]
3
4use embassy_executor::Spawner;
5use embassy_mcxa::bind_interrupts;
6use embassy_mcxa_examples::init_uart2;
7use embassy_time::{Duration, Timer};
8use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
9
10// Bind only OS_EVENT, and retain the symbol explicitly so it can’t be GC’ed.
11bind_interrupts!(struct Irqs {
12 OS_EVENT => hal::ostimer::time_driver::OsEventHandler;
13});
14
15#[used]
16#[no_mangle]
17static KEEP_OS_EVENT: unsafe extern "C" fn() = OS_EVENT;
18
19#[embassy_executor::main]
20async fn main(_spawner: Spawner) {
21 let p = hal::init(hal::config::Config::default());
22
23 // Create UART configuration
24 let config = hal::lpuart::Config {
25 baudrate_bps: 115_200,
26 enable_tx: true,
27 enable_rx: true,
28 ..Default::default()
29 };
30
31 // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX
32 unsafe {
33 init_uart2(hal::pac());
34 }
35 let mut uart = hal::lpuart::Lpuart::new_blocking(
36 p.LPUART2, // Peripheral
37 p.PIO2_2, // TX pin
38 p.PIO2_3, // RX pin
39 config,
40 )
41 .unwrap();
42 uart.blocking_write(b"boot\n").unwrap();
43
44 // Avoid mass NVIC writes here; DefaultHandler now safely returns.
45
46 // Initialize embassy-time global driver backed by OSTIMER0 (re-enables OS_EVENT with priority)
47 // The bind_interrupts! macro handles handler binding automatically
48
49 // Initialize OSTIMER with default 1MHz frequency
50 // Adjust this value to match your actual OSTIMER clock frequency
51 hal::ostimer::time_driver::init(hal::config::Config::default().time_interrupt_priority, 1_000_000);
52
53 // Removed force-pend; rely on real hardware match to trigger OS_EVENT.
54
55 // Log using defmt if enabled
56 defmt::info!("OSTIMER async example starting...");
57
58 loop {
59 defmt::info!("tick");
60 uart.write_str_blocking("tick\n");
61 Timer::after(Duration::from_millis(1000)).await;
62 }
63}