Page 1 of 1
Using ESP.restart() not consistent on ESP32-WROOM
Posted: Wed Sep 07, 2022 7:13 pm
by sparky2019
Hello
Having a problem consistently resetting or restarting ESP32-WROOM module.
Using Arduino IDE and ESP32-WROOM with FREERTOS.
Have 2 TASKS running, a main task and a WiFi task and on a post or get I write up to 50 bytes of data using the (SPIFFS) with the method EEPROM.write (add, data)
After this EEPROM write, then call the ESP.restart() .......
The module does not consistently reset and the EEPROM is NOT written and it can hang in which case needs a power recycle or hard reset. I have added and tried various combinations of delays.
Is there a way of gracefully shutting off all interrupts and then resetting the module ?
Any help would be appreciated.
Thanks in adv. S
Re: Using ESP.restart() not consistent on ESP32-WROOM
Posted: Wed Sep 07, 2022 9:28 pm
by lbernstone
You won't be able to properly use the system reset reason, but abort() will reliably give you a reboot.
Re: Using ESP.restart() not consistent on ESP32-WROOM
Posted: Thu Sep 08, 2022 6:03 am
by sparky2019
Thanks, my worry is that sometimes the EERPOM is not written prior to calling ESP.reset() and I have included a long delay between EEPROM.write and ESP.reset() so it may also have been the cause of the hang up ?
tr
S
Re: Using ESP.restart() not consistent on ESP32-WROOM
Posted: Thu Sep 08, 2022 9:14 am
by martinius96
Yep and also, are you using EEPROM.commit() after you write into SPIFFS?
You can disable interrupts using cli() or noInterrupts() function.
For enable them you can use sei() or interrupts(). I am using just ESP32-WROOM-32, but esp_restart(); worked properly for me.
Or when resetting call this, it will reset your ESP 1 ms after u start that watchdog timer.
Also, maybe you will need to add more wdtTimeout if your datas will not be written into SPIFFS in time.
You can try this code in Wokwi simulator from browser with ESP32 Devkit - ESP32-WROOM-32:
https://wokwi.com/projects/342223177015886420
Code: Select all
//GLOBAL VARIABLES
const int wdtTimeout = 1; //time in ms to trigger the watchdog
hw_timer_t *timer = NULL;
void IRAM_ATTR resetModule() {
ets_printf("reboot\n");
esp_restart();
}
//IN CODE WHERE U WANT RESTART
timer = timerBegin(0, 80, true); //timer 0, div 80
timerAttachInterrupt(timer, &resetModule, true); //attach callback
timerAlarmWrite(timer, wdtTimeout * 1000, false); //set time in us
timerAlarmEnable(timer); //enable interrupt
Re: Using ESP.restart() not consistent on ESP32-WROOM
Posted: Fri Sep 09, 2022 9:25 am
by sparky2019
Thanks very much - will try that
Re: Using ESP.restart() not consistent on ESP32-WROOM
Posted: Mon Sep 12, 2022 6:45 pm
by sparky2019
Thanks for your responses. Because I am using FREERTOS I had a few other little problems so after some fiddling and testing I found that this code below worked best for my situation and in case anyone else battling with similar issues :
if (allGood == 2)
{
ERROR_LED_ON;
WiFi.disconnect(); // Disconnect radio
delay(600);
noInterrupts(); // stop any interrupts that this call will stop
delay(500);
// store(0,25,data0); // store data and this function calls EEPROM.commit();
delay(500); // should be enough time for commit
//store(25,50,data1); // store data
delay(500); // should be enough time
abort(); // abort
delay(2000); // should never get here
abort(); // or here
}
Re: Using ESP.restart() not consistent on ESP32-WROOM
Posted: Mon Sep 12, 2022 7:21 pm
by lbernstone
Just a note- EEPROM is provided for compatibility with Arduino libraries. If you are writing new code specific to ESP32, you should use the Preferences library or nvs (which is the backing store for both Preferences and EEPROM).
https://github.com/espressif/arduino-es ... references
https://docs.espressif.com/projects/esp ... flash.html