From 6c52bc026cc6b268870617eaa7d76bfcffad295f Mon Sep 17 00:00:00 2001 From: MaBecker Date: Wed, 28 Aug 2024 20:49:23 +0200 Subject: [PATCH] allow to switch between USB_CDC and UART for ESP32C3 boards 'DEFINES+=-DUSB_CDC', # Disable this line to use serial interface --- boards/ESP32C3_IDF4.py | 1 + targets/esp32/jshardwareUart.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/boards/ESP32C3_IDF4.py b/boards/ESP32C3_IDF4.py index 4342b63cca..e8f5c9f27c 100644 --- a/boards/ESP32C3_IDF4.py +++ b/boards/ESP32C3_IDF4.py @@ -74,6 +74,7 @@ 'DEFINES+=-DESP_STACK_SIZE=25000', 'DEFINES+=-DJSVAR_MALLOC', # Allocate space for variables at jsvInit time 'DEFINES+=-DUSE_FONT_6X8', + 'DEFINES+=-DUSB_CDC', # Disable USB_CDC if board has uart interface 'ESP32_FLASH_MAX=1572864' ] } diff --git a/targets/esp32/jshardwareUart.c b/targets/esp32/jshardwareUart.c index b18cf33709..ec22daf679 100644 --- a/targets/esp32/jshardwareUart.c +++ b/targets/esp32/jshardwareUart.c @@ -87,11 +87,13 @@ void initSerial(IOEventFlags device,JshUSARTInfo *inf){ void initConsole(){ #ifdef CONFIG_IDF_TARGET_ESP32C3 + #ifdef USB_CDC /* Configure USB-CDC */ usb_serial_jtag_driver_config_t usb_serial_config = {.tx_buffer_size = 128, .rx_buffer_size = 128}; ESP_ERROR_CHECK(usb_serial_jtag_driver_install(&usb_serial_config)); + #endif #endif uart_config_t uart_config = { @@ -117,7 +119,11 @@ void consoleToEspruino(){ ticksToWait = 50 / portTICK_RATE_MS; #endif #ifdef CONFIG_IDF_TARGET_ESP32C3 + #ifdef USB_CDC int len = usb_serial_jtag_read_bytes(rxbuf, sizeof(rxbuf), ticksToWait); + #else + int len = uart_read_bytes(uart_console, rxbuf, sizeof(rxbuf), ticksToWait); // Read data from UART + #endif #else int len = uart_read_bytes(uart_console, rxbuf, sizeof(rxbuf), ticksToWait); // Read data from UART #endif