Page 1 of 1

[Solved] gettimeofday() is throwing an exception ...

Posted: Mon Oct 10, 2016 5:44 am
by kolban
I am compiling some 3rd party C code and tracking down an exception. When I ran GDB, on the exception, I was told that I was in the stack panic stack with no obvious backtrace before that.

The actual call is:

Code: Select all

struct timeval tv;
printf("cs_time: A\n");
if (gettimeofday(&tv, NULL /* tz */) != 0) return 0;
printf("cs_time: B\n");
I see the first log statement but not the second. If I comment out the gettimeofday() and just return 0, no issue and no exception. I am assuming gettimeofday() ....

Ohh ... pause here ...

I hunted deeper into the source and found:

https://github.com/espressif/esp-idf/bl ... alls.c#L91

It appears "gettimeofday" is not implemented and just aborts(). That's a little naughty. I see a comment mentioning it as a "todo". Might it be possible to issue a ESP_LOG message saying something like "<functionName>: Not yet implemented, aborting!".

Re: gettimeofday() is throwing an exception ...

Posted: Tue Oct 11, 2016 11:24 pm
by ESP_Angus
Yes, sorry about this. This is on my todo list to fix for all abort() calls, so it's more obvious when an abort() has occured rather than a crash.

A working gettimeofday() implementation is also... on the todo list. :)

Re: gettimeofday() is throwing an exception ...

Posted: Thu Nov 03, 2016 12:33 pm
by ESP_igrr
Time functions support has been merged into ESP-IDF master.

You can now use LwIP SNTP module got synchronize time from NTP servers, and obtain current time using 'gettimeofday' and standard C library functions.
Timekeeping is done using RTC clock and RTC memory during deep sleep, so next time ESP32 wakes up, these functions will still report correct time.
Example directory includes an example for all this: https://github.com/espressif/esp-idf/tr ... /README.md