Skip to content

Commit

Permalink
Merge pull request #9579 from dhalbert/9.1.x-esp32-c6-uart-fix
Browse files Browse the repository at this point in the history
ESP32-C6: don't use LP (low-power) UART
  • Loading branch information
dhalbert authored Aug 29, 2024
2 parents 4e96417 + e2523ff commit e680f66
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 0 additions & 2 deletions ports/espressif/boards/seeed_xiao_esp32c6/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ IDF_TARGET = esp32c6
CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB

CIRCUITPY_ESP_USB_SERIAL_JTAG = 1
20 changes: 19 additions & 1 deletion ports/espressif/common-hal/busio/UART.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,22 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
self->timeout_ms = timeout * 1000;

self->uart_num = UART_NUM_MAX;
for (uart_port_t num = 0; num < UART_NUM_MAX; num++) {

// ESP32-C6 and ESP32-P4 both have a single LP (low power) UART, which is
// limited in what it can do and which pins it can use. Ignore it for now.
// Its UART number is higher than the numbers for the regular ("HP", high-power) UARTs.

// SOC_UART_LP_NUM is not defined for chips without an LP UART.
#if defined(SOC_UART_LP_NUM) && (SOC_UART_LP_NUM >= 1)
#define UART_LIMIT LP_UART_NUM_0
#else
#define UART_LIMIT UART_NUM_MAX
#endif

for (uart_port_t num = 0; num < UART_LIMIT; num++) {
if (!uart_is_driver_installed(num)) {
self->uart_num = num;
break;
}
}
if (self->uart_num == UART_NUM_MAX) {
Expand Down Expand Up @@ -224,6 +237,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
int rx_num = -1;
int rts_num = -1;
int cts_num = -1;

if (have_tx) {
claim_pin(tx);
self->tx_pin = tx;
Expand Down Expand Up @@ -254,9 +268,13 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
self->rts_pin = rs485_dir;
rts_num = rs485_dir->number;
}

if (uart_set_pin(self->uart_num, tx_num, rx_num, rts_num, cts_num) != ESP_OK) {
// Uninstall driver and clean up.
common_hal_busio_uart_deinit(self);
raise_ValueError_invalid_pins();
}

if (have_rx) {
// On ESP32-C3 and ESP32-S3 (at least), a junk byte with zero or more consecutive 1's can be
// generated, even if the pin is pulled high (normal UART resting state) to begin with.
Expand Down

0 comments on commit e680f66

Please sign in to comment.