Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32-C6: don't use LP (low-power) UART #9579

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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