gettimeofday fails after esp_restart

davdav
Posts: 208
Joined: Thu Nov 17, 2016 2:33 pm

gettimeofday fails after esp_restart

Postby davdav » Fri Oct 05, 2018 10:32 am

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

papaluna
Posts: 50
Joined: Tue Jan 30, 2018 11:27 am

Re: gettimeofday fails after esp_restart

Postby papaluna » Sat Oct 06, 2018 9:25 pm

"Internal RTC clock frequency error is about 5%."
viewtopic.php?f=2&t=3715&p=17063&hilit= ... acy#p17063
--
Paul.

0xffff
Posts: 41
Joined: Tue Jun 19, 2018 1:53 am

Re: gettimeofday fails after esp_restart

Postby 0xffff » Mon Oct 08, 2018 2:14 pm

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.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: gettimeofday fails after esp_restart

Postby WiFive » Mon Oct 08, 2018 8:12 pm

Try calling esp_sync_counters_rtc_and_frc before restart

davdav
Posts: 208
Joined: Thu Nov 17, 2016 2:33 pm

Re: gettimeofday fails after esp_restart

Postby davdav » Mon Oct 08, 2018 8:57 pm

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?

Who is online

Users browsing this forum: No registered users and 106 guests