-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
Environment
- Development Kit: ESP32-DevKitC
- Kit version (for DevKitC): v4
- Module or chip used: ESP32-WROOM-32D
- IDF version : v4.1
- Build System: CMake and idf.py
- Compiler version: xtensa-esp32-elf-gcc (crosstool-NG esp-2020r2) 8.2.0
- Operating System: macOS
- Using an IDE?: No
- Power Supply: USB
Problem Description
Looks like call of esp_wifi_sta_get_ap_info cause stack overflow (or corrupt stack).
I have implemented test project to reproduce problem (it's part of my other project with minimal code to reproduce problem): esp_wifi_sta_get_ap_info_stack_overflow.
It cause the following error (from 1 sec till several minutes after start) (see full monitoring output here):
I (4607) LOG_TAG: Wi-Fi RSSI:***ERROR*** A stack overflow in task Tmr Svc has been detected.
abort() was called at PC 0x40088451 on core 0
0x40088451: vApplicationStackOverflowHook at /Users/mdobryakov/.esp-idf/components/esp32/panic.c:125
ELF file SHA256: dcacbb36167eb951
Backtrace: 0x40087fec:0x3ffbc210 0x4008842c:0x3ffbc240 0x40088451:0x3ffbc270 0x4008a208:0x3ffbc2a0 0x40088f40:0x3ffbc2d0 0x40088ef6:0xa5a5a5a5 |<-CORRUPTED
0x40087fec: invoke_abort at /Users/mdobryakov/.esp-idf/components/esp32/panic.c:157
0x4008842c: abort at /Users/mdobryakov/.esp-idf/components/esp32/panic.c:174
0x40088451: vApplicationStackOverflowHook at /Users/mdobryakov/.esp-idf/components/esp32/panic.c:125
0x4008a208: vTaskSwitchContext at /Users/mdobryakov/.esp-idf/components/freertos/tasks.c:2770
0x40088f40: _frxt_dispatch at /Users/mdobryakov/.esp-idf/components/freertos/portasm.S:406
0x40088ef6: _frxt_int_exit at /Users/mdobryakov/.esp-idf/components/freertos/portasm.S:206
Rebooting...
in some stack traces I see additional line:
0x400ff6b3: esp_wifi_sta_get_ap_info at ??:?
Stack for FreeRTOS timer has size of 2048 bytes (see sdkconfig). I suppose this is big stack size for such small handler and it should be enough to work of my code. So, I suppose that esp_wifi_sta_get_ap_info corrupt this stack and cause error.
P.S. I have set Stack smashing protection mode to Overall to decrease time of error appear but without this option the error happens too (required more time to reproduce).
Expected Behavior
esp_wifi_sta_get_ap_info must not corrupt stack.
Actual Behavior
Looks like esp_wifi_sta_get_ap_info corrupt stack.
Steps to reproduce
- Clone esp_wifi_sta_get_ap_info_stack_overflow test project to reproduce problem.
- Set correct SSID and password in
main.cpp - Run
idf.py reconfigure build flash monitor.
Code to reproduce this issue
See esp_wifi_sta_get_ap_info_stack_overflow test project.
It establish Wi-Fi connection use SSID and password and then run FreeRTOS timer to collect Wi-Fi RSSI every second (it real app every 10 sec) use esp_wifi_sta_get_ap_info method.
Here is method which cause error:
void WiFiManager::strangeMeasurementsTimerHandler(TimerHandle_t timer) {
void *p0 = nullptr;
ESP_LOGW("STACK POSITION", "p0: %p", (void *)&p0);
wifi_ap_record_t wifiApRecord = {};
void *p1 = nullptr;
ESP_LOGW("STACK POSITION", "p1: %p", (void *)&p1);
esp_err_t result = esp_wifi_sta_get_ap_info(&wifiApRecord);
void *p2 = nullptr;
ESP_LOGW("STACK POSITION", "p2: %p", (void *)&p2);
ESP_LOGI("LOG_TAG", "Wi-Fi RSSI: %d", wifiApRecord.rssi);
}
I have added additional logging of current stack position because it helps to decrease time of reproduce problem. If you wish you can replace it to something like ESP_LOGW("", "Point 1"); and it will decrease time of reproduction too. Without additional code around esp_wifi_sta_get_ap_info very hard to catch error in test project.
Debug Logs
See full monitoring output here. Here is main part:
...
I (4608) LOG_TAG: Wi-Fi RSSI: -58
***ERROR*** A stack overflow in task Tmr Svc has been detected.
abort() was called at PC 0x40088451 on core 0
0x40088451: vApplicationStackOverflowHook at /Users/mdobryakov/.esp-idf/components/esp32/panic.c:125
ELF file SHA256: dcacbb36167eb951
Backtrace: 0x40087fec:0x3ffbc7a0 0x4008842c:0x3ffbc7d0 0x40088451:0x3ffbc800 0x4008a208:0x3ffbc830 0x40088f40:0x3ffbc860 0x40088ef6:0x3ffbc890 0x400ff6b3:0x00000001 |<-CORRUPTED
0x40087fec: invoke_abort at /Users/mdobryakov/.esp-idf/components/esp32/panic.c:157
0x4008842c: abort at /Users/mdobryakov/.esp-idf/components/esp32/panic.c:174
0x40088451: vApplicationStackOverflowHook at /Users/mdobryakov/.esp-idf/components/esp32/panic.c:125
0x4008a208: vTaskSwitchContext at /Users/mdobryakov/.esp-idf/components/freertos/tasks.c:2770
0x40088f40: _frxt_dispatch at /Users/mdobryakov/.esp-idf/components/freertos/portasm.S:406
0x40088ef6: _frxt_int_exit at /Users/mdobryakov/.esp-idf/components/freertos/portasm.S:206
0x400ff6b3: esp_wifi_sta_get_ap_info at ??:?
Rebooting...
...
Other items if possible
- sdkconfig file - see test project
- coredump - I suppose I can provide it if it will be required.