espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.37k stars 7.37k forks source link

USB stops working after Windows host computer sleep #8107

Open asafteirobert opened 1 year ago

asafteirobert commented 1 year ago

Board

LOLIN S2 mini

Device Description

LOLIN S2 mini with ESP32-S2FH4 chip

Hardware Configuration

LOLIN S2 mini with some buttons attached to IO pins, connected to a Windows PC through USB.

Version

v2.0.8

IDE Name

Arduino IDE

Operating System

Windows 10 21H2

Flash frequency

40MHz

PSRAM enabled

no

Upload speed

921600

Description

Reproduction steps:

It appears the whole USB ends up in a broken state as uploading to the port(which still shows as connected) is no longer possible. Trying to access the debug serial port gives Error 31 "A device attached to the system is not functioning". Unplugging the USB cable USBLogView shows the USB Composite device, USB Input Device and USB Serial Device being unplugged. Reconnecting the USB cable (and thus also resetting the device) makes the sketch and upload port work again.

What I tried:

I can confirm that USB power is not turned off.

Sketch

The official example USB\Keyboard\KeyboardMessage

Debug Message

No output

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

No-idea-anymore commented 1 year ago

Good day, I I was wondering if you found a solution to this problem? I'm encountering the same issue with the ESP32-S3-WROOM-1 module.

tobwen commented 10 months ago

Did you try this?

USB.usbAttributes(TUSB_DESC_CONFIG_ATT_SELF_POWERED | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP);

source: https://forums.adafruit.com/viewtopic.php?p=937699

wareya commented 7 months ago

Hi, I'm having this issue too and the fix in the above post doesn't seem to work. I think TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP is about the mouse's ability to wake up the computer, not the other way around. I'm using an ESP32-S2-DevKitM-1U.

MRezaNasirloo commented 5 months ago

I'm having the same issue. It's not an ESP32-* issue, but rather an issue with the TinyUSB library. I tried a different project on an RP2040 board, which also uses TinyUSB and exhibits the same behavior. You should open a bug ticket for that project as well.

wareya commented 5 months ago

I actually remade my project on an rp2040 and this issue went away, but I'm using the mbed os core, not the arduino-pico core. Does the mbed os core also use TinyUSB?

MRezaNasirloo commented 5 months ago

I couldn't find any reference to TinyUSB in the mbed project. Do you use USB CDC in your project? Also, do you use USB power or a dedicated 5V voltage?

When the PC goes to sleep, the 5V is not disconnected, leaving the cdc usb stack in a broken state. I found out that if you use a 5V source from the PSU, the MCU will shut off on PC sleep and turn on again on wake up, It's a workaround, not a solution.