Skip to content

Commit e2523ff

Browse files
committed
ESP32-C6: don't use LP UART; clean up if constructor failure
1 parent 0ba89fc commit e2523ff

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

ports/espressif/boards/seeed_xiao_esp32c6/mpconfigboard.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,3 @@ IDF_TARGET = esp32c6
66
CIRCUITPY_ESP_FLASH_MODE = qio
77
CIRCUITPY_ESP_FLASH_FREQ = 80m
88
CIRCUITPY_ESP_FLASH_SIZE = 4MB
9-
10-
CIRCUITPY_ESP_USB_SERIAL_JTAG = 1

ports/espressif/common-hal/busio/UART.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,22 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
106106
self->timeout_ms = timeout * 1000;
107107

108108
self->uart_num = UART_NUM_MAX;
109-
for (uart_port_t num = 0; num < UART_NUM_MAX; num++) {
109+
110+
// ESP32-C6 and ESP32-P4 both have a single LP (low power) UART, which is
111+
// limited in what it can do and which pins it can use. Ignore it for now.
112+
// Its UART number is higher than the numbers for the regular ("HP", high-power) UARTs.
113+
114+
// SOC_UART_LP_NUM is not defined for chips without an LP UART.
115+
#if defined(SOC_UART_LP_NUM) && (SOC_UART_LP_NUM >= 1)
116+
#define UART_LIMIT LP_UART_NUM_0
117+
#else
118+
#define UART_LIMIT UART_NUM_MAX
119+
#endif
120+
121+
for (uart_port_t num = 0; num < UART_LIMIT; num++) {
110122
if (!uart_is_driver_installed(num)) {
111123
self->uart_num = num;
124+
break;
112125
}
113126
}
114127
if (self->uart_num == UART_NUM_MAX) {
@@ -224,6 +237,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
224237
int rx_num = -1;
225238
int rts_num = -1;
226239
int cts_num = -1;
240+
227241
if (have_tx) {
228242
claim_pin(tx);
229243
self->tx_pin = tx;
@@ -254,9 +268,13 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
254268
self->rts_pin = rs485_dir;
255269
rts_num = rs485_dir->number;
256270
}
271+
257272
if (uart_set_pin(self->uart_num, tx_num, rx_num, rts_num, cts_num) != ESP_OK) {
273+
// Uninstall driver and clean up.
274+
common_hal_busio_uart_deinit(self);
258275
raise_ValueError_invalid_pins();
259276
}
277+
260278
if (have_rx) {
261279
// On ESP32-C3 and ESP32-S3 (at least), a junk byte with zero or more consecutive 1's can be
262280
// generated, even if the pin is pulled high (normal UART resting state) to begin with.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy