Skip to content

Commit 3837fec

Browse files
committed
Fixes for espruino#2609 - Initial testing
1 parent 4d3e4c7 commit 3837fec

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

targets/esp32/IDF4/sdkconfig_c3

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,8 @@ CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0=y
801801
# CONFIG_ESP_MAIN_TASK_AFFINITY_NO_AFFINITY is not set
802802
CONFIG_ESP_MAIN_TASK_AFFINITY=0x0
803803
CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048
804-
CONFIG_ESP_CONSOLE_UART_DEFAULT=y
805-
# CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG is not set
804+
CONFIG_ESP_CONSOLE_UART_DEFAULT=n
805+
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y
806806
# CONFIG_ESP_CONSOLE_UART_CUSTOM is not set
807807
# CONFIG_ESP_CONSOLE_NONE is not set
808808
# CONFIG_ESP_CONSOLE_SECONDARY_NONE is not set

targets/esp32/IDF4/sdkconfig_s3

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,9 +845,9 @@ CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0=y
845845
# CONFIG_ESP_MAIN_TASK_AFFINITY_NO_AFFINITY is not set
846846
CONFIG_ESP_MAIN_TASK_AFFINITY=0x0
847847
CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048
848-
CONFIG_ESP_CONSOLE_UART_DEFAULT=y
848+
CONFIG_ESP_CONSOLE_UART_DEFAULT=n
849849
# CONFIG_ESP_CONSOLE_USB_CDC is not set
850-
# CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG is not set
850+
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y
851851
# CONFIG_ESP_CONSOLE_UART_CUSTOM is not set
852852
# CONFIG_ESP_CONSOLE_NONE is not set
853853
# CONFIG_ESP_CONSOLE_SECONDARY_NONE is not set

targets/esp32/jshardware.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ void jshUSARTKick(IOEventFlags device) {
592592
#endif
593593
case EV_SERIAL1:
594594
uart_tx_one_char((uint8_t)c);
595-
#ifdef CONFIG_IDF_TARGET_ESP32C3
595+
#if defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) && !defined(ESP_FORCE_NO_USB_SERIAL)
596596
// The USB CDC UART on the C3 only writes the data to USB after a newline. Ensure uartTask in main.c knows to flush the UART next time
597597
extern void esp32USBUARTWasUsed();
598598
esp32USBUARTWasUsed();

targets/esp32/jshardwareUart.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
#include <stdio.h>
2222
#include <string.h>
2323
#include <jsdevices.h>
24+
#include "jsinteractive.h" // jsDebug() ??
2425

25-
#ifdef CONFIG_IDF_TARGET_ESP32C3
26+
#if defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) && !defined(ESP_FORCE_NO_USB_SERIAL)
2627
#include "driver/usb_serial_jtag.h"
2728
#endif
2829

@@ -86,14 +87,12 @@ void initSerial(IOEventFlags device,JshUSARTInfo *inf){
8687
}
8788

8889
void initConsole(){
89-
#ifdef CONFIG_IDF_TARGET_ESP32C3
90-
#ifdef USB_CDC
90+
#if defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) && !defined(ESP_FORCE_NO_USB_SERIAL)
9191
/* Configure USB-CDC */
9292
usb_serial_jtag_driver_config_t usb_serial_config = {.tx_buffer_size = 128,
9393
.rx_buffer_size = 128};
94-
94+
jsDebug(DBG_INFO, "initConsole: Installing usb_serial_jtag_driver \n");
9595
ESP_ERROR_CHECK(usb_serial_jtag_driver_install(&usb_serial_config));
96-
#endif
9796
#endif
9897

9998
uart_config_t uart_config = {
@@ -114,17 +113,14 @@ void initConsole(){
114113

115114
uint8_t rxbuf[256];
116115
void consoleToEspruino(){
116+
#if ESP_IDF_VERSION_MAJOR >= 4
117+
TickType_t ticksToWait = 50 / portTICK_RATE_MS;
118+
#else
117119
TickType_t ticksToWait = 100;
118-
#if ESP_IDF_VERSION_MAJOR>=4
119-
ticksToWait = 50 / portTICK_RATE_MS;
120120
#endif
121-
#ifdef CONFIG_IDF_TARGET_ESP32C3
122-
#ifdef USB_CDC
121+
#if defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) && !defined(ESP_FORCE_NO_USB_SERIAL)
123122
int len = usb_serial_jtag_read_bytes(rxbuf, sizeof(rxbuf), ticksToWait);
124-
#else
125-
int len = uart_read_bytes(uart_console, rxbuf, sizeof(rxbuf), ticksToWait); // Read data from UART
126-
#endif
127-
#else
123+
#else
128124
int len = uart_read_bytes(uart_console, rxbuf, sizeof(rxbuf), ticksToWait); // Read data from UART
129125
#endif
130126
if(len > 0) jshPushIOCharEvents(EV_SERIAL1, rxbuf, len);

targets/esp32/main.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "jshardwareESP32.h"
2020
#include "jswrap_wifi.h" // jswrap_wifi_restore
2121
#include "jswrapper.h"
22+
#include "sdkconfig.h"
23+
2224

2325
#ifdef BLUETOOTH
2426
#include "libs/bluetooth/bluetooth.h"
@@ -37,15 +39,21 @@
3739

3840
#include "jsvar.h"
3941

42+
#if defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) && !defined(ESP_FORCE_NO_USB_SERIAL)
43+
#pragma message ("USB Serial JTAG console is enabled")
44+
#else
45+
#pragma message ("Using UART console")
46+
#endif
47+
4048
extern void *espruino_stackHighPtr; //Name spaced because this has to be a global variable.
4149
//Used in jsuGetFreeStack().
42-
#ifdef CONFIG_IDF_TARGET_ESP32C3
50+
#if defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) && !defined(ESP_FORCE_NO_USB_SERIAL)
4351
#include "hal/usb_serial_jtag_ll.h"
4452
volatile bool usbUARTIsNotFlushed;
4553
#endif
4654

4755
void esp32USBUARTWasUsed() {
48-
#ifdef CONFIG_IDF_TARGET_ESP32C3
56+
#if defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) && !defined(ESP_FORCE_NO_USB_SERIAL)
4957
usbUARTIsNotFlushed = true;
5058
#endif
5159
}
@@ -57,7 +65,7 @@ static void uartTask(void *data) {
5765
while(1) {
5866
consoleToEspruino();
5967
serialToEspruino();
60-
#ifdef CONFIG_IDF_TARGET_ESP32C3
68+
#if defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) && !defined(ESP_FORCE_NO_USB_SERIAL)
6169
/* The USB CDC UART on the C3 only writes the data to USB after a newline.
6270
We don't want that, so we call flush in this uart task if any data has been sent. */
6371
if (usbUARTIsNotFlushed) {

0 commit comments

Comments
 (0)