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

Skip to content

Commit 50aa3bb

Browse files
committed
esp32: Add a config option for native USB-CDC serial.
This turned out to be necessary due to the previous commit, to avoid 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 bbc5d34 commit 50aa3bb

File tree

10BC0

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
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: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,24 @@ typedef long mp_off_t;
259259
// board specifics
260260
#define MICROPY_PY_SYS_PLATFORM "esp32"
261261

262+
// Enable native USB peripheral CDC via TinyUSB
263+
#ifndef MICROPY_HW_USB_CDC
264+
#define MICROPY_HW_USB_CDC (CONFIG_USB_OTG_SUPPORTED)
265+
#endif
266+
262267
// Enable serial over USB/JTAG serial peripheral
263268
#ifndef MICROPY_HW_ESP_USB_SERIAL_JTAG
264-
#define MICROPY_HW_ESP_USB_SERIAL_JTAG (CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED || ( \
265-
ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0) && ( \
266-
CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG || \
267-
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG)))
269+
#define MICROPY_HW_ESP_USB_SERIAL_JTAG (!MICROPY_HW_USB_CDC && \
270+
(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED || ( \
271+
ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0) && ( \
272+
CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG || \
273+
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG))))
268274
#endif // MICROPY_HW_ESP_USB_SERIAL_JTAG
269275

276+
#if MICROPY_HW_USB_CDC && MICROPY_HW_ESP_USB_SERIAL_JTAG
277+
#error "Invalid build config: Can't enable both native USB and USB Serial/JTAG peripheral"
278+
#endif
279+
270280
// ESP32-S3 extended IO for 47 & 48
271281
#ifndef MICROPY_HW_ESP32S3_EXTENDED_IO
272282
#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