Heap Corruption Wifi+ZigBee ESP32C6

kioelka
Posts: 1
Joined: Wed Sep 04, 2024 3:11 am

Heap Corruption Wifi+ZigBee ESP32C6

Postby kioelka » 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?
  1.     char buf[CLOUD_READBUF];
  2.     int ret, flags, err;
  3.     vTaskDelay(pdMS_TO_TICKS(50));
  4.     DEBUG_MSG(BDL, (COL_CLOUD "mbedTLS thread start OK"));
  5.  
  6.     devc.cloudPin = initState;
  7.  
  8.     wifiInit((wifi_mode_t)NULL);
  9. #if defined(CONFIG_IDF_TARGET_ESP32C6)
  10.     DEBUG_MSG(BDL, (COL_EXCHANGE "initZigbee()" COL_END));
  11.     initZigbee();
  12. #endif
  13.  
  14.     time(&now);
  15.     localtime_r(&now, &timeinfo);
  16.  
  17.     if (!devc.certsOk)
  18.     {
  19.         DEBUG_MSG(BDL, (COL_ERROR COL_CLOUD "Certs corrupted, delete task"));
  20.         vTaskDelete(NULL);
  21.     }
  1.     esp_zb_platform_config_t config = {
  2.         .radio_config = {
  3.             .radio_mode = ZB_RADIO_MODE_NATIVE
  4.             },
  5.         .host_config = {
  6.             .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE,
  7.         }
  8.     };
  9.     ESP_ERROR_CHECK(esp_zb_platform_config(&config));
  10.     xTaskCreate(esp_zb_task, "Zigbee_main", ZIBGEE_TASK_STACK, NULL, ZIGBEE_TASK_PRIORITY, &devc.zbTaskHandle);
  1.     exit:
  2.         vTaskDelay(pdMS_TO_TICKS(500));
  3.         if (devc.connectionState > wifiConnection)
  4.         {
  5.             DEBUG_MSG(BDL, (COL_CLOUD "Free CA certificate"));
  6.             mbedtls_x509_crt_free(&cacert);
  7.             DEBUG_MSG(BDL, (COL_CLOUD "Free CLI certificate"));
  8.             mbedtls_x509_crt_free(&clicert);
  9.             DEBUG_MSG(BDL, (COL_CLOUD "Free key"));
  10.             mbedtls_pk_free(&pkey);
  11.             DEBUG_MSG(BDL, (COL_INFO COL_CLOUD "%d", heap_caps_get_free_size(MALLOC_CAP_8BIT)));
  12.         }
  1. I (62482) esp-cloud.c:0345 : Connecting to IP:PORT...
  2. I (62492) telnet_log.c:0087 : INFO: >> telnetTask
  3. I (62992) contikiIntegration.c:0393 : INFO: msID: 55, cmd: 05
  4. I (63052) esp-cloud.c:0365 : Cloud IP: IP
  5. I (63052) esp-cloud.c:0399 : Connected
  6. I (63052) wifi.c:1989 : Hostname: api.ipify.org
  7. I (63052) wifi.c:1990 : Port: 80
  8. 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
  9. I (63192) functions.c:1037 : WIFI: serverConnection/WIFI_MODE_APSTA/WIFI_PS_MIN_MODEM/scanStopped
  10. I (63202) functions.c:1041 : IP: 192.168.3.98
  11. I (63202) functions.c:1043 : certsOk:1; nvsOk:1
  12. I (63212) functions.c:1045 : mtx: k:0, i2c:0, ssl:0, fl:0
  13. I (63222) functions.c:1049 : state: 0 ["display":"000"]
  14. I (63222) functions.c:1051 : tmr time: rx:0, tx:0, ex:62, etemp:55, mc:0, STA:0, wApply:4, AP:0
  15. I (63232) functions.c:1055 : tmr cnt: rx:0, tx:0, ex:53, etemp:5, mc:0, STA:0, wApply:1, AP:0
  16. I (63242) functions.c:1059 : countdown: ota:6, web:255
  17. I (63252) functions.c:1060 : traceData: , eventReset:
  18. I (63462) wifi.c:2028 : ip addr: IP
  19. I (63562) wifi.c:2044 : IP: connected; socket: 58
  20. I (63562) wifi.c:2062 : Port 80 opened
  21. I (63612) wifi.c:1957 : socket #58 opened, delete task
  22. I (63772) esp-cloud.c:0116 : Ip address
  23. I (63772) esp-cloud.c:0403 : INFO: freeHeap:125548
  24. I (63782) esp-cloud.c:0405 : INFO: Loading CA certificate: err: 0, ESP_OK
  25. I (63792) esp-cloud.c:0411 : Loading CLI certificate. success_connects: 0
  26. I (63802) esp-cloud.c:0413 : INFO: Loading CLI certificate: err: 0, ESP_OK
  27. I (63802) esp-cloud.c:0419 : Verify certificates
  28. I (63832) esp-cloud.c:0421 : Verify certificates: err: 0, ESP_OK
  29. I (63832) esp-cloud.c:0427 : Loading key
  30. I (63842) esp-cloud.c:0429 : Loading key: err: 0, ESP_OK
  31. I (63842) esp-cloud.c:0434 : INFO: freeHeap:121096
  32. I (63852) esp-cloud.c:0436 : Success server connects: 0
  33. I (64862) esp-cloud.c:0452 : RECEIVED HELLO
  34.  
  35. I (64862) esp-cloud.c:0455 : send 10 bytes, STARTTLS
  36.  
  37. I (66002) esp-cloud.c:0469 : RECEIVED READY
  38.  
  39. I (66002) esp-cloud.c:0471 : Performing the SSL/TLS handshake...
  40. I (66002) esp-cloud.c:0477 : ERROR: mbedtls_ssl_handshake returned -0x5100
  41. I (66512) esp-cloud.c:0540 : Free CA certificate
  42. I (66512) esp-cloud.c:0542 : Free CLI certificate
  43. I (66512) esp-cloud.c:0544 : Free key
  44. I (66512) esp-cloud.c:0546 : INFO: 122816
  45. CORRUPT HEAP: Bad tail at 0x40843e40. Expected 0xbaad5678 got 0x00000000
  46.  
  47. assert failed: 0x4081317c
  48. 0x4081317c: multi_heap_free at C:/Users/kelka/esp/v5.1.3/esp-idf/components/heap/multi_heap_poisoning.c:276 (discriminator 1)
  49.  
  50. Core  0 register dump:
  51. MEPC    : 0x408005d6  RA      : 0x4080e5ca  SP      : 0x40836530  GP      : 0x40817180
  52. 0x408005d6: panic_abort at C:/Users/kelka/esp/v5.1.3/esp-idf/components/esp_system/panic.c:472
  53. 0x4080e5ca: __ubsan_include at C:/Users/kelka/esp/v5.1.3/esp-idf/components/esp_system/ubsan.c:313
  54.  
  55. TP      : 0x407f51c4  T0      : 0x37363534  T1      : 0x7271706f  T2      : 0x33323130
  56. S0/FP   : 0x40813180  S1      : 0x4082bc30  A0      : 0x40836544  A1      : 0x00000033
  57. 0x40813180: multi_heap_free at C:/Users/kelka/esp/v5.1.3/esp-idf/components/heap/multi_heap_poisoning.c:280
  58.  
  59. A2      : 0x00000003  A3      : 0x40836558  A4      : 0x00000001  A5      : 0x40828000
  60. A6      : 0x00000000  A7      : 0x76757473  S2      : 0xffffaf00  S3      : 0x40817e80
  61. S4      : 0x40816e80  S5      : 0x4081d000  S6      : 0x4081c690  S7      : 0x421b7000
  62. S8      : 0x421b7000  S9      : 0x4081c690  S10     : 0x00000000  S11     : 0x00000000
  63. T3      : 0x6e6d6c6b  T4      : 0x6a696867  T5      : 0x66656463  T6      : 0x62613938
  64. MSTATUS : 0x00001881  MTVEC   : 0x40800001  MCAUSE  : 0x00000007  MTVAL   : 0x00000000
  65. 0x40800001: _vector_table at ??:?
  66.  
  67. MHARTID : 0x00000000
  68.  
  69. Stack memory:
  70. 40836530: 0x00000001 0x00000000 0x40813180 0x40814d18 0x40816e80 0x65737361 0x66207472 0x656c6961
  71. 0x40813180: multi_heap_free at C:/Users/kelka/esp/v5.1.3/esp-idf/components/heap/multi_heap_poisoning.c:280
  72. 0x40814d18: newlib_include_assert_impl at C:/Users/kelka/esp/v5.1.3/esp-idf/components/newlib/assert.c:93
  73.  
  74. 40836550: 0x30203a64 0x38303478 0x37313331 0x00000063 0x00000019 0x4082bc30 0x00000000 0x40813180
  75. 0x40813180: multi_heap_free at C:/Users/kelka/esp/v5.1.3/esp-idf/components/heap/multi_heap_poisoning.c:280
  76.  
  77. 40836570: 0x00000001 0x4081d094 0x40843e0c 0x40800ba8 0x4081c690 0x4081d000 0x40842fc8 0x42131660
  78. 0x40800ba8: heap_caps_free at C:/Users/kelka/esp/v5.1.3/esp-idf/components/heap/heap_caps.c:390
  79. 0x42131660: mbedtls_mpi_free at C:/Users/kelka/esp/v5.1.3/esp-idf/components/mbedtls/mbedtls/library/bignum.c:215
  80.  
  81. 40836590: 0xffffaf00 0x00000955 0x40842f14 0x4213513e 0xffffaf00 0x0000094d 0x40842ebc 0x4212c0b2
  82. 0x4213513e: mbedtls_ecdh_free at C:/Users/kelka/esp/v5.1.3/esp-idf/components/mbedtls/mbedtls/library/ecdh.c:253
  83. 0x4212c0b2: mbedtls_ssl_handshake_free at C:/Users/kelka/esp/v5.1.3/esp-idf/components/mbedtls/mbedtls/library/ssl_tls.c:4162
  84.  
  85. 408365b0: 0xffffaf00 0x00001000 0x4081d094 0x4212c13a 0xffffaf00 0x4081d094 0x00000000 0x4212dda4
  86. 0x4212c13a: ssl_handshake_init at C:/Users/kelka/esp/v5.1.3/esp-idf/components/mbedtls/mbedtls/library/ssl_tls.c:1071
  87. 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)
  88.  
  89. 408365d0: 0x4081c690 0x421b1000 0x421b6000 0x42016eb4 0xa5a5a5a5 0xa5a5a5a5 0x4081c690 0x000103d0
  90. 0x42016eb4: sslClientTask at X:/Dev/DS_Projects/dsexs-3-cc-3-vasiltsov/trunk/trunk_esp32c3/main/cloud/esp-cloud.c:553 (discriminator 18)
  91.  
  92. 408365f0: 0xa5a5a5a5 0xa5a5a5a5 0x00000039 0x00000000 0x00000000 0x00000000 0x44414552 0x000a0d59
  93. 40836610: 0x00000000 0x00000000 0xa5a5a500 0xa5a5a500 0x0000003d 0x00000035 0x0000009c 0x0000009d
  94. 40836630: 0x0000009e 0x0000009f 0x00000000 0xbadeb3aa 0x784d1c12 0x5e3fcd1f 0xb9cdd3cb 0x00000002
  95. 40836650: 0x00000000 0x00000030 0x00002710 0x4cf40020 0x2f21f858 0x4cf6d6d0 0xe537f9b5 0xc7d208d6
  96. 40836670: 0x905b5568 0x020a61f7 0x03525ce8 0x0000e403 0x4213949c 0x40836a4c 0x00000303 0x00000303
  97. 0x4213949c: mbedtls_entropy_func at C:/Users/kelka/esp/v5.1.3/esp-idf/components/mbedtls/mbedtls/library/entropy.c:285
  98.  
  99. 40836690: 0x00010000 0x00010100 0x00000101 0x40836620 0x00000000 0x00000000 0x42134fdc 0x4083663c
  100. 0x42134fdc: mbedtls_ctr_drbg_random at C:/Users/kelka/esp/v5.1.3/esp-idf/components/mbedtls/mbedtls/library/ctr_drbg.c:585
  101.  
  102. 408366b0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  103. 408366d0: 0x00000000 0x00000000 0x421e8e30 0x4082ca88 0x40836714 0x00000000 0x408189c8 0x408189f0
  104. 408366f0: 0x00000000 0x00000000 0x00000010 0xffff0000 0xffffffff 0x00000000 0x00000000 0x00000000
  105. 40836710: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  106. 40836730: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  107. 40836750: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  108. 40836770: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  109. 40836790: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  110. 408367b0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  111. 408367d0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  112. 408367f0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  113. 40836810: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  114. 40836830: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  115. 40836850: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  116. 40836870: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  117. 40836890: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  118. 408368b0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  119. 408368d0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  120. 408368f0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  121. 40836910: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
  122.  
  123.  
  124.  
  125. ELF file SHA256: 655cc31654f76458
  126.  
  127. Rebooting in  3 seconds...

Who is online

Users browsing this forum: No registered users and 86 guests