From fe9eaf12f391232f195ac052005ac2b852409dd6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 13 Apr 2022 16:00:22 +1000 Subject: [PATCH] esp32: Add MICROPY_HW_ENABLE_UART_REPL and enable on generic S2/S3. Some S2/S3 modules don't use the native USB interface but instead have an external USB-UART. To make the GENERIC_S3/S3 firmware work on these boards the UART REPL is enabled in addition to the native USB CDC REPL. Fixes issues #8418 and #8524. Signed-off-by: Damien George --- ports/esp32/boards/GENERIC_S2/mpconfigboard.h | 3 +++ ports/esp32/boards/GENERIC_S3/mpconfigboard.h | 3 +++ ports/esp32/boards/GENERIC_S3_SPIRAM/mpconfigboard.h | 3 +++ ports/esp32/main.c | 3 ++- ports/esp32/mphalport.c | 3 ++- ports/esp32/uart.h | 5 +++++ 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ports/esp32/boards/GENERIC_S2/mpconfigboard.h b/ports/esp32/boards/GENERIC_S2/mpconfigboard.h index 01ac2ce58e..c4f86a8fc6 100644 --- a/ports/esp32/boards/GENERIC_S2/mpconfigboard.h +++ b/ports/esp32/boards/GENERIC_S2/mpconfigboard.h @@ -3,3 +3,6 @@ #define MICROPY_PY_BLUETOOTH (0) #define MICROPY_HW_ENABLE_SDCARD (0) + +// Enable UART REPL for modules that have an external USB-UART and don't use native USB. +#define MICROPY_HW_ENABLE_UART_REPL (1) diff --git a/ports/esp32/boards/GENERIC_S3/mpconfigboard.h b/ports/esp32/boards/GENERIC_S3/mpconfigboard.h index 3540e5a855..b8f5fb2560 100644 --- a/ports/esp32/boards/GENERIC_S3/mpconfigboard.h +++ b/ports/esp32/boards/GENERIC_S3/mpconfigboard.h @@ -3,5 +3,8 @@ #define MICROPY_PY_MACHINE_DAC (0) +// Enable UART REPL for modules that have an external USB-UART and don't use native USB. +#define MICROPY_HW_ENABLE_UART_REPL (1) + #define MICROPY_HW_I2C0_SCL (9) #define MICROPY_HW_I2C0_SDA (8) diff --git a/ports/esp32/boards/GENERIC_S3_SPIRAM/mpconfigboard.h b/ports/esp32/boards/GENERIC_S3_SPIRAM/mpconfigboard.h index beb796dd9e..f9126c98d7 100644 --- a/ports/esp32/boards/GENERIC_S3_SPIRAM/mpconfigboard.h +++ b/ports/esp32/boards/GENERIC_S3_SPIRAM/mpconfigboard.h @@ -4,5 +4,8 @@ #define MICROPY_PY_BLUETOOTH (0) #define MICROPY_PY_MACHINE_DAC (0) +// Enable UART REPL for modules that have an external USB-UART and don't use native USB. +#define MICROPY_HW_ENABLE_UART_REPL (1) + #define MICROPY_HW_I2C0_SCL (9) #define MICROPY_HW_I2C0_SDA (8) diff --git a/ports/esp32/main.c b/ports/esp32/main.c index a1c27c0a26..f833c95018 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -92,7 +92,8 @@ void mp_task(void *pvParameter) { usb_init(); #elif CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG usb_serial_jtag_init(); - #else + #endif + #if MICROPY_HW_ENABLE_UART_REPL uart_stdout_init(); #endif machine_init(); diff --git a/ports/esp32/mphalport.c b/ports/esp32/mphalport.c index 41e6e6ec00..aab534937e 100644 --- a/ports/esp32/mphalport.c +++ b/ports/esp32/mphalport.c @@ -111,7 +111,8 @@ void mp_hal_stdout_tx_strn(const char *str, size_t len) { usb_tx_strn(str, len); #elif CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG usb_serial_jtag_tx_strn(str, len); - #else + #endif + #if MICROPY_HW_ENABLE_UART_REPL uart_stdout_tx_strn(str, len); #endif if (release_gil) { diff --git a/ports/esp32/uart.h b/ports/esp32/uart.h index f32d5cf342..e3c7482e7b 100644 --- a/ports/esp32/uart.h +++ b/ports/esp32/uart.h @@ -28,6 +28,11 @@ #ifndef MICROPY_INCLUDED_ESP32_UART_H #define MICROPY_INCLUDED_ESP32_UART_H +// Whether to enable the REPL on a UART. +#ifndef MICROPY_HW_ENABLE_UART_REPL +#define MICROPY_HW_ENABLE_UART_REPL (!CONFIG_USB_ENABLED && !CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) +#endif + #ifndef MICROPY_HW_UART_REPL #define MICROPY_HW_UART_REPL (UART_NUM_0) #endif