arduino-esp32
arduino-esp32 copied to clipboard
USBMSC reports repeated "USB UNPLUGGED" and can cause stack corruption
Board
ESP32-S3 DevKitC-1
Device Description
Plane ESP32-S3 DevKitC-1
Hardware Configuration
no peripheral attached
Version
v2.0.4
IDE Name
Arduini IDE
Operating System
Windows 10
Flash frequency
80Mhz
PSRAM enabled
yes
Upload speed
921600
Description
There seems to be a bug in the USB MSC implementation. When the native USB Port is not connected to a USB Host (aka a Laptop/PC) it repeatedly fires the USB UNPLUGGED event. as the event queue is only 5 long, this can cause the code to crash with stack canary when there is enough other code running.
This can be easily reproduced by powering an ESP32-S3 (for example over the "UART" USB port on the devkit) and not connecting or disconnecting the "USB" USB Port.
I found a mention of a similar problem with the ESP32-S2 here and here
Sketch
Debug Message
USB UNPLUGGED <- this one is fired immediately
USB UNPLUGGED <- after a second the repeated event start
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
USB UNPLUGGED
Guru Meditation Error: Core 0 panic'ed (Unhandled debug exception).
Debug exception reason: Stack canary watchpoint triggered (arduino_usb_eve)
Core 0 register dump:
PC : 0x40378413 PS : 0x00060136 A0 : 0x00060130 A1 : 0x3fcf2130
A2 : 0x3fcf2984 A3 : 0x3fcf2530 A4 : 0x3fcf241c A5 : 0x00000000
A6 : 0x00000001 A7 : 0x3fcf2454 A8 : 0x00000000 A9 : 0x00000001
A10 : 0xa0000000 A11 : 0x00000000 A12 : 0x40000000 A13 : 0x00000000
A14 : 0x02c92bd0 A15 : 0x00ffffff SAR : 0x00000004 EXCCAUSE: 0x00000001
EXCVADDR: 0x00000000 LBEG : 0x400556d5 LEND : 0x400556e5 LCOUNT : 0xffffffff
Backtrace:0x40378410:0x3fcf21300x0006012d:0x3fcf2220 |<-CORRUPTED
ELF file SHA256: 0000000000000000
The stack canary can not be reproduced with the blank example code. I added this as an example exception that can happen when the event queue is not emptied fast enough.
Other Steps to Reproduce
The best way to reproduce the problem: 1.) connect both USB ports to the PC. 2.) Start the example code (a USB stick should be presented) 3.) disconnect the "USB" USB Port but leave the "UART" USB Port connected 4.) the USB UNPLUGGED will start to get printed repeatedly
I have checked existing issues, online documentation and the Troubleshooting Guide
- [X] I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@hathach Could you please look at this issue. I've seen you have investigated a similar issue before. Do you have an idea what could cause the USB UNPLUGGED event to be fired so rapidly? Help would be very appreciated!