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

This commit is contained in:
Badr Bouslikhin 2025-03-07 18:00:52 +01:00 committed by Dario Nieuwenhuis
parent 668f5d42c3
commit b0ba604ba5
2 changed files with 10 additions and 1 deletions

View File

@ -711,7 +711,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

View File

@ -150,6 +150,16 @@ impl<'d> RingBufferedUartRx<'d> {
pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error> {
self.start_dma_or_check_errors()?;
// In half-duplex mode, we need to disable the Transmitter and enable the Receiver
// since they can't operate simultaneously on the shared line
let r = self.info.regs;
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, _)) => {}