From c50f9cbb4244a4aef2a77098939af3b7eb7410b3 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sat, 16 Aug 2025 21:26:06 +0200 Subject: [PATCH] esp32/machine_uart: Handle properly the timeout_char argument. Before, it was ignored. Tested with ESP32, ESP32S3, ESP32C6. Signed-off-by: robert-hh --- ports/esp32/machine_uart.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/ports/esp32/machine_uart.c b/ports/esp32/machine_uart.c index 55987c9b62..36b5bcb0ff 100644 --- a/ports/esp32/machine_uart.c +++ b/ports/esp32/machine_uart.c @@ -668,19 +668,18 @@ static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t return 0; } - TickType_t time_to_wait; - if (self->timeout == 0) { - time_to_wait = 0; - } else { - time_to_wait = pdMS_TO_TICKS(self->timeout); - } + TickType_t time_to_wait = self->timeout > 0 ? pdMS_TO_TICKS(self->timeout) : 0; - bool release_gil = time_to_wait > 0; + bool release_gil = (self->timeout + self->timeout_char) > 0; if (release_gil) { MP_THREAD_GIL_EXIT(); } - int bytes_read = uart_read_bytes(self->uart_num, buf_in, size, time_to_wait); + int bytes_read = uart_read_bytes(self->uart_num, buf_in, 1, time_to_wait); + if (size > 1 && bytes_read != 0) { + time_to_wait = self->timeout_char > 0 ? pdMS_TO_TICKS(self->timeout_char) : 0; + bytes_read += uart_read_bytes(self->uart_num, buf_in + 1, size - 1, time_to_wait); + } if (release_gil) { MP_THREAD_GIL_ENTER();