I converted an ESP32 sample C program to C++ which basically opens the Wifi in Station mode. The program works right up to the point where I get an IP address back from the router – then crashes. I decoded my backtrace which points to freertos/port.c
Will someone please tell me what port.c is doing for Wifi? There is hardly a line of comment in that source file that says anything about its function. There is a lot of disclaimer jazz in there – nothing that gives me the bigger picture.
Here is my backtrace:
Wifi::event_handler(void*, char const*, int, void*) main/Wifi.cpp:1271 (discriminator 8)
Wifi::eventMarshaller(void*, char const*, int, void*) main/Wifi.cpp:1190
handler_execute at C:/SysGCC/esp32/esp-idf/v4.0/components/esp_event/esp_event.c:145
esp_event_loop_run at C:/SysGCC/esp32/esp-idf/v4.0/components/esp_event/esp_event.c:553 (discriminator 3)
esp_event_loop_run_task at C:/SysGCC/esp32/esp-idf/v4.0/components/esp_event/esp_event.c:115
vPortTaskWrapper at C:/SysGCC/esp32/esp-idf/v4.0/components/freertos/port.c:143
Final reference here – line 143 points to this small function:
#if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER
// Wrapper to allow task functions to return (increases stack overhead by 16 bytes)
static void vPortTaskWrapper(TaskFunction_t pxCode, void *pvParameters)
{
pxCode(pvParameters);
//FreeRTOS tasks should not return. Log the task name and abort.
char * pcTaskName = pcTaskGetTaskName(NULL);
ESP_LOGE(“FreeRTOS”, “FreeRTOS Task “%s” should not return, Aborting now!”, pcTaskName);
abort();
}
#endif
@KeithInAsia I tried building station example in ESP-IDF with C++ and did not find any issues.
Issue you are facing generally occurs if you are returning from a task(a task should never return). Can you please confirm the same?
In my run task I do not return…
This crash traces back to my event handler. Specifically back to the IP_EVENT, IP_EVENT_STA_GOT_IP handler.
case IP_EVENT_STA_GOT_IP : { // ESP32 station got IP from connected AP
ESP_LOGI(TAG, " IP_EVENT_STA_GOT_IP");
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
ESP_LOGI(TAG, “got ip:%s”, ip4addr_ntoa(&event->ip_info.ip)) ;
s_retry_num = 0 ;
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
}
Inside the function – the 5 lines inside – if I comment a few of them out – the crash stops.
The Log statement is always ok.
Most of the time does not crash with only Lines 2, 3 lines enabled.
Always crashes with line 4 enabled.
Always crashes with xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
I don’t see how any of this ties back to the run task in that object…
If you built the station example in ESP-IDF with C++ then you have a lot of changes to do to make it compile. Did you change the main from .c to.cpp?
Amanem
(Amanem)
April 9, 2024, 4:10am
4
hi , @KeithInAsia did you find an solution regarding to this issue , because even for me it is crashing .
Guru Meditation Error: Core 0 panic’ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x401b1fb0 PS : 0x00060230 A0 : 0x801b2050 A1 : 0x3ffd0530
0x401b1fb0: esp_event_loop_run at C:/v4.4.3/esp-idf/components/esp_event/esp_event.c:586 (discriminator 3)
A2 : 0x3ffcf84c A3 : 0xffffffff A4 : 0xfb0000e0 A5 : 0xfb0000e0
A6 : 0x00000000 A7 : 0x3f4f64f0 A8 : 0x3ffdd2d4 A9 : 0x3ffd0500
A10 : 0x3ffcf84c A11 : 0x00000000 A12 : 0x00000000 A13 : 0x3f4f64f0
A14 : 0x00000005 A15 : 0x00000000 SAR : 0x0000001a EXCCAUSE: 0x0000001c
EXCVADDR: 0xfb0000ec LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff
Backtrace: 0x401b1fad:0x3ffd0530 0x401b204d:0x3ffd0570 0x4008e571:0x3ffd0590
0x401b1fad: esp_event_loop_run at C:/v4.4.3/esp-idf/components/esp_event/esp_event.c:594 (discriminator 1)
0x401b204d: esp_event_loop_run_task at C:/v4.4.3/esp-idf/components/esp_event/esp_event.c:115 (discriminator 15)
0x4008e571: vPortTaskWrapper at C:/v4.4.3/esp-idf/components/freertos/port/xtensa/port.c:131
ELF file SHA256: 5351570e1e3da409
Rebooting…
ets Jul 29 2019 12:21:46
This is happening after successful provisioning and then crashing while switching to station mode .
code lines i suspect :
else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP)
{
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
ESP_LOGI(TAG, “got ip:” IPSTR “\n”, IP2STR(&event->ip_info.ip));
xEventGroupSetBits(s_wifi_event_group, WIFIEVT_CONNECT_BIT);
xEventGroupClearBits(s_wifi_event_group, WIFIEVT_DISCONNECT_BIT | WIFIEVT_APPDISCONNECT_BIT);
}
kanherea
(Aniruddha)
April 11, 2024, 10:06pm
5
Hello @Amanem can you check using breakpoints in your code to see exactly where is the code crashing? That might help us in zeroing in on the issue.
Thanks
Amanem
(Amanem)
April 12, 2024, 8:32am
6
unfortunately all my pins are begin used and i don’t have debugger too , so i used logging statements to do this
RAc
April 12, 2024, 9:22am
8
Have you checked for stack overflows?
Amanem
(Amanem)
April 26, 2024, 12:01pm
9
Hey , i found some wifi function was called multiple times , due to which crashing was happening .
Thanks .
aggarg
(Gaurav Aggarwal)
April 26, 2024, 6:11pm
10
Thank you for reporting back!