Skip to content

Commit

Permalink
Merge pull request #2548 from MaBecker/master
Browse files Browse the repository at this point in the history
allow to switch between USB_CDC and UART for ESP32C3 boards
  • Loading branch information
gfwilliams authored Aug 29, 2024
2 parents 7000f5d + 6c52bc0 commit 66fec69
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions boards/ESP32C3_IDF4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
}
Expand Down
6 changes: 6 additions & 0 deletions targets/esp32/jshardwareUart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
Expand Down

0 comments on commit 66fec69

Please sign in to comment.