You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
@kiran-desilva - Thanks for the detailed issue report! Issue confirmed.
It can be also reproduced using the Serial Monitor, by just adding a delay(5000); before Serial.begin(). This gives me time to send data before begin() is executed.
The solution you have proposed is the right one. Please proceed with the PR.
kiran-desilva
added a commit
to icl-rocketry/arduino-esp32
that referenced
this issue
Mar 2, 2024
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 ifUSB_SERIAL_JTAG.ep1_conf.serial_out_ep_data_avail
is set. WhenHWCDC::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 inUSB_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!
serialbug.txt
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: