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

Offen
#4,024 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 2 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
48/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
c
Bereich
embedded-iot

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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
}
}
}

Vorherrschende Sprache
C
Sterne
3.9k
Forks
1.5k
Ø Merge
2 T. 19 Std.
Gemergte PRs (30 T.)
61

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus meshcore-dev/MeshCore

Alle Issues in meshcore-dev/MeshCore

Ähnliche Issues

Weitere Issues zu C

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.