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