Skip to content
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

fix(stm32): handle half-duplex in ringbuffered read #3952

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 0 additions & 1 deletion embassy-stm32/src/usart/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,6 @@ impl<'d> UartRx<'d, Async> {

// make sure USART state is restored to neutral state when this future is dropped
let on_drop = OnDrop::new(move || {
// defmt::trace!("Clear all USART interrupts and DMA Read Request");
// clear all interrupts and DMA Rx Request
r.cr1().modify(|w| {
// disable RXNE interrupt
Expand Down
9 changes: 9 additions & 0 deletions embassy-stm32/src/usart/ringbuffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ impl<'d> RingBufferedUartRx<'d> {
check_for_errors(sr)?;
}

// In half-duplex mode, we need to disable the Transmitter and enable the Receiver
// since they can't operate simultaneously on the shared line
if r.cr3().read().hdsel() && r.cr1().read().te() {
r.cr1().modify(|reg| {
reg.set_re(true);
reg.set_te(false);
});
}

loop {
match self.ring_buf.read(buf) {
Ok((0, _)) => {}
Expand Down