Skip to content

ESP32-S3 native USB CDC stops working after light sleep #6581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
Miraculix200 opened this issue Apr 15, 2022 · 9 comments
Closed
1 task done

ESP32-S3 native USB CDC stops working after light sleep #6581

Miraculix200 opened this issue Apr 15, 2022 · 9 comments
Assignees
Labels
Area: Peripherals API Relates to peripheral's APIs. Chip: ESP32-C3 Issue is related to support of ESP32-C3 Chip Chip: ESP32-S3 Issue is related to support of ESP32-S3 Chip Status: Test needed Issue needs testing

Comments

@Miraculix200
Copy link

Miraculix200 commented Apr 15, 2022

Board

ESP32-S3-WROOM-1 N8R2

Device Description

Custom PCB https://oshwlab.com/Miraculix200/esp32-s3-mini_copy

Hardware Configuration

GPIO 19 and 20 are connected to USB connector

Version

2.0.3-RC1

IDE Name

Arduino IDE

Operating System

Windows 10

Flash frequency

80MHz

PSRAM enabled

yes

Upload speed

115200

Description

When using the Arduino IDE serial monitor or Putty connected to USB (with Hardware CDC and JTAG enabled) at 115200 baud, ESP_LOGD output will stop after light sleep. Doing ESP.restart() will not enable the output again. Only after a hard reset the ESP32-S3 outputs data over USB again.

Sketch

#include "esp32s3/rom/rtc.h"
#include "esp_log.h"

void setup()
{
    while (millis() < 5000)
        delay(100);

    ESP_LOGD("abc", "hello");
    delay(1000);

    for (int i = 0; i < 10; i++) {
        esp_sleep_enable_timer_wakeup(600 * 1000);
        esp_light_sleep_start();
        delay(1);
    }
}

void loop()
{
    ESP_LOGD("abc", "hello");
    delay(1000);
}

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.
@Miraculix200 Miraculix200 added the Status: Awaiting triage Issue is waiting for triage label Apr 15, 2022
@me-no-dev me-no-dev added Status: Test needed Issue needs testing Chip: ESP32-C3 Issue is related to support of ESP32-C3 Chip Chip: ESP32-S3 Issue is related to support of ESP32-S3 Chip Area: Peripherals API Relates to peripheral's APIs. labels Apr 19, 2022
@VojtechBartoska
Copy link
Contributor

@SuGlider Can you please help with triage? Maybe it's a duplicate of already opened USB CDC issues? Thanks

@Miraculix200
Copy link
Author

Miraculix200 commented Apr 20, 2022

It's similar to this issue #6264, but I failed to fix it using phy_bbpll_en_usb(true); (it had no effect, but maybe I did it wrong)

@me-no-dev
Copy link
Member

What happens if you sleep for a shorter time?

What probably happens is that your computer fails to communicate with the ESP during light sleep, so it stops asking it for data (with USB, it's the HOST that asks the questions, the DEVICE can not just send data on it's own). When you hard-reset the ESP, the USB is re-enumerated and starts working again. The solution might be to call an extra function in the future, or another Arduino functions that will re-enumerate the USB on wakeup from light sleep.

@WereCatf
Copy link
Contributor

WereCatf commented Nov 3, 2022

This is months old now and I don't know if this is relevant anymore, but I actually had this same issue with an STM32-board using USB-CDC and it was caused by, indeed, what @me-no-dev there said. What worked for me was as simple as stopping the USB-peripheral, pulling both USB-data lines down to GND for a couple of milliseconds, then restarting the USB-peripheral. I would assume the same would work on the ESP32-S2/-S3/-C3.

@N0ury
Copy link

N0ury commented Apr 22, 2023

Found this in USB Serial/JTAG Controller Console chapter of Espressif documentation:
If the application enters deep sleep mode, the USB Serial/JTAG device will disappear from the system.
Read it it's more detailed about light sleep.
I think this issue should be closed.

@SuGlider
Copy link
Collaborator

Closing the issue as per the description in the documentation. This is a limitation od the USB and deep/light sleeping.
https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-guides/usb-serial-jtag-console.html#limitations

@jstockdale
Copy link

jstockdale commented Feb 21, 2024

@WereCatf did you find a way to do this purely on the software / firmware side? I can replicate your workaround (touching ground to D+ alone seems to do it in my case) but when I tried to use the following snippet it didn't work. Do I also have to change the io_mux or other settings?

# This does not work to reset the USB bus, but pulling D+ to ground does...
            gpio_reset_pin(GPIO_NUM_19);
            gpio_reset_pin(GPIO_NUM_20);
            gpio_set_direction(GPIO_NUM_19, GPIO_MODE_OUTPUT);
            gpio_set_direction(GPIO_NUM_20, GPIO_MODE_OUTPUT);
            gpio_set_level(GPIO_NUM_19, 0);
            gpio_set_level(GPIO_NUM_20, 0);
            vTaskDelay(100 / portTICK_PERIOD_MS);
            gpio_set_direction(GPIO_NUM_19, GPIO_MODE_INPUT);
            gpio_set_direction(GPIO_NUM_20, GPIO_MODE_INPUT);
            gpio_reset_pin(GPIO_NUM_19);
            gpio_reset_pin(GPIO_NUM_20);

I was able to get it to work by using GPIOs to pull down the usb data lines (by soldering a small wire to the pads) but I'd very much prefer to reset usb without any hardware modifications.

@IhorNehrutsa
Copy link

IhorNehrutsa commented Apr 3, 2024

This reset the USB bus by pulling D+ to the ground.

...
ESP_ERROR_CHECK(esp_light_sleep_start());
...
uint32_t save = REG_READ(RTC_CNTL_USB_CONF_REG);
SET_PERI_REG_MASK(RTC_CNTL_USB_CONF_REG, RTC_CNTL_USB_PAD_PULL_OVERRIDE);
SET_PERI_REG_MASK(RTC_CNTL_USB_CONF_REG, RTC_CNTL_USB_DP_PULLDOWN);
vTaskDelay(5 / portTICK_PERIOD_MS);
REG_WRITE(RTC_CNTL_USB_CONF_REG, save ) ;
...

@Rob58329
Copy link
Contributor

Rob58329 commented Sep 23, 2024

ESP32-S3 native USB CDC stops working after light sleep

This is also an issue for the ESP32-C3 with "USB CDC On Boot: Enabled" (when using a Windows10 PC).

The best(?) solution I have found is to do:

 Serial.flush();
 Serial.end();
 esp_light_sleep_start();
 Serial.begin(115200);

This causes the Arduino-Serial-Monitor to be disconnected at "Serial.end()", which you then have to close and then re-open shortly after you hear the USB connection re-starting at the "Serial.begin(115200)". This is similar to what you have to do if using the ESP32-C3 "esp_deep_sleep_start()" function.

This works because recent versions of github.com/espressif/arduino-esp32 (eg. v23Sep24) for the ESP32-C3 have changed something in "Serial.end()", and also possibly in Serial.begin().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Peripherals API Relates to peripheral's APIs. Chip: ESP32-C3 Issue is related to support of ESP32-C3 Chip Chip: ESP32-S3 Issue is related to support of ESP32-S3 Chip Status: Test needed Issue needs testing
Projects
Development

No branches or pull requests

9 participants