From 9d0c1226d9a6c54f94dcb1b04b631ff61ab6f94b Mon Sep 17 00:00:00 2001 From: Zach Grimaldi Date: Sun, 29 Dec 2024 18:22:23 -0500 Subject: [PATCH] fix: flipped rx and tx in `Uart::new()` --- examples/src/bin/uart_break_detection.rs | 3 ++- .../src/bin/uart_break_detection_async.rs | 7 +++++-- examples/src/bin/uart_interrupts.rs | 20 ++++++++++--------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/examples/src/bin/uart_break_detection.rs b/examples/src/bin/uart_break_detection.rs index cecdebb007..b2847d9c31 100644 --- a/examples/src/bin/uart_break_detection.rs +++ b/examples/src/bin/uart_break_detection.rs @@ -13,6 +13,7 @@ use esp_backtrace as _; use esp_hal::{ entry, + gpio::{Level, Output}, uart::{Config as UartConfig, DataBits, StopBits, Uart}, }; @@ -28,8 +29,8 @@ fn main() -> ! { let mut uart = Uart::new( peripherals.UART1, uart_config, - peripherals.GPIO17, // TX peripherals.GPIO16, // RX + peripherals.GPIO17, // TX ) .expect("Failed to initialize UART"); diff --git a/examples/src/bin/uart_break_detection_async.rs b/examples/src/bin/uart_break_detection_async.rs index 8f5ac5edde..81737dfada 100644 --- a/examples/src/bin/uart_break_detection_async.rs +++ b/examples/src/bin/uart_break_detection_async.rs @@ -12,7 +12,10 @@ use embassy_executor::Spawner; use esp_backtrace as _; -use esp_hal::uart::{Config as UartConfig, DataBits, StopBits, Uart}; +use esp_hal::{ + gpio::{Level, Output}, + uart::{Config as UartConfig, DataBits, StopBits, Uart}, +}; #[esp_hal_embassy::main] async fn main(_spawner: Spawner) { @@ -26,8 +29,8 @@ async fn main(_spawner: Spawner) { let mut uart = Uart::new( peripherals.UART1, uart_config, - peripherals.GPIO17, // TX peripherals.GPIO16, // RX + peripherals.GPIO17, // TX ) .expect("Failed to initialize UART") .into_async(); diff --git a/examples/src/bin/uart_interrupts.rs b/examples/src/bin/uart_interrupts.rs index f8e72b18c1..7207088eda 100644 --- a/examples/src/bin/uart_interrupts.rs +++ b/examples/src/bin/uart_interrupts.rs @@ -35,16 +35,16 @@ fn main() -> ! { let mut uart = Uart::new( peripherals.UART1, uart_config, - peripherals.GPIO17, // TX peripherals.GPIO16, // RX + peripherals.GPIO17, // TX ) .expect("Failed to initialize UART"); uart.set_interrupt_handler(handler); critical_section::with(|cs| { - uart.clear_interrupts(UartInterrupt::RxFifoFull | UartInterrupt::RxBreakDetected); - uart.listen(UartInterrupt::RxFifoFull | UartInterrupt::RxBreakDetected); + uart.clear_interrupts(UartInterrupt::RxBreakDetected | UartInterrupt::RxFifoFull); + uart.listen(UartInterrupt::RxBreakDetected | UartInterrupt::RxFifoFull); SERIAL.borrow_ref_mut(cs).replace(uart); }); @@ -58,14 +58,16 @@ fn handler() { let mut serial = SERIAL.borrow_ref_mut(cs); let serial = serial.as_mut().unwrap(); - if serial.interrupts().contains(UartInterrupt::RxFifoFull) { - esp_println::println!("Byte received: {:?}", serial.read_byte()); - } else if serial.interrupts().contains(UartInterrupt::RxBreakDetected) { + if serial.interrupts().contains(UartInterrupt::RxBreakDetected) { esp_println::println!("Break detected"); - } else { - esp_println::println!("Unknown source of interrupt"); + + // Clear the RX FIFO + while serial.read_byte().is_ok() {} + } + if serial.interrupts().contains(UartInterrupt::RxFifoFull) { + // esp_println::println!("Byte received: {:?}", serial.read_byte()); } - serial.clear_interrupts(UartInterrupt::RxFifoFull | UartInterrupt::RxBreakDetected); + serial.clear_interrupts(UartInterrupt::RxBreakDetected | UartInterrupt::RxFifoFull); }); }