Heap Corruption Wifi+ZigBee ESP32C6
Posted: Wed Sep 04, 2024 3:19 am
hello I am trying to implement zigbee functionality on a device that has wifi. the project was originally written for esp32C3.
i changed sdkconfig and inserted the zigbee code, but at a random point in the code execution, after connecting to a wifi access point, the firmware crashes with heap corruption. how can i identify the exact cause and location of the crash?
i changed sdkconfig and inserted the zigbee code, but at a random point in the code execution, after connecting to a wifi access point, the firmware crashes with heap corruption. how can i identify the exact cause and location of the crash?
- char buf[CLOUD_READBUF];
- int ret, flags, err;
- vTaskDelay(pdMS_TO_TICKS(50));
- DEBUG_MSG(BDL, (COL_CLOUD "mbedTLS thread start OK"));
- devc.cloudPin = initState;
- wifiInit((wifi_mode_t)NULL);
- #if defined(CONFIG_IDF_TARGET_ESP32C6)
- DEBUG_MSG(BDL, (COL_EXCHANGE "initZigbee()" COL_END));
- initZigbee();
- #endif
- time(&now);
- localtime_r(&now, &timeinfo);
- if (!devc.certsOk)
- {
- DEBUG_MSG(BDL, (COL_ERROR COL_CLOUD "Certs corrupted, delete task"));
- vTaskDelete(NULL);
- }
- esp_zb_platform_config_t config = {
- .radio_config = {
- .radio_mode = ZB_RADIO_MODE_NATIVE
- },
- .host_config = {
- .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE,
- }
- };
- ESP_ERROR_CHECK(esp_zb_platform_config(&config));
- xTaskCreate(esp_zb_task, "Zigbee_main", ZIBGEE_TASK_STACK, NULL, ZIGBEE_TASK_PRIORITY, &devc.zbTaskHandle);
- exit:
- vTaskDelay(pdMS_TO_TICKS(500));
- if (devc.connectionState > wifiConnection)
- {
- DEBUG_MSG(BDL, (COL_CLOUD "Free CA certificate"));
- mbedtls_x509_crt_free(&cacert);
- DEBUG_MSG(BDL, (COL_CLOUD "Free CLI certificate"));
- mbedtls_x509_crt_free(&clicert);
- DEBUG_MSG(BDL, (COL_CLOUD "Free key"));
- mbedtls_pk_free(&pkey);
- DEBUG_MSG(BDL, (COL_INFO COL_CLOUD "%d", heap_caps_get_free_size(MALLOC_CAP_8BIT)));
- }
- I (62482) esp-cloud.c:0345 : Connecting to IP:PORT...
- I (62492) telnet_log.c:0087 : INFO: >> telnetTask
- I (62992) contikiIntegration.c:0393 : INFO: msID: 55, cmd: 05
- I (63052) esp-cloud.c:0365 : Cloud IP: IP
- I (63052) esp-cloud.c:0399 : Connected
- I (63052) wifi.c:1989 : Hostname: api.ipify.org
- I (63052) wifi.c:1990 : Port: 80
- I (63192) functions.c:1031 : TotTsk:18; Free:125352, pubResTmr:3/16, WiFi:2/3/1/0, BLE:1, RSSI:-85, temp:16 uptm:63, stmrst:0, ota:ESP32INIT(0):100, 0
- I (63192) functions.c:1037 : WIFI: serverConnection/WIFI_MODE_APSTA/WIFI_PS_MIN_MODEM/scanStopped
- I (63202) functions.c:1041 : IP: 192.168.3.98
- I (63202) functions.c:1043 : certsOk:1; nvsOk:1
- I (63212) functions.c:1045 : mtx: k:0, i2c:0, ssl:0, fl:0
- I (63222) functions.c:1049 : state: 0 ["display":"000"]
- I (63222) functions.c:1051 : tmr time: rx:0, tx:0, ex:62, etemp:55, mc:0, STA:0, wApply:4, AP:0
- I (63232) functions.c:1055 : tmr cnt: rx:0, tx:0, ex:53, etemp:5, mc:0, STA:0, wApply:1, AP:0
- I (63242) functions.c:1059 : countdown: ota:6, web:255
- I (63252) functions.c:1060 : traceData: , eventReset:
- I (63462) wifi.c:2028 : ip addr: IP
- I (63562) wifi.c:2044 : IP: connected; socket: 58
- I (63562) wifi.c:2062 : Port 80 opened
- I (63612) wifi.c:1957 : socket #58 opened, delete task
- I (63772) esp-cloud.c:0116 : Ip address
- I (63772) esp-cloud.c:0403 : INFO: freeHeap:125548
- I (63782) esp-cloud.c:0405 : INFO: Loading CA certificate: err: 0, ESP_OK
- I (63792) esp-cloud.c:0411 : Loading CLI certificate. success_connects: 0
- I (63802) esp-cloud.c:0413 : INFO: Loading CLI certificate: err: 0, ESP_OK
- I (63802) esp-cloud.c:0419 : Verify certificates
- I (63832) esp-cloud.c:0421 : Verify certificates: err: 0, ESP_OK
- I (63832) esp-cloud.c:0427 : Loading key
- I (63842) esp-cloud.c:0429 : Loading key: err: 0, ESP_OK
- I (63842) esp-cloud.c:0434 : INFO: freeHeap:121096
- I (63852) esp-cloud.c:0436 : Success server connects: 0
- I (64862) esp-cloud.c:0452 : RECEIVED HELLO
- I (64862) esp-cloud.c:0455 : send 10 bytes, STARTTLS
- I (66002) esp-cloud.c:0469 : RECEIVED READY
- I (66002) esp-cloud.c:0471 : Performing the SSL/TLS handshake...
- I (66002) esp-cloud.c:0477 : ERROR: mbedtls_ssl_handshake returned -0x5100
- I (66512) esp-cloud.c:0540 : Free CA certificate
- I (66512) esp-cloud.c:0542 : Free CLI certificate
- I (66512) esp-cloud.c:0544 : Free key
- I (66512) esp-cloud.c:0546 : INFO: 122816
- CORRUPT HEAP: Bad tail at 0x40843e40. Expected 0xbaad5678 got 0x00000000
- assert failed: 0x4081317c
- 0x4081317c: multi_heap_free at C:/Users/kelka/esp/v5.1.3/esp-idf/components/heap/multi_heap_poisoning.c:276 (discriminator 1)
- Core 0 register dump:
- MEPC : 0x408005d6 RA : 0x4080e5ca SP : 0x40836530 GP : 0x40817180
- 0x408005d6: panic_abort at C:/Users/kelka/esp/v5.1.3/esp-idf/components/esp_system/panic.c:472
- 0x4080e5ca: __ubsan_include at C:/Users/kelka/esp/v5.1.3/esp-idf/components/esp_system/ubsan.c:313
- TP : 0x407f51c4 T0 : 0x37363534 T1 : 0x7271706f T2 : 0x33323130
- S0/FP : 0x40813180 S1 : 0x4082bc30 A0 : 0x40836544 A1 : 0x00000033
- 0x40813180: multi_heap_free at C:/Users/kelka/esp/v5.1.3/esp-idf/components/heap/multi_heap_poisoning.c:280
- A2 : 0x00000003 A3 : 0x40836558 A4 : 0x00000001 A5 : 0x40828000
- A6 : 0x00000000 A7 : 0x76757473 S2 : 0xffffaf00 S3 : 0x40817e80
- S4 : 0x40816e80 S5 : 0x4081d000 S6 : 0x4081c690 S7 : 0x421b7000
- S8 : 0x421b7000 S9 : 0x4081c690 S10 : 0x00000000 S11 : 0x00000000
- T3 : 0x6e6d6c6b T4 : 0x6a696867 T5 : 0x66656463 T6 : 0x62613938
- MSTATUS : 0x00001881 MTVEC : 0x40800001 MCAUSE : 0x00000007 MTVAL : 0x00000000
- 0x40800001: _vector_table at ??:?
- MHARTID : 0x00000000
- Stack memory:
- 40836530: 0x00000001 0x00000000 0x40813180 0x40814d18 0x40816e80 0x65737361 0x66207472 0x656c6961
- 0x40813180: multi_heap_free at C:/Users/kelka/esp/v5.1.3/esp-idf/components/heap/multi_heap_poisoning.c:280
- 0x40814d18: newlib_include_assert_impl at C:/Users/kelka/esp/v5.1.3/esp-idf/components/newlib/assert.c:93
- 40836550: 0x30203a64 0x38303478 0x37313331 0x00000063 0x00000019 0x4082bc30 0x00000000 0x40813180
- 0x40813180: multi_heap_free at C:/Users/kelka/esp/v5.1.3/esp-idf/components/heap/multi_heap_poisoning.c:280
- 40836570: 0x00000001 0x4081d094 0x40843e0c 0x40800ba8 0x4081c690 0x4081d000 0x40842fc8 0x42131660
- 0x40800ba8: heap_caps_free at C:/Users/kelka/esp/v5.1.3/esp-idf/components/heap/heap_caps.c:390
- 0x42131660: mbedtls_mpi_free at C:/Users/kelka/esp/v5.1.3/esp-idf/components/mbedtls/mbedtls/library/bignum.c:215
- 40836590: 0xffffaf00 0x00000955 0x40842f14 0x4213513e 0xffffaf00 0x0000094d 0x40842ebc 0x4212c0b2
- 0x4213513e: mbedtls_ecdh_free at C:/Users/kelka/esp/v5.1.3/esp-idf/components/mbedtls/mbedtls/library/ecdh.c:253
- 0x4212c0b2: mbedtls_ssl_handshake_free at C:/Users/kelka/esp/v5.1.3/esp-idf/components/mbedtls/mbedtls/library/ssl_tls.c:4162
- 408365b0: 0xffffaf00 0x00001000 0x4081d094 0x4212c13a 0xffffaf00 0x4081d094 0x00000000 0x4212dda4
- 0x4212c13a: ssl_handshake_init at C:/Users/kelka/esp/v5.1.3/esp-idf/components/mbedtls/mbedtls/library/ssl_tls.c:1071
- 0x4212dda4: __wrap_mbedtls_ssl_session_reset at C:/Users/kelka/esp/v5.1.3/esp-idf/components/mbedtls/port/dynamic/esp_ssl_tls.c:361 (discriminator 15)
- 408365d0: 0x4081c690 0x421b1000 0x421b6000 0x42016eb4 0xa5a5a5a5 0xa5a5a5a5 0x4081c690 0x000103d0
- 0x42016eb4: sslClientTask at X:/Dev/DS_Projects/dsexs-3-cc-3-vasiltsov/trunk/trunk_esp32c3/main/cloud/esp-cloud.c:553 (discriminator 18)
- 408365f0: 0xa5a5a5a5 0xa5a5a5a5 0x00000039 0x00000000 0x00000000 0x00000000 0x44414552 0x000a0d59
- 40836610: 0x00000000 0x00000000 0xa5a5a500 0xa5a5a500 0x0000003d 0x00000035 0x0000009c 0x0000009d
- 40836630: 0x0000009e 0x0000009f 0x00000000 0xbadeb3aa 0x784d1c12 0x5e3fcd1f 0xb9cdd3cb 0x00000002
- 40836650: 0x00000000 0x00000030 0x00002710 0x4cf40020 0x2f21f858 0x4cf6d6d0 0xe537f9b5 0xc7d208d6
- 40836670: 0x905b5568 0x020a61f7 0x03525ce8 0x0000e403 0x4213949c 0x40836a4c 0x00000303 0x00000303
- 0x4213949c: mbedtls_entropy_func at C:/Users/kelka/esp/v5.1.3/esp-idf/components/mbedtls/mbedtls/library/entropy.c:285
- 40836690: 0x00010000 0x00010100 0x00000101 0x40836620 0x00000000 0x00000000 0x42134fdc 0x4083663c
- 0x42134fdc: mbedtls_ctr_drbg_random at C:/Users/kelka/esp/v5.1.3/esp-idf/components/mbedtls/mbedtls/library/ctr_drbg.c:585
- 408366b0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 408366d0: 0x00000000 0x00000000 0x421e8e30 0x4082ca88 0x40836714 0x00000000 0x408189c8 0x408189f0
- 408366f0: 0x00000000 0x00000000 0x00000010 0xffff0000 0xffffffff 0x00000000 0x00000000 0x00000000
- 40836710: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 40836730: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 40836750: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 40836770: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 40836790: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 408367b0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 408367d0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 408367f0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 40836810: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 40836830: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 40836850: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 40836870: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 40836890: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 408368b0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 408368d0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 408368f0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- 40836910: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
- ELF file SHA256: 655cc31654f76458
- Rebooting in 3 seconds...