How safe is esp_restart()?

Gardin
Posts: 18
Joined: Fri Dec 13, 2019 4:53 pm

How safe is esp_restart()?

Postby Gardin » Fri Oct 09, 2020 11:33 pm

I'm working on a project that involves using an esp32 as a gateway to collect data from multiple sensors and send this data to aws-iot core.
In most cases I have a stable ethernet or Wi-Fi connection, but I have to back up data in an external flash in case data is not correctly sended.

What I also need is an external button to reset the board in certain cases(eg. when I need to change the Wi-Fi credentials, also stored in flash).

Is it a goot idea to use

Code: Select all

esp_restart()
for that? Is it a "clean and safe" reboot or I can have problems if I call this function when another Task may be saving data on my external flash?

Thank's in advance!!

Gabriel Gardin!

PeterR
Posts: 540
Joined: Mon Jun 04, 2018 2:47 pm

Re: How safe is esp_restart()?

Postby PeterR » Mon Oct 12, 2020 12:21 am

Its a 'shoot myself in the head' option. The code has a

Code: Select all

   sleep(1); // pause for dramatic effect
before pulling the trigger.
If you think about it; why wait for FLASH, what about an SD-CARD, other devices that ESP don't know about? The ESP reboot can only know about ESP devices & unless there is an 'add device' (which there is not) then doing anything other then 'restart now' might become inconsistent.
As you say, you will need to wait until FLASH has been updated before rebooting.
Of course you still have the problem of dealing with power fail & exceptions (my code never crashes ;)) - the power might be removed at anytime.
ESP NVS deals with this problem quite well.
& I also believe that IDF CAN should be fixed.

Gardin
Posts: 18
Joined: Fri Dec 13, 2019 4:53 pm

Re: How safe is esp_restart()?

Postby Gardin » Mon Oct 12, 2020 11:18 am

I was lookin for the 1 second pause you are talking about, is this RTC timer inside esp_restart_noos(void)?

Code: Select all

   // Enable RTC watchdog for 1 second
    rtc_wdt_protect_off();
    rtc_wdt_disable();
    rtc_wdt_set_stage(RTC_WDT_STAGE0, RTC_WDT_STAGE_ACTION_RESET_RTC);
    rtc_wdt_set_stage(RTC_WDT_STAGE1, RTC_WDT_STAGE_ACTION_RESET_SYSTEM);
    rtc_wdt_set_length_of_reset_signal(RTC_WDT_SYS_RESET_SIG, RTC_WDT_LENGTH_200ns);
    rtc_wdt_set_length_of_reset_signal(RTC_WDT_CPU_RESET_SIG, RTC_WDT_LENGTH_200ns);
    rtc_wdt_set_time(RTC_WDT_STAGE0, 1000);
    rtc_wdt_flashboot_mode_enable();
    
Anyway, if esp_restart is not a good idea, what option do I have?

Any hints would be appreciated :D

PeterR
Posts: 540
Joined: Mon Jun 04, 2018 2:47 pm

Re: How safe is esp_restart()?

Postby PeterR » Mon Oct 12, 2020 11:52 am

was lookin for the 1 second pause you are talking about, is this RTC timer inside esp_restart_noos(void)?
No idea & why care?
Anyway, if esp_restart is not a good idea, what option do I have?
esp_restart is perfectly ok. The problem is your task and/or your FLASH strategy.
Tell your task to stop and wait for it to stop. Then esp_restart(). That's just a simple mutex/semaphore.
You should be able to bring the adaptor down then up if you do not want to restart. Look at the NETIF api. Its easier to reboot however.

You still have potential issues with power fail and/or crashes however. Maybe you can live with the odd corruption or you dual buffer/use a transactional write - IJDK.
& I also believe that IDF CAN should be fixed.

Who is online

Users browsing this forum: No registered users and 33 guests