summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/esp32/machine_uart.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/ports/esp32/machine_uart.c b/ports/esp32/machine_uart.c
index c0eedb80b..49ce78b1b 100644
--- a/ports/esp32/machine_uart.c
+++ b/ports/esp32/machine_uart.c
@@ -267,12 +267,18 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
}
// set timeout_char
- // make sure it is at least as long as a whole character (13 bits to be safe)
+ // 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 min_timeout_char = 13000 / baudrate + 1;
- if (self->timeout_char < min_timeout_char) {
- self->timeout_char = min_timeout_char;
+ uint32_t char_time_ms = 12000 / baudrate + 1;
+ uint32_t rx_timeout = self->timeout_char / char_time_ms;
+ if (rx_timeout < 1) {
+ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0)
+ uart_set_rx_full_threshold(self->uart_num, 1);
+ #endif
+ uart_set_rx_timeout(self->uart_num, 1);
+ } else {
+ uart_set_rx_timeout(self->uart_num, rx_timeout);
}
}