Skip to content

Clear the UART's TX/RX FIFOs at initialization #1344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed core1 startup using the wrong stack on the esp32 and esp32s3 (#1286).
- ESP32: Apply fix for Errata 3.6 in all the places necessary. (#1315)
- ESP32 & ESP32-S2: Fix I²C frequency (#1306)
- UART's TX/RX FIFOs are now cleared during initialization (#1344)

### Changed

Expand Down
29 changes: 29 additions & 0 deletions esp-hal/src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,11 @@ where
}
}

// Reset Tx/Rx FIFOs
serial.txfifo_reset();
serial.rxfifo_reset();
crate::rom::ets_delay_us(15);

serial
}

Expand Down Expand Up @@ -1021,6 +1026,30 @@ where
#[cfg(not(any(esp32c3, esp32c6, esp32h2, esp32s3)))]
#[inline(always)]
fn sync_regs(&mut self) {}

fn rxfifo_reset(&mut self) {
T::register_block()
.conf0()
.modify(|_, w| w.rxfifo_rst().set_bit());
self.sync_regs();

T::register_block()
.conf0()
.modify(|_, w| w.rxfifo_rst().clear_bit());
self.sync_regs();
}

fn txfifo_reset(&mut self) {
T::register_block()
.conf0()
.modify(|_, w| w.txfifo_rst().set_bit());
self.sync_regs();

T::register_block()
.conf0()
.modify(|_, w| w.txfifo_rst().clear_bit());
self.sync_regs();
}
}

/// UART peripheral instance
Expand Down