Skip to content

Commit b5f7c51

Browse files
authored
uart: fix polling edge case in buffered read (#548)
This pull request makes a targeted adjustment to the `UartRx` asynchronous receive logic to more accurately determine the amount of available data in the buffer, particularly when handling a DMA transfer completion edge case. - **Buffer availability calculation fix:** * The logic for when `xfercount == 0x3FF` has been updated so that instead of skipping the case with `continue`, it now sets `available = 0`, ensuring that the available data is correctly reported as zero when the transfer has just finished. This prevents potential calculation errors in the number of bytes available to read.
1 parent 8ad0644 commit b5f7c51

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/uart.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -860,15 +860,14 @@ impl<'a> UartRx<'a, Async> {
860860
// But if it is 0x3FF and buffer is not granted, this can mean we just finished transfer after
861861
// our grant check - so we skip this case to avoid overflowing written calculation below
862862
if xfercount == 0x3FF {
863-
continue;
864-
}
865-
866-
// Channel not active (transfer finished) and value is 0x3FF - nothing to transfer
867-
let remaining = xfercount as usize + 1;
863+
available = 0;
864+
} else {
865+
let remaining = xfercount as usize + 1;
868866

869-
let written = half_size - remaining;
870-
if written > buffer_config.read_off {
871-
available = written - buffer_config.read_off;
867+
let written = half_size - remaining;
868+
if written > buffer_config.read_off {
869+
available = written - buffer_config.read_off;
870+
}
872871
}
873872
}
874873
// If DMA is writing to the other buffer, no new data is available

0 commit comments

Comments
 (0)