From 20f85fb26e2b08b2e6114f31ea05d3da759432eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20de=20Giessen?= Date: Tue, 12 Dec 2023 15:59:46 +0100 Subject: [PATCH] esp32/machine_uart: Always configure timeout_char setting in init(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the `timeout_char` parameter is not given, we should still configure the UART to ensure the UART is always initialized consistently. So the default of 0 gets applied correctly, or if, for example, the baudrate was changed the char timeout isn't still based on the old baudrate causing weird behaviour, etc. Signed-off-by: Daniƫl van de Giessen --- ports/esp32/machine_uart.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ports/esp32/machine_uart.c b/ports/esp32/machine_uart.c index b5c5c016a..50c9a19be 100644 --- a/ports/esp32/machine_uart.c +++ b/ports/esp32/machine_uart.c @@ -277,17 +277,17 @@ static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, } // set timeout_char - // make sure it is at least as long as a whole character (12 bits here) if (args[ARG_timeout_char].u_int != -1) { self->timeout_char = args[ARG_timeout_char].u_int; - uint32_t char_time_ms = 12000 / baudrate + 1; - uint32_t rx_timeout = self->timeout_char / char_time_ms; - if (rx_timeout < 1) { - check_esp_err(uart_set_rx_full_threshold(self->uart_num, 1)); - check_esp_err(uart_set_rx_timeout(self->uart_num, 1)); - } else { - check_esp_err(uart_set_rx_timeout(self->uart_num, rx_timeout)); - } + } + // make sure it is at least as long as a whole character (12 bits here) + uint32_t char_time_ms = 12000 / baudrate + 1; + uint32_t rx_timeout = self->timeout_char / char_time_ms; + if (rx_timeout < 1) { + check_esp_err(uart_set_rx_full_threshold(self->uart_num, 1)); + check_esp_err(uart_set_rx_timeout(self->uart_num, 1)); + } else { + check_esp_err(uart_set_rx_timeout(self->uart_num, rx_timeout)); } // set line inversion