Skip to content

Commit

Permalink
fix: flipped rx and tx in Uart::new()
Browse files Browse the repository at this point in the history
  • Loading branch information
zpg6 committed Dec 29, 2024
1 parent 473780c commit 9d0c122
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
3 changes: 2 additions & 1 deletion examples/src/bin/uart_break_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use esp_backtrace as _;
use esp_hal::{
entry,
gpio::{Level, Output},
uart::{Config as UartConfig, DataBits, StopBits, Uart},
};

Expand All @@ -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");

Expand Down
7 changes: 5 additions & 2 deletions examples/src/bin/uart_break_detection_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
20 changes: 11 additions & 9 deletions examples/src/bin/uart_interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -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);
});
}

0 comments on commit 9d0c122

Please sign in to comment.