-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'clock_gettime()' function doesn't return the time with us accuracy (IDFGH-9531) #10885
Comments
Could you please provide the rest of the information from the bug report issue template: IDF version (commit) ID, sdkconfig file? The code snippet you have posted looks odd, because:
Please try the following code instead: struct timespec tv_now;
clock_gettime(CLOCK_REALTIME, &tv_now);
int64_t time_us = (int64_t)tv_now.tv_sec * 1000000L + (int64_t)tv_now.tv_nsec / 1000;
printf("time_us: %lld\n", time_us); |
I have modified the first post to provide the rest of the information.
Nevertheless, sometimes the microcontroller stops working right after the first |
There is no release/v5.1 branch in IDF yet, therefore you get the error. It looks like you have cloned the The docs for updating IDF are here: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/versions.html#updating-master. Just be aware, if you have done local changes in IDF repo, you need to |
Is this the latest version? I have updated to this version and now I have the following compilation error:
|
I'm not sure what is the reason for this issue, I'll ask my colleagues familiar with LwIP to take a look. In the meantime please check the docs about SNTP: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system_time.html#sntp-time-synchronization — i think there is a new API recommended there, and the header file is apps/esp_sntp.h. |
@marco711 There's also a note about it in the v5.1 Migration guide Quick fix is to include -#include "lwip/apps/sntp.h"
+#include "esp_sntp.h"
...
-sntp_stop();
+esp_sntp_stop(); Alternatively (preferably) you can use esp_netif's SNTP API |
Thank you. I have updated to ESP-IDF v5.1-dev-3710-gacac972f70 but the microcontroller still blocks sometimes after the first |
@marco711 Could you please attach your |
Attached you will find the Below you will find the log with the line (in bold) where the microcontroller blocks:
The
|
Thank you for the extra details. |
I cannot connect with the debugger:
Below my gdbinit file:
Is there any port other than 3333 that I can try? |
Is OpenOCD running when you are starting GDB? It looks like not, because GDB isn't able to connect to it. If you are working from the command line, you can start it like this:
|
I cannot launch OpenOCD:
I'm trying to run OpenOCD with
Is there any configuration I'm missing? |
Could you please check, what does Maybe you aren't connecting the board over the built-in USB port and are using some USB-Serial converter, instead. Which development board are you using, by the way? On the ESP32-S3-DevKit-C there are two ports, you need the one which has "USB" written next to it (docs). |
Yes, I'm connecting over the port marked as "USB" and not "UART" and I'm using an ESP32-S3-DevKitC-1 board. |
That looks pretty odd! Which of those devices disappears when you unplug the board? |
Right after I connect the USB port the following device appears: Below the complete log:
Nevertheless, if I retry running
Below the result of dmesg
When I "flash" and "monitor" the device I use the UART port. Just for launching OpenOCD I have connected the "USB" port. I am using the same USB cable I use for flashing and I have also tried with another one. The result is the same when connecting to the "USB" port.
This time the device has not disappeared from the |
Alright... seems like this troubleshooting direction is only getting us further away from the original problem.
This often indicates that there is a permission issue accessing the device. Assigning the usb device to Another way to debug the case when a task gets blocked is to subscribe the task to the Task Watchdog ( A few other troubleshooting ideas:
|
I have added the task watchdog. The MQTT task is triggering the watchdog:
I have also tried the two last troubleshooting ideas:
|
The problem might have came from two tasks trying to access to the same variable at the same time. A variable was read by |
Answers checklist.
General issue report
IDF version:
ESP-IDF v5.1-dev-1006-g02605f1a31-dirty 2nd stage bootloader
SDK config file:
Attached.
Issue
Hello,
I want to get an Epoch timestamp by using
clock_gettime()
function. Nevertheless, when I print the result I only get a second accuracy:This is the code I'm using:
I'm using an ESP32-S3 microcontroller and as clock source I'm using the internal 136 kHz oscillator. Could this be the reason why I get this accuracy?
The text was updated successfully, but these errors were encountered: