esp-idf: esp_restart() intermittently won't reset, causing stuck esp32 (IDFGH-258)
Environment
- Development Kit: custom board
- Core (if using chip or module): ESP32-D0WDQ6
- IDF version: master
- Development Env: C++ / arduino as idf component
- Power Supply: external 5V
Problem Description
Under some circumstances esp_restart() won’t actually reset the ESP32 leaving it in a state where no more console output is generated and no reset done. The ESP32 only reboots then after power cycle or EN-toggle.
Expected Behavior
Under all circumstances a call to esp_restart() should reboot the device.
Also when the device is in a “locked” state, there should be a watchdog reset.
Actual Behavior
Sometimes esp_restart() get’s stuck. Then either no more console output is produced or just a lot of gibberish with no subsequent console output.
No watchdog reset occurs.
Steps to repropduce
Hard to reproduce cause this happens in some safeguard timer functions (FreeRTOS timers) which are executed when some task won’t finish in time.
Code to reproduce this issue
Example:
#include "arduino.h"
// this is the callback that is called by the timer
void resetCallback(void * args) {
ESP_LOGE(ResetTimer::LOG_TAG, "ResetTimer not stopped in time, going down for reset in 5 secs");
WiFi.disconnect();
delay(5000);
ESP_LOGW(ResetTimer::LOG_TAG, "going down for reset now"); //this line is actually printed
ESP.restart(); //here either no more console output or random gibberish
}
Debug Logs
looks like that: EDIT: uploaded real log
W (446999) ResetTimer: going down for reset now
D (446999) event: SYSTEM_EVENT_STA_STOP
I (446999) wifi: flush txq
[D][WiFiGeneric.cpp:293] _eventCallback(): Event: 3 - STA_STOP
I (446999) wifi: stop sw txq
I (447005) K&O-Logger: Unhandled WiFiEvent //this is sent by WiFi Event handler
I (447010) wifi: lmac stop hw txq
D (447016) RTC_MODULE: Wi-Fi returns adc2 lock.
//nothing or gibberish
Other items if possible
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 39 (19 by maintainers)
Commits related to this issue
- Initialize detectedBaudRate to prevent compilation errors (#2101) — committed to 0xFEEDC0DE64/esp-idf by jamieparkinson 6 years ago
We recently hit an issue where esp_restart() will not reboot the device while https post is hanging, not sure if this is the same as the issue described here.
The solution that worked for us was to use esp_system_abort() instead - that call was succeeding in rebooting the esp.
@KonstantinKondrashov that solution could also work but for me it sounds a little risky to trust that the oscillator (if it’s bad) will stop when there are only 5 cycles.
@igrr @vonnieda as indeed the RTC crystal seems to be the problem here: would there be some kind of possibility to add a safeguard against this failure mode? The idea would be to detect a crystal failure from the main CPU clock / ABP clock and switch over to internal RC chain.
Also any notes on the design of the actual crystal osciallator circuit would be appreciated since I followed some guidelines I found online but many of them differ. It would be interesting to see how you at espressif pick the RTC crystal and load caps.