ESP32-C3 random reboot when light sleep, powersaving ON(fixed!) and not keep IO pin HIGH(fixed too).

Open
#4,024 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c
Domain
embedded-iot

Research direction

Read the ESP32-C3 sleep path in ESP32Board.h and compare it with the reported changes: preserving GPIO state during sleep and adding a 500 µs delay before esp_light_sleep_start(). Reproduce the reported receiver pin drop and random reboot with powersaving enabled, then verify the fixes across sleep and wake cycles. The issue also mentions Serial CLI handling in simple repeater/main.cpp, but does not establish that as a confirmed cause.

Written by the indexing model from the issue text.

Description

Hello,

Two issue I fix, I use ESP32-C3 supermini board with a E22-900 30 dbm module. RXEN is wired to GPIO10, this pin are not on the RTC domain.

When my board go to sleep (powersaving ON) receiver become deaf. I found the RXEN(GPIO10) pin, become floating or dropping to LOW and receiver preamp is disabled. I add this line to my own variant ::begin() to to force CPU to keep all IO at it current state when sleeping:

esp_sleep_enable_gpio_switch(false);        // VE2YAG: Needed or C3 return pin le LOW or float during sleep (RX enable disabled)

This fix the issue, ESP32-C3 now keep it IO at current level during sleep, insteed of become floating.


Second issue:
When my ESP32-C3 meshcore is running and light sleep (powersaving ON), it randomly reboot with rst: 0x1 code (cold boot) After many hour of testing and debugging, the CPU reboot during it's sleeping time, just reboot when sleeping. I beefer power, put big capacitor on 3.3v and 5v rail, nothing prevent rebooting.

Finally, it seem to be a C3 bug when enter sleeping, you need to insert a small delay before entering sleep. I add this line: (ESP32Board.h)

// Configure GPIO wakeup
esp_sleep_enable_gpio_wakeup();
gpio_wakeup_enable((gpio_num_t)wakeupPin, GPIO_INTR_HIGH_LEVEL); // Wake up when receiving a LoRa packet

// MCU enters light sleep
delayMicroseconds(500);
esp_light_sleep_start();

// Avoid ISR flood during wakeup due to HIGH LEVEL interrupt
gpio_wakeup_disable(wakeupPin);
gpio_set_intr_type(wakeupPin, GPIO_INTR_POSEDGE);

500uS delay seem to be enough to fix my ramdom reboot.Also I reduce sleeping time to 1 second to worst the problem, and all is fine, random reboot is gone.


Note:
I have a reboot once, sending to console "unknown command" and reboot. I disable Serial CLI handling when CPU use sleeping, maybe I got some spurious entry on serial port when enter and exit from sleep each second. Anyway, serial port are unusable when sleeping, I disable serial handling to not got weird thing.

Here part of my code, simple repeater/main.cpp

void HandleSerialCLI()
{
// Handle Serial CLI
int len = strlen(command);
// command must stay NUL-terminated within its bounds. If it ever isn't,
// strlen() above can return >= sizeof(command) and the loop below would then
// index past the buffer, so clamp defensively.
if (len >= (int)sizeof(command)) {
command[0] = 0;
len = 0;
}
while (Serial.available() && len < sizeof(command)-1) {
char c = Serial.read();
if (c != '\n') {
command[len++] = c;
command[len] = 0;
Serial.print(c);
}
if (c == '\r') break;
}
if (len == sizeof(command)-1) { // buffer full: treat as a completed line
command[sizeof(command)-2] = '\r'; // place end-of-line marker inside the buffer
command[sizeof(command)-1] = 0; // keep the buffer NUL-terminated
}

if (len > 0 && command[len - 1] == '\r') { // received complete line
Serial.print('\n');
command[len - 1] = 0; // replace newline with C string null terminator
char reply[160];
reply[0] = 0;
#ifdef ETHERNET_ENABLED
if (!ethernet_handle_command(command, reply)) {
the_mesh.handleCommand(0, command, reply);
}
#else
the_mesh.handleCommand(0, command, reply); // NOTE: there is no sender_timestamp via serial!
#endif
if (reply[0]) {
Serial.print(" -> "); Serial.println(reply);
}

command[0] = 0;  // reset command buffer

}
}

void loop() {
bool board_is_sleeping = false;

if(board_is_sleeping == false) HandleSerialCLI();

board.loop(); // let the board feed its watchdog, run periodic housekeeping

#ifdef ETHERNET_ENABLED
ethernet_loop_maintain();
if (ethernet_read_line(ethernet_command, sizeof(ethernet_command))) {
char reply[160];
reply[0] = 0;
if (!ethernet_handle_command(ethernet_command, reply)) {
the_mesh.handleCommand(0, ethernet_command, reply);
}
ethernet_send_reply(reply);
ethernet_command[0] = 0;
}
#endif

#if defined(PIN_USER_BTN) && defined(SEEED_SENSECAP_SOLAR_H) && !defined(DISPLAY_CLASS)
// Hold the user button to power off the SenseCAP Solar repeater.
int btnState = digitalRead(PIN_USER_BTN);
if (btnState == LOW) {
if (userBtnDownAt == 0) {
userBtnDownAt = millis();
} else if ((unsigned long)(millis() - userBtnDownAt) >= USER_BTN_HOLD_OFF_MILLIS) {
Serial.println("Powering off...");
board.powerOff(); // does not return
}
} else {
userBtnDownAt = 0;
}
#endif

the_mesh.loop();
sensors.loop();
#ifdef DISPLAY_CLASS
ui_task.loop();
#endif
rtc_clock.tick();

#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.loop();
#endif

if(the_mesh.getNodePrefs()->powersaving_enabled == false)
{
board_is_sleeping = false;
}
else
{
if(!the_mesh.hasPendingWork())
{
#if defined(NRF52_PLATFORM)
board.sleep(0); // nrf ignores seconds param, sleeps whenever possible
#else
if (the_mesh.millisHasNowPassed(POWERSAVING_FIRSTSLEEP_SECS * 1000)) // To check if it is time to sleep
{
//Serial.print("S"); Serial.flush(); delay(1);
board.sleep(1); // Sleep. Wake up after a while or when receiving a LoRa packet
board_is_sleeping = true;
//delay(1); delay.print("W");
}
#endif
}
}
}

Dominant language
C
Stars
3.9k
Forks
1.5k
Avg merge
2d 7h
Merged PRs (30d)
56

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from meshcore-dev/MeshCore

All issues in meshcore-dev/MeshCore

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.