aboutsummaryrefslogtreecommitdiff
path: root/examples/src/bin/uart_interrupt.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/uart_interrupt.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/uart_interrupt.rs')
-rw-r--r--examples/src/bin/uart_interrupt.rs66
1 files changed, 0 insertions, 66 deletions
diff --git a/examples/src/bin/uart_interrupt.rs b/examples/src/bin/uart_interrupt.rs
deleted file mode 100644
index 100588727..000000000
--- a/examples/src/bin/uart_interrupt.rs
+++ /dev/null
@@ -1,66 +0,0 @@
1#![no_std]
2#![no_main]
3
4use embassy_executor::Spawner;
5use embassy_mcxa::bind_interrupts;
6use embassy_mcxa_examples::init_uart2;
7use hal::interrupt::typelevel::Handler;
8use hal::uart;
9use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
10
11// Bind LPUART2 interrupt to our handler
12bind_interrupts!(struct Irqs {
13 LPUART2 => hal::uart::UartInterruptHandler;
14});
15
16#[used]
17#[no_mangle]
18static KEEP_LPUART2: unsafe extern "C" fn() = LPUART2;
19
20// Wrapper function for the interrupt handler
21unsafe extern "C" fn lpuart2_handler() {
22 hal::uart::UartInterruptHandler::on_interrupt();
23}
24
25#[embassy_executor::main]
26async fn main(_spawner: Spawner) {
27 let _p = hal::init(hal::config::Config::default());
28
29 // Enable/clock UART2 before touching its registers
30 unsafe {
31 init_uart2(hal::pac());
32 }
33 let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) };
34 let uart = uart::Uart::<uart::Lpuart2>::new(_p.LPUART2, uart::Config::new(src));
35
36 // Configure LPUART2 interrupt for UART operation BEFORE any UART usage
37 hal::interrupt::LPUART2.configure_for_uart(hal::interrupt::Priority::from(3));
38
39 // Manually install the interrupt handler and enable RX IRQs in the peripheral
40 unsafe {
41 hal::interrupt::LPUART2.install_handler(lpuart2_handler);
42 // Enable RX interrupts so the handler actually fires on incoming bytes
43 uart.enable_rx_interrupts();
44 }
45
46 // Print welcome message
47 uart.write_str_blocking("UART interrupt echo demo starting...\r\n");
48 uart.write_str_blocking("Type characters to echo them back.\r\n");
49
50 // Log using defmt if enabled
51 defmt::info!("UART interrupt echo demo starting...");
52
53 loop {
54 // Check if we have received any data
55 if uart.rx_data_available() {
56 if let Some(byte) = uart.try_read_byte() {
57 // Echo it back
58 uart.write_byte(byte);
59 uart.write_str_blocking(" (received)\r\n");
60 }
61 } else {
62 // No data available, wait a bit before checking again
63 cortex_m::asm::delay(12_000_000); // ~1 second at 12MHz
64 }
65 }
66}