From 6ad6297ef7524ad74ad7618e666dd35fc5e92cfe Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 27 Aug 2024 15:49:43 +1000 Subject: [PATCH] esp32: Fix ESP32-C3 USB serial/jtag peripheral pre-IDF 5.1. Regression in 0a11832cd in IDF 5.0.x where macro CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED is not defined. With this patch, ESP32-S3 still USB Serial/JTAG incorrectly (now on all ESP-IDF versions). Closes #15701 This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- ports/esp32/machine_pin.c | 2 +- ports/esp32/machine_pin.h | 2 +- ports/esp32/main.c | 2 +- ports/esp32/mpconfigport.h | 5 +++++ ports/esp32/mphalport.c | 6 +++--- ports/esp32/uart.h | 2 +- ports/esp32/usb.c | 4 ++-- ports/esp32/usb_serial_jtag.c | 4 ++-- 8 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ports/esp32/machine_pin.c b/ports/esp32/machine_pin.c index 17c01fc7b38e..149715cf6013 100644 --- a/ports/esp32/machine_pin.c +++ b/ports/esp32/machine_pin.c @@ -159,7 +159,7 @@ static mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_ } } - #if CONFIG_IDF_TARGET_ESP32C3 && CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED + #if CONFIG_IDF_TARGET_ESP32C3 && MICROPY_HW_ESP_USB_SERIAL_JTAG if (index == 18 || index == 19) { CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE); } diff --git a/ports/esp32/machine_pin.h b/ports/esp32/machine_pin.h index b46998725326..1d64e7f413e4 100644 --- a/ports/esp32/machine_pin.h +++ b/ports/esp32/machine_pin.h @@ -87,7 +87,7 @@ #define MICROPY_HW_ENABLE_GPIO11 (1) #define MICROPY_HW_ENABLE_GPIO12 (1) #define MICROPY_HW_ENABLE_GPIO13 (1) -#if !CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED +#if !MICROPY_HW_ESP_USB_SERIAL_JTAG #define MICROPY_HW_ENABLE_GPIO18 (1) #define MICROPY_HW_ENABLE_GPIO19 (1) #endif diff --git a/ports/esp32/main.c b/ports/esp32/main.c index 330ba64b467c..dedc5421e34e 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -99,7 +99,7 @@ void mp_task(void *pvParameter) { #if MICROPY_PY_THREAD mp_thread_init(pxTaskGetStackStart(NULL), MICROPY_TASK_STACK_SIZE / sizeof(uintptr_t)); #endif - #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED + #if MICROPY_HW_ESP_USB_SERIAL_JTAG usb_serial_jtag_init(); #elif CONFIG_USB_OTG_SUPPORTED usb_init(); diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index a5c6b9c01449..25fa4706214c 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -260,6 +260,11 @@ typedef long mp_off_t; // board specifics #define MICROPY_PY_SYS_PLATFORM "esp32" +// 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) +#endif + // ESP32-S3 extended IO for 47 & 48 #ifndef MICROPY_HW_ESP32S3_EXTENDED_IO #define MICROPY_HW_ESP32S3_EXTENDED_IO (1) diff --git a/ports/esp32/mphalport.c b/ports/esp32/mphalport.c index cc0e2ee7b499..e85aa6260c06 100644 --- a/ports/esp32/mphalport.c +++ b/ports/esp32/mphalport.c @@ -104,7 +104,7 @@ void check_esp_err_(esp_err_t code, const char *func, const int line, const char uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { uintptr_t ret = 0; - #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED + #if MICROPY_HW_ESP_USB_SERIAL_JTAG usb_serial_jtag_poll_rx(); #endif if ((poll_flags & MP_STREAM_POLL_RD) && stdin_ringbuf.iget != stdin_ringbuf.iput) { @@ -118,7 +118,7 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { int mp_hal_stdin_rx_chr(void) { for (;;) { - #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED + #if MICROPY_HW_ESP_USB_SERIAL_JTAG usb_serial_jtag_poll_rx(); #endif int c = ringbuf_get(&stdin_ringbuf); @@ -143,7 +143,7 @@ mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) { if (release_gil) { MP_THREAD_GIL_EXIT(); } - #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED + #if MICROPY_HW_ESP_USB_SERIAL_JTAG usb_serial_jtag_tx_strn(str, len); did_write = true; #elif CONFIG_USB_OTG_SUPPORTED diff --git a/ports/esp32/uart.h b/ports/esp32/uart.h index 13c5e8830728..0a0985d1b4e2 100644 --- a/ports/esp32/uart.h +++ b/ports/esp32/uart.h @@ -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 && !CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED) +#define MICROPY_HW_ENABLE_UART_REPL (!CONFIG_USB_OTG_SUPPORTED && !CONFIG_ESP_CONSOLE_USB_CDC && !MICROPY_HW_ESP_USB_SERIAL_JTAG) #endif #if MICROPY_HW_ENABLE_UART_REPL diff --git a/ports/esp32/usb.c b/ports/esp32/usb.c index 5a0e6b8a9209..471f2c2e0e46 100644 --- a/ports/esp32/usb.c +++ b/ports/esp32/usb.c @@ -28,7 +28,7 @@ #include "py/mphal.h" #include "usb.h" -#if CONFIG_USB_OTG_SUPPORTED && !CONFIG_ESP_CONSOLE_USB_CDC && !CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED +#if CONFIG_USB_OTG_SUPPORTED && !CONFIG_ESP_CONSOLE_USB_CDC && !MICROPY_HW_ESP_USB_SERIAL_JTAG #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 && !CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED +#endif // CONFIG_USB_OTG_SUPPORTED && !CONFIG_ESP_CONSOLE_USB_CDC && !MICROPY_HW_ESP_USB_SERIAL_JTAG diff --git a/ports/esp32/usb_serial_jtag.c b/ports/esp32/usb_serial_jtag.c index f1148ab197eb..32eb806e7295 100644 --- a/ports/esp32/usb_serial_jtag.c +++ b/ports/esp32/usb_serial_jtag.c @@ -28,7 +28,7 @@ #include "py/mphal.h" #include "usb_serial_jtag.h" -#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED +#if MICROPY_HW_ESP_USB_SERIAL_JTAG #include "hal/usb_serial_jtag_ll.h" #include "esp_intr_alloc.h" @@ -117,4 +117,4 @@ void usb_serial_jtag_tx_strn(const char *str, size_t len) { } } -#endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED +#endif // MICROPY_HW_ESP_USB_SERIAL_JTAG