Skip to content

Commit 1e3215f

Browse files
committed
Corrected number of serial bytes returned
1 parent d2febfa commit 1e3215f

File tree

1 file changed

+8
-1
lines changed
  • ports/mimxrt10xx/common-hal/busio

1 file changed

+8
-1
lines changed

ports/mimxrt10xx/common-hal/busio/UART.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,10 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
345345

346346
// if we timed out, stop the transfer
347347
if (self->rx_ongoing) {
348+
uint32_t recvd = 0;
349+
LPUART_TransferGetReceiveCount(self->uart, &self->handle, &recvd);
348350
LPUART_TransferAbortReceive(self->uart, &self->handle);
351+
return recvd;
349352
}
350353

351354
// No data left, we got it all
@@ -355,7 +358,11 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
355358

356359
// The only place we can reliably tell how many bytes have been received is from the current
357360
// wp in the handle (because the abort nukes rxDataSize, and reading it before abort is a race.)
358-
return self->handle.rxData - data;
361+
if (self->handle.rxData > data) {
362+
return self->handle.rxData - data;
363+
} else {
364+
return len;
365+
}
359366
}
360367

361368
// Write characters.

0 commit comments

Comments
 (0)