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

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

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

Postby kolban » Mon Oct 10, 2016 5:44 am

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!".
Last edited by kolban on Mon Nov 07, 2016 5:38 am, edited 1 time in total.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

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

Postby ESP_Angus » Tue Oct 11, 2016 11:24 pm

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. :)

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

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

Postby ESP_igrr » Thu Nov 03, 2016 12:33 pm

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

Who is online

Users browsing this forum: Majestic-12 [Bot] and 136 guests