ivmarkov / rust-esp32-std-demo

Rust on ESP32 STD demo app. A demo STD binary crate for the ESP32[XX] and ESP-IDF, which connects to WiFi, Ethernet, drives a small HTTP server and draws on a LED screen.
Apache License 2.0
785 stars 105 forks source link

Abort while spawning threads in demo on TTGO board #49

Closed questmaster closed 2 years ago

questmaster commented 2 years ago

I compiled the demo with the following call:

cargo build --features ttgo --target xtensa-esp32-espidf

Building and flashing went well. when monitoring the serial connection the following output shows a crash while threads are spawned/joined... In the demo code a patching of the IDF is mentioned could this be the culprit? Any idea what went wrong here?

Thanks!

espmonitor /dev/ttyUSB0

I (442) cpu_start: Pro cpu up.
I (442) cpu_start: Starting app cpu, entry point is 0x400825f4
I (436) cpu_start: App cpu up.
I (457) cpu_start: Pro cpu start user code
I (457) cpu_start: cpu freq: 160000000
I (457) cpu_start: Application information:
I (461) cpu_start: Project name:     esp-idf
I (466) cpu_start: App version:      b57bae0-dirty
I (472) cpu_start: Compile time:     Jan 10 2022 17:33:30
I (478) cpu_start: ELF file SHA256:  0000000000000000...
I (484) cpu_start: ESP-IDF:          4.3.1
I (489) heap_init: Initializing. RAM available for dynamic allocation:
I (496) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (502) heap_init: At 3FFB8308 len 00027CF8 (159 KiB): DRAM
I (508) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (514) heap_init: At 3FFE4350 len 0001BCB0 (111 KI (442) cpu_start: Pro cpu up.
I (442) cpu_start: Starting app cpu, entry point is 0x400825f4
I (436) cpu_start: App cpu up.
I (457) cpu_start: Pro cpu start user code
I (457) cpu_start: cpu freq: 160000000
I (457) cpu_start: Application information:
I (461) cpu_start: Project name:     esp-idf
I (466) cpu_start: App version:      b57bae0-dirty
I (472) cpu_start: Compile time:     Jan 10 2022 17:33:30
I (478) cpu_start: ELF file SHA256:  0000000000000000...
I (484) cpu_start: ESP-IDF:          4.3.1
I (489) heap_init: Initializing. RAM available for dynamic allocation:
I (496) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (502) heap_init: At 3FFB8308 len 00027CF8 (159 KiB): DRAM
I (508) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (514) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (521) heap_init: At 40097514 len 00008AEC (34 KiB): IRAM
I (528) spi_flash: detected chip: generic
I (532) spi_flash: flash io: dio
I (537) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
Hello from Rust!
More complex print ["foo", "bar"]
Result: 0, 1
Rust main thread: Thread { id: ThreadId(1), name: Some("main"), .. }
Main TLS before change: 13
Main TLS after change: 42
This is thread number 0, Thread { id: ThreadId(2), name: None, .. }
Inner TLS: 0
abort() was called at PC 0x4008390f on core 0
Backtrace:0x40089182:0x3ffbec00 0x400899b5:0x3ffbec20 0x40091b1a:0x3ffbec40 0x4008390f:0x3ffbecb0 0x40083a6d:0x3ffbece0 0x40083af1:0x3ffbed00 0x4016b235:0x3ffbed30 0x40166fe1:0x3ffbeff0 0x40166f69:0x3ffbf040 0x4008fadf:0x3ffbf070 0x40090456:0x3ffbf090 0x4008362a:0x3ffbf0b0 0x40091b45:0x3ffbf0d0 0x4012a4ab:0x3ffbf0f0 0x4012a56f:0x3ffbf110 0x40129fa3:0x3ffbf130 0x4012a073:0x3ffbf150 0x400
ivmarkov commented 2 years ago

To get some extra hints, you should try to decode the Backtrace: line and then paste the decoded call stack here.

You can use this online decoding utility (you need to paste there the "backtrace" line and upload your ELF file): https://maximeborges.github.io/esp-stacktrace-decoder/

questmaster commented 2 years ago

Cool, thanks for the hint.

The Output is the following:

    0x4008390f: lock_acquire_generic at /home/.../rust-esp32-std-hello/.embuild/platformio/packages/framework-espidf/components/newlib/locks.c:139
    0x40089182: panic_abort at /home/.../rust-esp32-std-hello/.embuild/platformio/packages/framework-espidf/components/esp_system/panic.c:368
    0x400899b5: esp_system_abort at /home/.../rust-esp32-std-hello/.embuild/platformio/packages/framework-espidf/components/esp_system/system_api.c:112
    0x40091b1a: abort at /home/.../rust-esp32-std-hello/.embuild/platformio/packages/framework-espidf/components/newlib/abort.c:46
    0x4008390f: lock_acquire_generic at /home/.../rust-esp32-std-hello/.embuild/platformio/packages/framework-espidf/components/newlib/locks.c:139
    0x40083a6d: _lock_acquire_recursive at /home/.../rust-esp32-std-hello/.embuild/platformio/packages/framework-espidf/components/newlib/locks.c:167
    0x40083af1: __retarget_lock_acquire_recursive at /home/.../rust-esp32-std-hello/.embuild/platformio/packages/framework-espidf/components/newlib/locks.c:323
    0x4016b235: _vfiprintf_r at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:853
    0x40166fe1: fiprintf at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/fiprintf.c:48
    0x40166f69: __assert_func at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdlib/assert.c:58
    0x4008fadf: tlsf_free at /home/.../rust-esp32-std-hello/.embuild/platformio/packages/framework-espidf/components/heap/heap_tlsf.c:866
    0x40090456: multi_heap_free_impl at /home/.../rust-esp32-std-hello/.embuild/platformio/packages/framework-espidf/components/heap/multi_heap.c:220
    0x4008362a: heap_caps_free at /home/.../rust-esp32-std-hello/.embuild/platformio/packages/framework-espidf/components/heap/heap_caps.c:305
    0x40091b45: free at /home/.../rust-esp32-std-hello/.embuild/platformio/packages/framework-espidf/components/newlib/heap.c:46
    0x4012a4ab: pthread_local_storage_thread_deleted_callback at /home/.../rust-esp32-std-hello/.embuild/platformio/packages/framework-espidf/components/pthread/pthread_local_storage.c:139
    0x4012a56f: pthread_internal_local_storage_destructor_callback at /home/.../rust-esp32-std-hello/.embuild/platformio/packages/framework-espidf/components/pthread/pthread_local_storage.c:173
    0x40129fa3: pthread_exit at /home/.../rust-esp32-std-hello/.embuild/platformio/packages/framework-espidf/components/pthread/pthread.c:427
    0x4012a073: pthread_task_func at /home/.../rust-esp32-std-hello/.embuild/platformio/packages/framework-espidf/components/pthread/pthread.c:212
    0x4008d3ed: vPortTaskWrapper at /home/.../rust-esp32-std-hello/.embuild/platformio/packages/framework-espidf/components/freertos/port/xtensa/port.c:168

So, stil looks like a problem from the fn test_threads() function.

Update

Ok, it is a problem inside the .embuild folder code and as I recently updated some of the tools including esp-idf, it seems to be an incompatibility here. So removing this folder and rebuilding solved the problem.

Thanks for the hint of the stracktrace decoding, that helped a lot...