Commit 5e692d04 authored by Angus Gratton's avatar Angus Gratton

esp32: Add MICROPY_HW_USB_CDC macro for native USB-CDC serial.

This fixes issue of ESP32-S3 switching its config over to USB serial/JTAG
instead of native USB.

The 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: default avatarAngus Gratton <angus@redyak.com.au>
parent 6ad6297e
......@@ -101,7 +101,7 @@ void mp_task(void *pvParameter) {
#endif
#if MICROPY_HW_ESP_USB_SERIAL_JTAG
usb_serial_jtag_init();
#elif CONFIG_USB_OTG_SUPPORTED
#elif MICROPY_HW_USB_CDC
usb_init();
#endif
#if MICROPY_HW_ENABLE_UART_REPL
......
......@@ -260,9 +260,18 @@ typedef long mp_off_t;
// board specifics
#define MICROPY_PY_SYS_PLATFORM "esp32"
// Enable stdio over native USB peripheral CDC via TinyUSB
#ifndef MICROPY_HW_USB_CDC
#define MICROPY_HW_USB_CDC (SOC_USB_OTG_SUPPORTED)
#endif
// Enable stdio over USB Serial/JTAG peripheral
#ifndef MICROPY_HW_ESP_USB_SERIAL_JTAG
#define MICROPY_HW_ESP_USB_SERIAL_JTAG (SOC_USB_SERIAL_JTAG_SUPPORTED)
#define MICROPY_HW_ESP_USB_SERIAL_JTAG (SOC_USB_SERIAL_JTAG_SUPPORTED && !MICROPY_HW_USB_CDC)
#endif
#if MICROPY_HW_USB_CDC && MICROPY_HW_ESP_USB_SERIAL_JTAG
#error "Invalid build config: Can't enable both native USB and USB Serial/JTAG peripheral"
#endif
// ESP32-S3 extended IO for 47 & 48
......
......@@ -146,7 +146,7 @@ mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) {
#if MICROPY_HW_ESP_USB_SERIAL_JTAG
usb_serial_jtag_tx_strn(str, len);
did_write = true;
#elif CONFIG_USB_OTG_SUPPORTED
#elif MICROPY_HW_USB_CDC
usb_tx_strn(str, len);
did_write = true;
#endif
......
......@@ -30,7 +30,7 @@
// Whether to enable the REPL on a UART.
#ifndef MICROPY_HW_ENABLE_UART_REPL
#define MICROPY_HW_ENABLE_UART_REPL (!CONFIG_USB_OTG_SUPPORTED && !CONFIG_ESP_CONSOLE_USB_CDC && !MICROPY_HW_ESP_USB_SERIAL_JTAG)
#define MICROPY_HW_ENABLE_UART_REPL (!MICROPY_HW_USB_CDC && !MICROPY_HW_ESP_USB_SERIAL_JTAG)
#endif
#if MICROPY_HW_ENABLE_UART_REPL
......
......@@ -28,7 +28,7 @@
#include "py/mphal.h"
#include "usb.h"
#if CONFIG_USB_OTG_SUPPORTED && !CONFIG_ESP_CONSOLE_USB_CDC && !MICROPY_HW_ESP_USB_SERIAL_JTAG
#if MICROPY_HW_USB_CDC
#include "esp_timer.h"
#ifndef NO_QSTR
......@@ -100,4 +100,4 @@ void usb_tx_strn(const char *str, size_t len) {
}
}
#endif // CONFIG_USB_OTG_SUPPORTED && !CONFIG_ESP_CONSOLE_USB_CDC && !MICROPY_HW_ESP_USB_SERIAL_JTAG
#endif // MICROPY_HW_USB_CDC
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment