Description
Board
ESP32-S3
Device Description
Any ESP32-S3
Hardware Configuration
Bare
Version
v2.0.6
IDE Name
PlatformIO
Operating System
Any
Flash frequency
40Mhz
PSRAM enabled
no
Upload speed
115200
Description
Hey, I think I have found a bug in the HWCDC library when using the USB Serial/Jtag interface. If any bytes are sent over serial before Serial.begin() gets called, the ESP will no longer respond over Serial, although the application will be running fine on the ESP. I believe this occurs due to how interrupts are handled specifically on the USB Serial/ JTAG hardware.
It appears that when data is sent to the ESP, the USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT
interrupt flag will not be raised if USB_SERIAL_JTAG.ep1_conf.serial_out_ep_data_avail
is set. When HWCDC::begin(...)
is called, the interrupts are disabled, all the interrupt bits are cleared and then the three interrupts the isr handler is looking for are re-enabled. This results in USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT
being cleared, and never raised again until reset.
The fix I currently have is removing the line where the interrupts are cleared (line 241 HWCDC.cpp on master) and am happy to submit a PR however I wanted to check if you guys see any direct issues with this fix.
I have attached a simple python program to recreate the bug in conjunction with the sketch attached below. The following build flags must also be passed inorder to enable USB Serial/JTAG.
-DARDUINO_USB_CDC_ON_BOOT=1
-DARDUINO_USB_MODE=1
Thanks!
Sketch
#include <Arduino.h>
#include <HWCDC.h>
#include <hal/usb_serial_jtag_ll.h>
#include <string>
uint32_t prevTime = 0;
void setup() {
// delay(2);
Serial.begin(115200);
Serial.println("begin");
}
void loop() {
if (millis() - prevTime > 500)
{
prevTime = millis();
std::string output;
output += "rxFifo: " + std::to_string(usb_serial_jtag_ll_rxfifo_data_available());
output += " Serial avaliable: " + std::to_string(Serial.available());
Serial.println(output.c_str());
}
while (Serial.available())
{
uint8_t b = Serial.read();
Serial.print(Serial.available());
Serial.print(" - ");
Serial.write(b);
Serial.println();
}
vTaskDelay(1); // watchdog
}
Debug Message
None
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status