From 18c12e782244c7dcdc95c0b09b9ddd365e9560f3 Mon Sep 17 00:00:00 2001 From: arturo182 Date: Thu, 26 Mar 2020 00:15:48 +0100 Subject: [PATCH] mimxrt10xx: Return proper UART read length when everything was read --- ports/mimxrt10xx/common-hal/busio/UART.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ports/mimxrt10xx/common-hal/busio/UART.c b/ports/mimxrt10xx/common-hal/busio/UART.c index b34b948b29..4633507d8b 100644 --- a/ports/mimxrt10xx/common-hal/busio/UART.c +++ b/ports/mimxrt10xx/common-hal/busio/UART.c @@ -270,9 +270,14 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t LPUART_TransferAbortReceive(self->uart, &self->handle); } + // No data left, we got it all + if (self->handle.rxData == NULL) { + return len; + } + // The only place we can reliably tell how many bytes have been received is from the current // wp in the handle (because the abort nukes rxDataSize, and reading it before abort is a race.) - return self->handle.rxData-data; + return self->handle.rxData - data; } // Write characters.