From 6378343bb3d0b6d109bd8cfd80cd3dfa2339ad8f Mon Sep 17 00:00:00 2001 From: KurtE Date: Tue, 3 May 2022 13:39:49 -0700 Subject: [PATCH] As I mentioned in issue #6332, there return of a read operation that times out with no data received is inconsistent: ``` Adafruit CircuitPython 7.3.0-beta.1-31-g73f6b4867-dirty on 2022-04-30; Adafruit Feather RP2040 with rp2040 >>> >>> import board, busio >>> print(board.UART().read(5)) None Adafruit CircuitPython 6.3.0 on 2021-06-01; FeatherS2 with ESP32S2 >>> import board,busio >>> print(board.UART().read(5)) None Adafruit CircuitPython 7.3.0-beta.1 on 2022-04-07; Adafruit Feather STM32F405 Express with STM32F405RG >>> import board, busio >>> print(board.UART().read(5)) None Adafruit CircuitPython 7.3.0-beta.1-31-g73f6b4867-dirty on 2022-04-28; Teensy 4.1 with IMXRT1062DVJ6A >>> import board, busio >>> print(board.UART().read(5)) b'' ``` Since I have a PR on this file anyway, I thought I would put in the change to make it consistent with the other 3 board types I tried. Can not say about any of the others. --- ports/mimxrt10xx/common-hal/busio/UART.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ports/mimxrt10xx/common-hal/busio/UART.c b/ports/mimxrt10xx/common-hal/busio/UART.c index 71de53f07f..57eaada7ef 100644 --- a/ports/mimxrt10xx/common-hal/busio/UART.c +++ b/ports/mimxrt10xx/common-hal/busio/UART.c @@ -428,6 +428,10 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t uint32_t recvd = 0; LPUART_TransferGetReceiveCount(self->uart, &self->handle, &recvd); LPUART_TransferAbortReceive(self->uart, &self->handle); + if (recvd == 0) { + *errcode = EAGAIN; + return MP_STREAM_ERROR; + } return recvd; }