Skip to content

Commit

Permalink
esp32/machine_uart: Always configure timeout_char setting in init().
Browse files Browse the repository at this point in the history
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 <daniel@dvdgiessen.nl>
  • Loading branch information
DvdGiessen authored and dpgeorge committed Mar 8, 2024
1 parent cdfc6c1 commit 20f85fb
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions ports/esp32/machine_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 20f85fb

Please sign in to comment.