Using ESP.restart() not consistent on ESP32-WROOM

sparky2019
Posts: 8
Joined: Sat Jan 19, 2019 5:08 am

Using ESP.restart() not consistent on ESP32-WROOM

Postby sparky2019 » Wed Sep 07, 2022 7:13 pm

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

lbernstone
Posts: 828
Joined: Mon Jul 22, 2019 3:20 pm

Re: Using ESP.restart() not consistent on ESP32-WROOM

Postby lbernstone » Wed Sep 07, 2022 9:28 pm

You won't be able to properly use the system reset reason, but abort() will reliably give you a reboot.

sparky2019
Posts: 8
Joined: Sat Jan 19, 2019 5:08 am

Re: Using ESP.restart() not consistent on ESP32-WROOM

Postby sparky2019 » Thu Sep 08, 2022 6:03 am

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

martinius96
Posts: 34
Joined: Thu Dec 13, 2018 1:39 am

Re: Using ESP.restart() not consistent on ESP32-WROOM

Postby martinius96 » Thu Sep 08, 2022 9:14 am

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
Image

sparky2019
Posts: 8
Joined: Sat Jan 19, 2019 5:08 am

Re: Using ESP.restart() not consistent on ESP32-WROOM

Postby sparky2019 » Fri Sep 09, 2022 9:25 am

Thanks very much - will try that

sparky2019
Posts: 8
Joined: Sat Jan 19, 2019 5:08 am

Re: Using ESP.restart() not consistent on ESP32-WROOM

Postby sparky2019 » Mon Sep 12, 2022 6:45 pm

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
}

lbernstone
Posts: 828
Joined: Mon Jul 22, 2019 3:20 pm

Re: Using ESP.restart() not consistent on ESP32-WROOM

Postby lbernstone » Mon Sep 12, 2022 7:21 pm

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

Who is online

Users browsing this forum: No registered users and 124 guests