Skip to content

ESP32C3 can not wake from Light-sleep by UART #6976

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
soulyiran opened this issue Jul 12, 2022 · 5 comments
Closed
1 task done

ESP32C3 can not wake from Light-sleep by UART #6976

soulyiran opened this issue Jul 12, 2022 · 5 comments
Assignees
Labels
Area: ESP-IDF related ESP-IDF related issues Area: Peripherals API Relates to peripheral's APIs. Chip: ESP32-C3 Issue is related to support of ESP32-C3 Chip Peripheral: UART Status: Solved Type: For reference Common questions & problems
Milestone

Comments

@soulyiran
Copy link

Board

ESP32-C3-4M

Device Description

Board: ESP32-C3-4M on custom board
IDE: Arduino
Version: Arduino ESP32 Version 2.0.4
Computer OS: Mac M1

Hardware Configuration

only uart

Version

latest master (checkout manually)

IDE Name

Arduino IDE

Operating System

macOS 12.4

Flash frequency

40Mhz

PSRAM enabled

no

Upload speed

115200

Description

ESP32C3 can not wake from Light-sleep by UART.

Sketch

#include <Arduino.h>
#include <driver/uart.h>

void setup() {
    // wake from sleep every 20s
    esp_sleep_enable_timer_wakeup(20*1000000); 

    // Configure UART0
    Serial.begin(115200);
    while (!Serial) { delay(500); }
    uart_set_wakeup_threshold(UART_NUM_0, 3);   // 3 edges on U0RXD to wakeup
    esp_sleep_enable_uart_wakeup(UART_NUM_0);   // Enable UART 0 as wakeup source

    Serial.printf("ESP32 light sleep with UART wake\r\n");
    Serial.printf("SDK: %s\r\n", ESP.getSdkVersion());
    Serial.flush();

}

void loop() {
    Serial.println("going to sleep");
    Serial.flush();
    esp_light_sleep_start();
    esp_sleep_wakeup_cause_t wakeup_cause;
    wakeup_cause = esp_sleep_get_wakeup_cause();
    
    if (wakeup_cause == 8){
      Serial.println("wakeup by uart");
      delay(5000);
      while(Serial.available()) Serial.write(Serial.read());
      Serial.flush();
    }
    if (wakeup_cause == 4){
      Serial.println("wakeup by timmer");
      Serial.flush();
    }
}

Debug Message

ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x1 (POWERON),boot:0xc (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x438
load:0x403ce000,len:0x918
load:0x403d0000,len:0x24e4
SHA-256 comparison failed:
Calculated: 080c5cb68a075ced55f248b97bca965e3e5bd5da80a64e34e6a1638f89d6f64e
Expected: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Attempting to boot anyway...
entry 0x403ce000
ESP32 light sleep with UART wake
SDK: v4.4.1-472-gc9140caf8c
going to sleep
wakeup by timmer
...

Other Steps to Reproduce

I also try this code on ESP32, and it can be successfully wake by UART0.

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

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@soulyiran soulyiran added the Status: Awaiting triage Issue is waiting for triage label Jul 12, 2022
@SuGlider
Copy link
Collaborator

SuGlider commented Jul 13, 2022

Issue confirmed. The sketch works fine with ESP32, ESP32-S2 and ESP32-S3, but not for the ESP32-C3.

@SuGlider
Copy link
Collaborator

It is not actually an Arduino issue, but instead it may be an IDF issue.
@igrr - Do you have any information about it?
I remember about a similar issue with ESP32 (#5107) related to IO_MUX.
Not sure if this is a similar problem.

@SuGlider SuGlider self-assigned this Jul 13, 2022
@SuGlider
Copy link
Collaborator

I tested it with all Arduino Core versions and none of them works.

  • SDK: v4.4-dev-2313-gc69f0ec32 - Core 2.0.0 - FAIL
  • SDK: v4.4-dev-3569-g6a7d83af19-dirty - Core 2.0.1 - FAIL
  • SDK: v4.4-beta1-189-ga79dc75f0a - Core 2.0.2 - FAIL
  • SDK: v4.4.1-1-gb8050b365e - Core 2.0.3 - FAIL
  • SDK: v4.4.1-472-gc9140caf8c - Core 2.0.4 - FAIL

@SuGlider SuGlider added Type: Bug 🐛 All bugs Area: ESP-IDF related ESP-IDF related issues Chip: ESP32-C3 Issue is related to support of ESP32-C3 Chip Area: Peripherals API Relates to peripheral's APIs. and removed Status: Awaiting triage Issue is waiting for triage labels Jul 13, 2022
@VojtechBartoska VojtechBartoska moved this to Under investigation in Arduino ESP32 Core Project Roadmap Jul 14, 2022
@SuGlider
Copy link
Collaborator

@soulyiran

SOLUTION: add gpio_sleep_set_direction(GPIO_NUM_20, GPIO_MODE_INPUT); to the code:

void setup() {
    // wake from sleep every 20s
    esp_sleep_enable_timer_wakeup(20*1000000); 

    // Configure UART0
    Serial.begin(115200);
    while (!Serial) { delay(500); }

    // GPIO 20 is the default UART_0 RX pin
    gpio_sleep_set_direction(GPIO_NUM_20, GPIO_MODE_INPUT);
    gpio_sleep_set_pull_mode(GPIO_NUM_20, GPIO_PULLUP_ONLY);

    uart_set_wakeup_threshold(UART_NUM_0, 3);   // 3 edges on U0RXD to wakeup
    esp_sleep_enable_uart_wakeup(UART_NUM_0);   // Enable UART 0 as wakeup source

    Serial.printf("ESP32 light sleep with UART wake\r\n");
    Serial.printf("SDK: %s\r\n", ESP.getSdkVersion());
    Serial.flush();

}

Please confirm that it solves the issue. Thanks.

@SuGlider SuGlider added Type: For reference Common questions & problems Peripheral: UART Status: Solved and removed Type: Bug 🐛 All bugs labels Jul 14, 2022
@SuGlider SuGlider added this to the 2.0.5 milestone Jul 14, 2022
@SuGlider SuGlider moved this from Under investigation to In Review in Arduino ESP32 Core Project Roadmap Jul 14, 2022
@soulyiran
Copy link
Author

@soulyiran

SOLUTION: add gpio_sleep_set_direction(GPIO_NUM_20, GPIO_MODE_INPUT); to the code:

void setup() {
    // wake from sleep every 20s
    esp_sleep_enable_timer_wakeup(20*1000000); 

    // Configure UART0
    Serial.begin(115200);
    while (!Serial) { delay(500); }

    // GPIO 20 is the default UART_0 RX pin
    gpio_sleep_set_direction(GPIO_NUM_20, GPIO_MODE_INPUT);
    gpio_sleep_set_pull_mode(GPIO_NUM_20, GPIO_PULLUP_ONLY);

    uart_set_wakeup_threshold(UART_NUM_0, 3);   // 3 edges on U0RXD to wakeup
    esp_sleep_enable_uart_wakeup(UART_NUM_0);   // Enable UART 0 as wakeup source

    Serial.printf("ESP32 light sleep with UART wake\r\n");
    Serial.printf("SDK: %s\r\n", ESP.getSdkVersion());
    Serial.flush();

}

Please confirm that it solves the issue. Thanks.

this works for me too, thank you very much!

Repository owner moved this from In Review to Done in Arduino ESP32 Core Project Roadmap Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: ESP-IDF related ESP-IDF related issues Area: Peripherals API Relates to peripheral's APIs. Chip: ESP32-C3 Issue is related to support of ESP32-C3 Chip Peripheral: UART Status: Solved Type: For reference Common questions & problems
Projects
Development

No branches or pull requests

2 participants