10000 esp32: Add a config option for native USB-CDC serial. · micropython/micropython@be77a35 · GitHub
[go: up one dir, main page]

Skip to content

Commit be77a35

Browse files
committed
esp32: Add a config option for native USB-CDC serial.
This fixes issue of ESP32-S3 switching its config over to USB serial/JTAG instead of native USB. However the existing logic was hard to follow, adding this config macro makes it easier to see which USB is in use and to have board definitions that enable/disable different USB levels. This commit also drops (nominal) support for manually setting CONFIG_ESP_CONSOLE_USB_CDC in sdkconfig. No included board configs use this and it didn't seem to work (if secondary console was set to the default USB Serial/JTAG then there is no serial output on any port, and if secondary console was set to None then linking fails.) Can be re-added if there's a use case for it. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent f0d89cc commit be77a35

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

ports/esp32/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void mp_task(void *pvParameter) {
101101
#endif
102102
#if MICROPY_HW_ESP_USB_SERIAL_JTAG
103103
usb_serial_jtag_init();
104-
#elif CONFIG_USB_OTG_SUPPORTED
104+
#elif MICROPY_HW_USB_CDC
105105
usb_init();
106106
#endif
107107
#if MICROPY_HW_ENABLE_UART_REPL

ports/esp32/mpconfigport.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,20 @@ typedef long mp_off_t;
260260
// board specifics
261261
#define MICROPY_PY_SYS_PLATFORM "esp32"
262262

263+
// Enable stdio over native USB peripheral CDC via TinyUSB
264+
#ifndef MICROPY_HW_USB_CDC
265+
#define MICROPY_HW_USB_CDC (SOC_USB_OTG_SUPPORTED)
266+
#endif
267+
263268
// Enable stdio over USB Serial/JTAG peripheral
264269
#ifndef MICROPY_HW_ESP_USB_SERIAL_JTAG
265-
#define MICROPY_HW_ESP_USB_SERIAL_JTAG (SOC_USB_SERIAL_JTAG_SUPPORTED)
270+
#define MICROPY_HW_ESP_USB_SERIAL_JTAG (SOC_USB_SERIAL_JTAG_SUPPORTED && !MICROPY_HW_USB_CDC)
266271
#endif // MICROPY_HW_ESP_USB_SERIAL_JTAG
267272

273+
#if MICROPY_HW_USB_CDC && MICROPY_HW_ESP_USB_SERIAL_JTAG
274+
#error "Invalid build config: Can't enable both native USB and USB Serial/JTAG peripheral"
275+
#endif
276+
268277
// ESP32-S3 extended IO for 47 & 48
269278
#ifndef MICROPY_HW_ESP32S3_EXTENDED_IO
270279
#define MICROPY_HW_ESP32S3_EXTENDED_IO (1)

ports/esp32/mphalport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) {
146146
#if MICROPY_HW_ESP_USB_SERIAL_JTAG
147147
usb_serial_jtag_tx_strn(str, len);
148148
did_write = true;
149-
#elif CONFIG_USB_OTG_SUPPORTED
149+
#elif MICROPY_HW_USB_CDC
150150
usb_tx_strn(str, len);
151151
did_write = true;
152152
#endif

ports/esp32/uart.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
// Whether to enable the REPL on a UART.
3232
#ifndef MICROPY_HW_ENABLE_UART_REPL
33-
#define MICROPY_HW_ENABLE_UART_REPL (!CONFIG_USB_OTG_SUPPORTED && !CONFIG_ESP_CONSOLE_USB_CDC && !MICROPY_HW_ESP_USB_SERIAL_JTAG)
33+
#define MICROPY_HW_ENABLE_UART_REPL (!MICROPY_HW_USB_CDC && !MICROPY_HW_ESP_USB_SERIAL_JTAG)
3434
#endif
3535

3636
#if MICROPY_HW_ENABLE_UART_REPL

ports/esp32/usb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "py/mphal.h"
2929
#include "usb.h"
3030

31-
#if CONFIG_USB_OTG_SUPPORTED && !CONFIG_ESP_CONSOLE_USB_CDC && !MICROPY_HW_ESP_USB_SERIAL_JTAG
31+
#if MICROPY_HW_USB_CDC
3232

3333
#include "esp_timer.h"
3434
#ifndef NO_QSTR
@@ -100,4 +100,4 @@ void usb_tx_strn(const char *str, size_t len) {
100100
}
101101
}
102102

103-
#endif // CONFIG_USB_OTG_SUPPORTED && !CONFIG_ESP_CONSOLE_USB_CDC && !MICROPY_HW_ESP_USB_SERIAL_JTAG
103+
#endif // MICROPY_HW_USB_CDC

0 commit comments

Comments
 (0)
0