Page 1 of 1

gettimeofday fails after esp_restart

Posted: Fri Oct 05, 2018 10:32 am
by davdav
Hi everybody,

I use gettimeofday to mantain a calendar on device.
If I have a "cold power on" it reports 1st jan 1970 and I update it using settimeofday with current time/date.
When I invoke gettimeofday it reports the current date/time correctly.

Then after some time (for example 24 hours of operation) and, let's imagine the date/time is 05 oct 2018, 10:00:00, I call "esp_restart" the program restart, but gettimeofday reports a time back of about 30minutes (it is not always the same time delay), so I get 05 oct 2018, 09:35:00

Should I not consider gettimeofday result after an esp_restart reboot?

Thanks

Re: gettimeofday fails after esp_restart

Posted: Sat Oct 06, 2018 9:25 pm
by papaluna
"Internal RTC clock frequency error is about 5%."
viewtopic.php?f=2&t=3715&p=17063&hilit= ... acy#p17063

Re: gettimeofday fails after esp_restart

Posted: Mon Oct 08, 2018 2:14 pm
by 0xffff
I had similar problem - not sure why this happens but it seemed to go away when I changed the configuration parameter in menuconfig -> component config -> ESP32 -> Timer used for gettimeofday from RTC & FRC to just RTC.

However, I don't really understand the FRC and RTC interactions.

Re: gettimeofday fails after esp_restart

Posted: Mon Oct 08, 2018 8:12 pm
by WiFive
Try calling esp_sync_counters_rtc_and_frc before restart

Re: gettimeofday fails after esp_restart

Posted: Mon Oct 08, 2018 8:57 pm
by davdav
Thanks @0xffff and @wifive.

As a workaround I m saving in a noinit ram variable the result of gettimeofday just before the restart.then at restart i settimeofday with thay variable and it seem to work.

However i discovered that in case of a crash of code the problem arise again because the reset is perfomed without my control.

Should i call regulary in the code the esp_sync_counter_rtc__and_frc?