求助,tlsf_malloc引起的kernel panic

wenbozzz
Posts: 5
Joined: Tue Jun 15, 2021 9:53 am

求助,tlsf_malloc引起的kernel panic

Postby wenbozzz » Tue Jun 15, 2021 10:29 am

芯片:ESP32-WROVER-B
IDF版本:release/v4.3
开发环境:Windows

各位好,
我在开发时遇到一个错误,貌似是和内存管理相关的,
每次都是0x4008a02f: block_locate_free at C:/Users/wenbo/workspace/nn/esp-idf-v4.3/components/heap/heap_tlsf.c:447之后assert条件不满足然后导致了kernel panic

但这又不像是内存不足导致的,
因为在这之前通过heap_caps_get_free_size()看到 MALLOC_CAP_8BIT有347 kB,MALLOC_CAP_32BIT有268 kB
这个vector里面也就只有两个元素,每个元素就是一个pointer而已

求教.. 这是我第一次用esp32和在rtos上开发,请问这个错误大概是由什么导致的?

Backtrace如下:

Code: Select all

abort() was called at PC 0x4008280b on core 0
0x4008280b: lock_acquire_generic at C:/Users/wenbo/workspace/nn/esp-idf-v4.3/components/newlib/locks.c:138


Backtrace:0x40085a73:0x3ffb72a0 0x40086199:0x3ffb72c0 0x4008ae3e:0x3ffb72e0 0x4008280b:0x3ffb7350 0x40082955:0x3ffb7380 0x4010929d:0x3ffb73a0 0x40100c39:0x3ffb7660 0x40100b11:0x3ffb76b0 0x4008a02f:0x3ffb76e0 0x4008ab57:0x3ffb7700 0x40081771:0x3ffb7720 0x400817a5:0x3ffb7740 0x4008ae49:0x3ffb7760 0x400e3f4a:0x3ffb7780 0x400d9837:0x3ffb77a0 0x400da742:0x3ffb77c0 0x400dba2e:0x3ffb7820 0x400d845d:0x3ffb78b0 0x400d8935:0x3ffb79f0 0x4011ce61:0x3ffb7a10 0x40088b01:0x3ffb7a30
0x40085a73: panic_abort at C:/Users/wenbo/workspace/nn/esp-idf-v4.3/components/esp_system/panic.c:356

0x40086199: esp_system_abort at C:/Users/wenbo/workspace/nn/esp-idf-v4.3/components/esp_system/system_api.c:112

0x4008ae3e: abort at C:/Users/wenbo/workspace/nn/esp-idf-v4.3/components/newlib/abort.c:46

0x4008280b: lock_acquire_generic at C:/Users/wenbo/workspace/nn/esp-idf-v4.3/components/newlib/locks.c:138

0x40082955: _lock_acquire_recursive at C:/Users/wenbo/workspace/nn/esp-idf-v4.3/components/newlib/locks.c:166

0x4010929d: _vfiprintf_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:853 (discriminator 2)

0x40100c39: fiprintf at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/fiprintf.c:48

0x40100b11: __assert_func at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdlib/assert.c:58 (discriminator 8)

0x4008a02f: block_locate_free at C:/Users/wenbo/workspace/nn/esp-idf-v4.3/components/heap/heap_tlsf.c:447
 (inlined by) tlsf_malloc at C:/Users/wenbo/workspace/nn/esp-idf-v4.3/components/heap/heap_tlsf.c:757

0x4008ab57: multi_heap_malloc_impl at C:/Users/wenbo/workspace/nn/esp-idf-v4.3/components/heap/multi_heap.c:197

0x40081771: heap_caps_malloc at C:/Users/wenbo/workspace/nn/esp-idf-v4.3/components/heap/heap_caps.c:145

0x400817a5: heap_caps_malloc_default at C:/Users/wenbo/workspace/nn/esp-idf-v4.3/components/heap/heap_caps.c:177

0x4008ae49: malloc at C:/Users/wenbo/workspace/nn/esp-idf-v4.3/components/newlib/heap.c:31

0x400e3f4a: operator new(unsigned int) at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/new_op.cc:50

0x400d9837: std::vector<MyNode*, std::allocator<MyNode*> >::operator=(std::vector<MyNode*, std::allocator<MyNode*> > const&) at c:\users\wenbo\.espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\8.4.0\ext/new_allocator.h:111
 (inlined by) ?? at c:\users\wenbo\.espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\8.4.0\bits/alloc_traits.h:436
 (inlined by) ?? at c:\users\wenbo\.espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\8.4.0\bits/stl_vector.h:296
 (inlined by) ?? at c:\users\wenbo\.espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\8.4.0\bits/stl_vector.h:1398
 (inlined by) std::vector<MyNode*, std::allocator<MyNode*> >::operator=(std::vector<MyNode*, std::allocator<MyNode*> > const&) at c:\users\wenbo\.espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\8.4.0\bits/vector.tcc:214

0x400da742: LayoutDetection::parseLayoutDetectionMessage(unsigned char const*, unsigned short) at c:\users\wenbo\workspace\nn\esp-idf-v4.3\projects\layout_detect_demo\build/../components/layout_detection/src/LayoutDetection.cpp:530

0x400dba2e: LayoutDetection::performLayoutDetection() at c:\users\wenbo\workspace\nn\esp-idf-v4.3\projects\layout_detect_demo\build/../components/layout_detection/src/LayoutDetection.cpp:663

0x400d845d: testLayoutDetection() at c:\users\wenbo\workspace\nn\esp-idf-v4.3\projects\layout_detect_demo\build/../main/main.cpp:75

0x400d8935: app_main at c:\users\wenbo\workspace\nn\esp-idf-v4.3\projects\layout_detect_demo\build/../main/main.cpp:180 (discriminator 1)

0x4011ce61: main_task at C:/Users/wenbo/workspace/nn/esp-idf-v4.3/components/freertos/port/port_common.c:133 (discriminator 2)

0x40088b01: vPortTaskWrapper at C:/Users/wenbo/workspace/nn/esp-idf-v4.3/components/freertos/port/xtensa/port.c:168
bootup的log如下

Code: Select all

I (27) boot: ESP-IDF v4.3-dirty 2nd stage bootloader
I (27) boot: compile time 17:25:36
I (27) boot: chip revision: 1
I (30) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (37) boot.esp32: SPI Speed      : 40MHz
I (42) boot.esp32: SPI Mode       : DIO
I (46) boot.esp32: SPI Flash Size : 2MB
I (51) boot: Enabling RNG early entropy source...
I (56) boot: Partition Table:
I (60) boot: ## Label            Usage          Type ST Offset   Length
I (67) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (75) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (82) boot:  2 factory          factory app      00 00 00010000 00100000
I (90) boot: End of partition table
I (94) boot_comm: chip revision: 1, min. application chip revision: 0
I (101) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=20b58h (133976) map
I (160) esp_image: segment 1: paddr=00030b80 vaddr=3ffb0000 size=029fch ( 10748) load
I (165) esp_image: segment 2: paddr=00033584 vaddr=40080000 size=0bdech ( 48620) load
I (187) esp_image: segment 3: paddr=0003f378 vaddr=50000000 size=00010h (    16) load
I (187) esp_image: segment 4: paddr=0003f390 vaddr=00000000 size=00c88h (  3208)
I (193) esp_image: segment 5: paddr=00040020 vaddr=400d0020 size=4d108h (315656) map
I (326) boot: Loaded app from partition at offset 0x10000
I (326) boot: Disabling RNG early entropy source...
I (338) cpu_start: Pro cpu up.
I (338) cpu_start: Starting app cpu, entry point is 0x40081268
0x40081268: call_start_cpu1 at C:/Users/wenbo/workspace/nanoleaf/esp-idf-v4.3/components/esp_system/port/cpu_start.c:141

I (325) cpu_start: App cpu up.
I (352) cpu_start: Pro cpu start user code
I (353) cpu_start: cpu freq: 160000000
I (353) cpu_start: Application information:
I (357) cpu_start: Project name:     main
I (362) cpu_start: App version:      2a4cb94-dirty
I (367) cpu_start: Compile time:     Jun 15 2021 17:25:19
I (373) cpu_start: ELF file SHA256:  6167980a57b10dcc...
I (379) cpu_start: ESP-IDF:          v4.3-dirty
I (385) heap_init: Initializing. RAM available for dynamic allocation:
I (392) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (398) heap_init: At 3FFB4BD0 len 0002B430 (173 KiB): DRAM
I (404) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (410) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (417) heap_init: At 4008BDEC len 00014214 (80 KiB): IRAM
I (424) spi_flash: detected chip: gd
I (427) spi_flash: flash io: dio
W (431) spi_flash: Detected size(16384k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (449) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.

ESP_Gargamel
Posts: 786
Joined: Wed Nov 14, 2018 8:45 am

Re: 求助,tlsf_malloc引起的kernel panic

Postby ESP_Gargamel » Wed Jun 16, 2021 8:58 am

不确定是否是内存有被破坏,能否先使用 https://docs.espressif.com/projects/esp ... debug.html 提供的方法,做一些 debug。
或者提供一个复现问题的最小工程。

Who is online

Users browsing this forum: No registered users and 76 guests