SNTP task crash

paolo86
Posts: 2
Joined: Fri May 03, 2024 10:31 am

SNTP task crash

Postby paolo86 » Fri May 03, 2024 12:00 pm

Hi, I have successfully integrated SNTP as per github sample (https://github.com/espressif/esp-idf/tr ... ocols/sntp).
I'm using default options, without SNTP over DHCP with pool.ntp.org as unique time server.
On WiFi connection I start an rtos task to monitor time acquisition.

The task method is the following:
  1. static void wifi_manager_sync_time_task(void *arg) {
  2.    
  3.     time_t now = 0;
  4.     struct tm timeinfo = { 0 };
  5.    
  6.     while (esp_netif_sntp_sync_wait(3000 / portTICK_PERIOD_MS) != ESP_OK) {
  7.         ESP_LOGI(TAG, "Waiting for system time to be set...");
  8.     }
  9.    
  10.     time(&now);
  11.     localtime_r(&now, &timeinfo);
  12.  
  13.     char strftime_buf[64];
  14.     strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
  15.     ESP_LOGI(TAG, "The current UTC date/time is: %s", strftime_buf);
  16.     vTaskDelete(NULL);
  17. }
Sometimes it takes some times to synchronize time (10/15s) after wifi connection. When this happen and the task code reach the vTaskDelete instruction the firmware reboot with this exception:

assert failed: heap_caps_free heap_caps.c:387 (heap != NULL && "free() target pointer is outside heap areas")

Backtrace: 0x40081aea:0x3ffbb390 0x40089ed9:0x3ffbb3b0 0x40091221:0x3ffbb3d0 0x400823a3:0x3ffbb4f0 0x40091269:0x3ffbb510 0x4015f16a:0x3ffbb530 0x4008af01:0x3ffbb550 0x4008afc7:0x3ffbb570 0x4008b0a7:0x3ffbb590 0x4008c8b9:0x3ffbb5b0
0x40081aea: panic_abort at /Users/paolo/esp/esp-idf/components/esp_system/panic.c:452
0x40089ed9: esp_system_abort at /Users/paolo/esp/esp-idf/components/esp_system/port/esp_system_chip.c:84
0x40091221: __assert_func at /Users/paolo/esp/esp-idf/components/newlib/assert.c:81
0x400823a3: heap_caps_free at /Users/paolo/esp/esp-idf/components/heap/heap_caps.c:387 (discriminator 1)
0x40091269: _free_r at /Users/paolo/esp/esp-idf/components/newlib/heap.c:49
0x4015f16a: _reclaim_reent at /builds/idf/crosstool-NG/.build/HOST-x86_64-apple-darwin12/xtensa-esp32-elf/src/newlib/newlib/libc/reent/reent.c:87
0x4008af01: prvDeleteTCB at /Users/paolo/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:4913
0x4008afc7: prvCheckTasksWaitingTermination at /Users/paolo/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:4621
0x4008b0a7: prvIdleTask at /Users/paolo/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:4278 (discriminator 1)
0x4008c8b9: vPortTaskWrapper at /Users/paolo/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162

If time acquisition is fast (2/3s) no exception will be throw.

Can someone help me to understand what is happeing and how can i deebug further?

IDF-Version: 5.1.1
board: esp32 wroom

Thank you.

MicroController
Posts: 1705
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: SNTP task crash

Postby MicroController » Sun May 05, 2024 7:21 pm

I imagine the issue could be that esp_netif_sntp_deinit() is called concurrently in another task while the wifi_manager_sync_time_task is still waiting.

paolo86
Posts: 2
Joined: Fri May 03, 2024 10:31 am

Re: SNTP task crash

Postby paolo86 » Tue May 07, 2024 11:58 am

Nope, there aren't any call to esp_netif_sntp_deinit method.
I will try to follow esp_netif_sntp_sync_wait method logic
Thanks

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 101 guests