esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
292 stars 36 forks source link

assert failed: block_trim_free tlsf.c:496 (block_is_free(block) && "block must be free") #4845

Closed srikanthpalvai closed 10 months ago

srikanthpalvai commented 1 year ago

The problem

I am working on esp32-s3 device, I have integrated with wifi sta and cdc_acm_host I am not sure in between the application flow intermittently i am getting this error I have cross checked all the memory allocation using NEW and malloc.

Here is the main loop

extern "C" void app_main(void) { usb_host_power_init(); //Initialize NVS TODO first boot is crashing, Yet to check this issue esp_err_t nfret = nvs_flash_init(); if (nfret == ESP_ERR_NVS_NO_FREE_PAGES || nfret == ESP_ERR_NVS_NEW_VERSION_FOUND) { ESP_ERROR_CHECK(nvs_flash_erase()); nfret = nvs_flash_init(); } ESP_ERROR_CHECK(nfret);

ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
ESP_LOGI(TAG, "After nvs [APP] Free memory: %lu bytes Internal %lu", esp_get_free_heap_size(), esp_get_free_internal_heap_size());

wifi_init_sta();
vTaskDelay(500);
usbInstall(); //here i will open the cdc_acm_host_open_vendor_specific()
vTaskDelay(500);

xTaskCreatePinnedToCore(MyTask, "MyTask", 16384, NULL,10, &myTaskHandle, 1); 

}

* Here is the core dump ***

length is 474 I (50959) sockets: write to socket...Start

assert failed: block_trim_free tlsf.c:496 (block_is_free(block) && "block must be free")

Backtrace: 0x40375fea:0x3fcb5500 0x4037d72d:0x3fcb5520 0x40384449:0x3fcb5540 0x40383410:0x3fcb5660 0x40382d56:0x3fcb5680 0x403762cd:0x3fcb56a0 0x4037632d:0x3fcb56c0 0x40376d49:0x3fcb56e0 0x40376f49:0x3fcb5760 0x40379efd:0x3fcb5780 0x4003ec95:0x3fcb57a0 |<-CORRUPTED 0x40375fea: panic_abort at /home/lab/esp/esp-idf/components/esp_system/panic.c:423

0x4037d72d: esp_system_abort at /home/lab/esp/esp-idf/components/esp_system/esp_system.c:153

0x40384449: __assert_func at /home/lab/esp/esp-idf/components/newlib/assert.c:78

0x40383410: block_trim_free at /home/lab/esp/esp-idf/components/heap/tlsf/tlsf.c:496 (inlined by) block_prepare_used at /home/lab/esp/esp-idf/components/heap/tlsf/tlsf.c:579 (inlined by) tlsf_malloc at /home/lab/esp/esp-idf/components/heap/tlsf/tlsf.c:1005

0x40382d56: multi_heap_malloc_impl at /home/lab/esp/esp-idf/components/heap/multi_heap.c:207

0x403762cd: heap_caps_malloc_base at /home/lab/esp/esp-idf/components/heap/heap_caps.c:167

0x4037632d: heap_caps_malloc at /home/lab/esp/esp-idf/components/heap/heap_caps.c:187

0x40376d49: trace_malloc at /home/lab/esp/esp-idf/components/heap/include/heap_trace.inc:95

0x40376f49: __wrap_heap_caps_malloc at /home/lab/esp/esp-idf/components/heap/include/heap_trace.inc:184

0x40379efd: malloc_internal_wrapper at /home/lab/esp/esp-idf/components/esp_wifi/esp32s3/esp_adapter.c:557

ELF file SHA256: 8249d26b8899892f

Initiating core dump! I (24196) esp_core_dump_uart: Press Enter to print core dump to UART... I (24203) esp_core_dump_uart: Print core dump to uart... Core dump started (further output muted) Received 35 kB... Core dump finished!

==================== ESP32 CORE DUMP START ====================

Crashed task handle: 0x3fcb5b24, name: 'wifi', GDB name: 'process 1070291748'

================== CURRENT THREAD REGISTERS =================== exccause 0x1d (StoreProhibitedCause) excvaddr 0x0 epc1 0x4037c347 epc2 0x0 epc3 0x0 epc4 0x0 epc5 0x0 epc6 0x0 eps2 0x0 eps3 0x0 eps4 0x0 eps5 0x0 eps6 0x0 pc 0x40375fed 0x40375fed <panic_abort+21> lbeg 0x40056f08 1074097928 lend 0x40056f12 1074097938 lcount 0x0 0 sar 0x10 16 ps 0x60723 395043 threadptr br scompare1 acclo acchi m0 m1 m2 m3 expstate f64r_lo f64r_hi f64s fcr fsr a0 0x8037d730 -2143824080 a1 0x3fcb5500 1070290176 a2 0x3fcb554b 1070290251 a3 0x2 2 a4 0xa 10 a5 0x60923 395555 a6 0x60023 393251 a7 0xcdcd 52685 a8 0x0 0 a9 0x1 1 a10 0x3fcb5613 1070290451 a11 0x3fcb5613 1070290451 a12 0x3fcb5613 1070290451 a13 0xe60bcee8 -435433752 a14 0x0 0 a15 0xcdcd 52685

==================== CURRENT THREAD STACK =====================

0 0x40375fed in panic_abort (details=0x3fcb554b \"assert failed: block_trim_free tlsf.c:496 (block_is_free(block) && \\"block must be free\\")\") at /home/lab/esp/esp-idf/components/esp_system/panic.c:423

1 0x4037d730 in esp_system_abort (details=0x3fcb554b \"assert failed: block_trim_free tlsf.c:496 (block_is_free(block) && \\"block must be free\\")\") at /home/lab/esp/esp-idf/components/esp_system/esp_system.c:153

2 0x4038444c in __assert_func (file=0x3c0f19e7 \"tlsf.c\", line=, func=, expr=0x3c0f1da8 \"block_is_free(block) && \\"block must be free\\"\") at /home/lab/esp/esp-idf/components/newlib/assert.c:78

3 0x40383413 in block_trim_free (size=124, block=, control=0x3fca3ca4) at /home/lab/esp/esp-idf/components/heap/tlsf/tlsf.c:496

4 block_prepare_used (size=124, block=, control=0x3fca3ca4) at /home/lab/esp/esp-idf/components/heap/tlsf/tlsf.c:579

5 tlsf_malloc (tlsf=0x3fca3ca4, size=) at /home/lab/esp/esp-idf/components/heap/tlsf/tlsf.c:1005

6 0x40382d59 in multi_heap_malloc_impl (heap=0x3fca3c90, size=124) at /home/lab/esp/esp-idf/components/heap/multi_heap.c:207

7 0x403762d0 in heap_caps_malloc_base (size=124, caps=2060) at /home/lab/esp/esp-idf/components/heap/heap_caps.c:167

8 0x40376330 in heap_caps_malloc (size=124, caps=2060) at /home/lab/esp/esp-idf/components/heap/heap_caps.c:187

9 0x40376d4c in trace_malloc (size=124, caps=2060, mode=TRACE_MALLOC_CAPS) at /home/lab/esp/esp-idf/components/heap/include/heap_trace.inc:95

10 0x40376f4c in __wrap_heap_caps_malloc (size=124, caps=2060) at /home/lab/esp/esp-idf/components/heap/include/heap_trace.inc:184

11 0x40379f00 in malloc_internal_wrapper (size=124) at /home/lab/esp/esp-idf/components/esp_wifi/esp32s3/esp_adapter.c:557

12 0x4003ec98 in ?? ()

13 0x4003ee9e in ?? ()

14 0x400398b8 in ?? ()

15 0x420855e0 in ieee80211_getmgtframe ()

16 0x4207aa20 in ieee80211_encap_null_data ()

17 0x4207aaf3 in ieee80211_pm_tx_null_process ()

18 0x4208730c in pm_send_nullfunc ()

19 0x42087ff5 in pm_tx_data_process ()

20 0x42088304 in pm_on_data_tx ()

21 0x420e5db0 in ppMapTxQueue ()

22 0x4003d7b6 in ?? ()

23 0x40039b1c in ?? ()

24 0x420e5ff8 in ppTask ()

25 0x40381220 in vPortTaskWrapper (pxCode=0x420e5f3c , pvParameters=0x0) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154

======================== THREADS INFO ========================= Id Target Id Frame

==================== THREAD 1 (TCB: 0x3fcb5b24, name: 'wifi') =====================

0 0x40375fed in panic_abort (details=0x3fcb554b \"assert failed: block_trim_free tlsf.c:496 (block_is_free(block) && \\"block must be free\\")\") at /home/lab/esp/esp-idf/components/esp_system/panic.c:423

1 0x4037d730 in esp_system_abort (details=0x3fcb554b \"assert failed: block_trim_free tlsf.c:496 (block_is_free(block) && \\"block must be free\\")\") at /home/lab/esp/esp-idf/components/esp_system/esp_system.c:153

2 0x4038444c in __assert_func (file=0x3c0f19e7 \"tlsf.c\", line=, func=, expr=0x3c0f1da8 \"block_is_free(block) && \\"block must be free\\"\") at /home/lab/esp/esp-idf/components/newlib/assert.c:78

3 0x40383413 in block_trim_free (size=124, block=, control=0x3fca3ca4) at /home/lab/esp/esp-idf/components/heap/tlsf/tlsf.c:496

4 block_prepare_used (size=124, block=, control=0x3fca3ca4) at /home/lab/esp/esp-idf/components/heap/tlsf/tlsf.c:579

5 tlsf_malloc (tlsf=0x3fca3ca4, size=) at /home/lab/esp/esp-idf/components/heap/tlsf/tlsf.c:1005

6 0x40382d59 in multi_heap_malloc_impl (heap=0x3fca3c90, size=124) at /home/lab/esp/esp-idf/components/heap/multi_heap.c:207

7 0x403762d0 in heap_caps_malloc_base (size=124, caps=2060) at /home/lab/esp/esp-idf/components/heap/heap_caps.c:167

8 0x40376330 in heap_caps_malloc (size=124, caps=2060) at /home/lab/esp/esp-idf/components/heap/heap_caps.c:187

9 0x40376d4c in trace_malloc (size=124, caps=2060, mode=TRACE_MALLOC_CAPS) at /home/lab/esp/esp-idf/components/heap/include/heap_trace.inc:95

10 0x40376f4c in __wrap_heap_caps_malloc (size=124, caps=2060) at /home/lab/esp/esp-idf/components/heap/include/heap_trace.inc:184

11 0x40379f00 in malloc_internal_wrapper (size=124) at /home/lab/esp/esp-idf/components/esp_wifi/esp32s3/esp_adapter.c:557

12 0x4003ec98 in ?? ()

13 0x4003ee9e in ?? ()

14 0x400398b8 in ?? ()

15 0x420855e0 in ieee80211_getmgtframe ()

16 0x4207aa20 in ieee80211_encap_null_data ()

17 0x4207aaf3 in ieee80211_pm_tx_null_process ()

18 0x4208730c in pm_send_nullfunc ()

19 0x42087ff5 in pm_tx_data_process ()

20 0x42088304 in pm_on_data_tx ()

21 0x420e5db0 in ppMapTxQueue ()

22 0x4003d7b6 in ?? ()

23 0x40039b1c in ?? ()

24 0x420e5ff8 in ppTask ()

25 0x40381220 in vPortTaskWrapper (pxCode=0x420e5f3c , pvParameters=0x0) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154

==================== THREAD 2 (TCB: 0x3fcbf614, name: 'FetchPendingMes') =====================

0 0x400559e0 in ?? ()

Backtrace stopped: Cannot access memory at address 0xfffffff3

==================== THREAD 3 (TCB: 0x3fcafc14, name: 'IDLE') =====================

0 0x4037c342 in esp_cpu_wait_for_intr () at /home/lab/esp/esp-idf/components/esp_hw_support/cpu.c:110

1 0x42005091 in esp_vApplicationIdleHook () at /home/lab/esp/esp-idf/components/esp_system/freertos_hooks.c:59

2 0x4037eed4 in prvIdleTask (pvParameters=0x0) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:4157

3 0x40381220 in vPortTaskWrapper (pxCode=0x4037eec8 , pvParameters=0x0) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154

==================== THREAD 4 (TCB: 0x3fcad39c, name: 'IDLE') =====================

0 0x4037c342 in esp_cpu_wait_for_intr () at /home/lab/esp/esp-idf/components/esp_hw_support/cpu.c:110

1 0x42005091 in esp_vApplicationIdleHook () at /home/lab/esp/esp-idf/components/esp_system/freertos_hooks.c:59

2 0x4037eed4 in prvIdleTask (pvParameters=0x0) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:4157

3 0x40381220 in vPortTaskWrapper (pxCode=0x4037eec8 , pvParameters=0x0) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154

==================== THREAD 5 (TCB: 0x3fcb1ff4, name: 'tiT') =====================

0 xQueueReceive (xQueue=0x3fcb1110, pvBuffer=0x3fcb1e50, xTicksToWait=) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/queue.c:1407

1 0x4204f94e in sys_arch_mbox_fetch (mbox=, msg=0x3fcb1e50, timeout=) at /home/lab/esp/esp-idf/components/lwip/port/esp32/freertos/sys_arch.c:341

2 0x4203deaf in tcpip_timeouts_mbox_fetch (mbox=0x3fc9f248 , msg=0x3fcb1e50) at /home/lab/esp/esp-idf/components/lwip/lwip/src/api/tcpip.c:104

3 0x4203df71 in tcpip_thread (arg=0x0) at /home/lab/esp/esp-idf/components/lwip/lwip/src/api/tcpip.c:142

4 0x40381220 in vPortTaskWrapper (pxCode=0x4203df50 , pvParameters=0x0) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154

==================== THREAD 6 (TCB: 0x3fca517c, name: 'ipc0') =====================

0 0x4037e7bc in xQueueSemaphoreTake (xQueue=0x3fc9a6b8 , xTicksToWait=) at /home/lab/esp/esp-idf/components/xtensa/include/xt_utils.h:40

1 0x40379de8 in ipc_task (arg=0x0) at /home/lab/esp/esp-idf/components/esp_system/esp_ipc.c:64

2 0x40381220 in vPortTaskWrapper (pxCode=0x40379db8 , pvParameters=0x0) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154

==================== THREAD 7 (TCB: 0x3fcb057c, name: 'Tmr Svc') =====================

0 0x40380fc3 in prvProcessTimerOrBlockTask (xNextExpireTime=, xListWasEmpty=1) at /home/lab/esp/esp-idf/components/xtensa/include/xt_utils.h:40

1 0x40381113 in prvTimerTask (pvParameters=0x0) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/timers.c:604

2 0x40381220 in vPortTaskWrapper (pxCode=0x40381104 , pvParameters=0x0) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154

==================== THREAD 8 (TCB: 0x3fca57e4, name: 'ipc1') =====================

0 xQueueSemaphoreTake (xQueue=0x3fc9a714 <s_ipc_sem_buffer+92>, xTicksToWait=) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/queue.c:1570

1 0x40379de8 in ipc_task (arg=0x1) at /home/lab/esp/esp-idf/components/esp_system/esp_ipc.c:64

2 0x40381220 in vPortTaskWrapper (pxCode=0x40379db8 , pvParameters=0x1) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154

==================== THREAD 9 (TCB: 0x3fcb2f98, name: 'sys_evt') =====================

0 0x4037e63d in xQueueReceive (xQueue=0x3fcb21d4, pvBuffer=0x3fcb2dd0, xTicksToWait=) at /home/lab/esp/esp-idf/components/xtensa/include/xt_utils.h:40

1 0x420e80a8 in esp_event_loop_run (event_loop=0x3fcb21b8, ticks_to_run=4294967295) at /home/lab/esp/esp-idf/components/esp_event/esp_event.c:558

2 0x420e80db in esp_event_loop_run_task (args=0x3fcb21b8) at /home/lab/esp/esp-idf/components/esp_event/esp_event.c:107

3 0x40381220 in vPortTaskWrapper (pxCode=0x420e80b4 , pvParameters=0x3fcb21b8) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154

==================== THREAD 10 (TCB: 0x3fcbbec8, name: 'usb_lib') =====================

0 0x4037e7bc in xQueueSemaphoreTake (xQueue=0x3fcbb874, xTicksToWait=) at /home/lab/esp/esp-idf/components/xtensa/include/xt_utils.h:40

1 0x4202f670 in usb_host_lib_handle_events (timeout_ticks=4294967295, event_flags_ret=0x3fcbd0e8) at /home/lab/esp/esp-idf/components/usb/usb_host.c:498

2 0x4202ae91 in usb_lib_task ()

3 0x40381220 in vPortTaskWrapper (pxCode=0x4202ae80 , pvParameters=0x3fcaab24) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154

==================== THREAD 11 (TCB: 0x3fcbe2ec, name: 'USB-CDC') =====================

0 0x4037e7bc in xQueueSemaphoreTake (xQueue=0x3fcbe498, xTicksToWait=) at /home/lab/esp/esp-idf/components/xtensa/include/xt_utils.h:40

1 0x4202f984 in usb_host_client_handle_events (client_hdl=0x3fcbe450, timeout_ticks=4294967295) at /home/lab/esp/esp-idf/components/usb/usb_host.c:730

2 0x4202b52e in cdc_acm_client_task ()

3 0x40381220 in vPortTaskWrapper (pxCode=0x4202b4e0 , pvParameters=0x0) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154

==================== THREAD 12 (TCB: 0x3fca9594, name: 'esp_timer') =====================

0 0x400559e0 in ?? ()

1 0x4038151a in vPortClearInterruptMaskFromISR (prev_level=) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:566

2 vPortExitCritical (mux=) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:342

3 0x403804a5 in ulTaskGenericNotifyTake (uxIndexToWait=0, xClearCountOnExit=1, xTicksToWait=) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:5564

4 0x42009397 in timer_task (arg=0x0) at /home/lab/esp/esp-idf/components/esp_timer/src/esp_timer.c:430

5 0x40381220 in vPortTaskWrapper (pxCode=0x42009388 , pvParameters=0x0) at /home/lab/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154

======================= ALL MEMORY REGIONS ======================== Name Address Size Attrs .rtc.force_fast 0x600fe010 0x0 RW
.rtc.force_slow 0x50000010 0x0 RW
.iram0.vectors 0x40374000 0x403 R XA .iram0.text 0x40374404 0x121b3 R XA .dram0.data 0x3fc96600 0x5994 RW A .noinit 0x3fc9bf94 0x0 RW
.flash.text 0x42000020 0xe996b R XA .flash.appdesc 0x3c0f0020 0x100 R A .flash.rodata 0x3c0f0120 0x52f3c RW A .ext_ram.bss 0x3c150000 0x0 RW
.iram0.data 0x40386600 0x0 RW
.iram0.bss 0x40386600 0x0 RW
.dram0.heap_start 0x3fca3c90 0x0 RW
.coredump.tasks.data 0x3fcb5b24 0x160 RW .coredump.tasks.data 0x3fcb5440 0x6d0 RW .coredump.tasks.data 0x3fcbf614 0x160 RW .coredump.tasks.data 0x3fcc22c0 0x1550 RW .coredump.tasks.data 0x3fcafc14 0x160 RW .coredump.tasks.data 0x3fcaf980 0x280 RW .coredump.tasks.data 0x3fcad39c 0x160 RW .coredump.tasks.data 0x3fcad110 0x280 RW .coredump.tasks.data 0x3fcb1ff4 0x160 RW .coredump.tasks.data 0x3fcb1d00 0x2e0 RW .coredump.tasks.data 0x3fca517c 0x160 RW .coredump.tasks.data 0x3fca4ef0 0x280 RW .coredump.tasks.data 0x3fcb057c 0x160 RW .coredump.tasks.data 0x3fcb02f0 0x280 RW .coredump.tasks.data 0x3fca57e4 0x160 RW .coredump.tasks.data 0x3fca5550 0x280 RW .coredump.tasks.data 0x3fcb2f98 0x160 RW .coredump.tasks.data 0x3fcb2cc0 0x2d0 RW .coredump.tasks.data 0x3fcbbec8 0x160 RW .coredump.tasks.data 0x3fcbcfc0 0x2c0 RW .coredump.tasks.data 0x3fcbe2ec 0x160 RW .coredump.tasks.data 0x3fcbe010 0x2d0 RW .coredump.tasks.data 0x3fca9594 0x160 RW .coredump.tasks.data 0x3fca92f0 0x290 RW

===================== ESP32 CORE DUMP END =====================

Done! Coredump checksum='2ddf2a53' I (577) esp_core_dump_uart: Core dump has been written to uart.

Which version of ESPHome has the issue?

ESP-IDF v5.0.2-dirty

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

No response

What platform are you using?

ESP32-IDF

Board

esp32-s3 OTG

Component causing the issue

wifi and USB host handler

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

github-actions[bot] commented 11 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.