Closed developer-ken closed 1 month ago
Please provide a minimal example that can be compiled and demonstrate the error. Your backtrace looks a lot like an out of memory error while the SD card is initializing, and doesn't seem to have anything to do with file access.
Thanks a lot for your effort helping.
I've changed the code a little bit and get a more related stack trace.
So when /test1.txt
exists, it works just fine. I verified that text is written into that file. But when I delete /test1.txt
in the card and run that again, I got a crash.
https://github.com/developer-ken/SCIRecorderFirmware/blob/e5017fb963ef7481c5ad1c354b4d5019cdc0e817/src/main.cpp#L116
23:42:10.801 > Backtrace: 0x4008f855:0x3ffb2010 0x4008fec3:0x3ffb2030 0x40090000:0x3ffb2050 0x40084114:0x3ffb2070 0x400841e3:0x3ffb20a0 0x400e6899:0x3ffb20f0 0x400e6fe4:0x3ffb2110 0x400e07b6:0x3ffb2140 0x400ee4ce:0x3ffb2160 0x400d25c2:0x3ffb21f0 0x400d1e1d:0x3ffb2220 0x400d721e:0x3ffb2290
23:42:10.801 > #0 0x4008f855 in block_locate_free at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_tlsf.c:439
23:42:10.801 > (inlined by) tlsf_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_tlsf.c:850
23:42:10.801 > #1 0x4008fec3 in multi_heap_malloc_impl at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap.c:187
23:42:10.801 > #2 0x40090000 in multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c:234
23:42:10.801 > (inlined by) multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c:223
23:42:10.801 > #3 0x40084114 in heap_caps_malloc_base at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c:175
23:42:10.801 > (inlined by) heap_caps_malloc_base at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c:120
23:42:10.801 > #4 0x400841e3 in heap_caps_malloc_prefer at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c:290
23:42:10.801 > #5 0x400e6899 in ff_memalloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/fatfs/port/freertos/ffsystem.c:20
23:42:10.801 > #6 0x400e6fe4 in vfs_fat_opendir at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/fatfs/vfs/vfs_fat.c:733
23:42:10.801 > #7 0x400e07b6 in esp_vfs_opendir at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/vfs/vfs.c:659 (discriminator 3)
23:42:10.801 > #8 0x400ee4ce in VFSImpl::open(char const*, char const*, bool) at C:/Users/dengb/.platformio/packages/framework-arduinoespressif32/libraries/FS/src/vfs_api.cpp:54
23:42:10.801 > #9 0x400d25c2 in fs::FS::open(char const*, char const*, bool) at C:/Users/dengb/.platformio/packages/framework-arduinoespressif32/libraries/FS/src/FS.cpp:234
23:42:10.801 > #10 0x400d1e1d in setup() at src/main.cpp:116
23:42:10.801 > #11 0x400d721e in loopTask(void*) at C:/Users/dengb/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:42
If those information is not useful, I may write a minimal schetch to reproduce the problem at weekend.
Still looks like a memory error. Can you disable psram and see if you get the same issue? Check your memory availability with ESP.getMaxAllocHeap() before the file write.
Thanks for your info. Disabling psram works.
With psram enabled , I add a line to print ESP.getMaxAllocHeap()
:
18:14:36.748 > Build Sep 12 2024 18:14:08
18:14:36.748 > ===================================
18:14:36.748 > Mounting SD card...
18:14:36.762 > SD card mounted:
18:14:36.762 > - Type: 3
18:14:36.762 > - Size: 7761920
18:14:36.762 > - Used: 96
18:14:36.762 > Heap: 114676
18:14:36.809 > Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
...Same crash stack...
I disabled psram by
build_unflags =
-DBOARD_HAS_PSRAM
and it works just fine.
18:20:42.824 > ===================================
18:20:42.824 > Mounting SD card...
18:20:43.057 > SD card mounted:
18:20:43.057 > - Type: 3
18:20:43.057 > - Size: 7761920
18:20:43.057 > - Used: 96
18:20:43.057 > Heap: 110580
What can be the problem here?
Something with how the psram is implemented in pico. @P-R-O-C-H-Y @SuGlider Do you have a pico-v3-02 device available to test this?
@developer-ken which pins are you using?
pins 6-11 are not available for use by the SD card, they are used by the flash card. Use different pins
I have got only pico-v3-zero here without PSRAM unfortunately.
I double checked and find out I used the pin connected internally to psram for SD card SPI. I've already made a PCB with the wrong pin config so I have to use the chip without psram now. Maybe change the BOM to use pico-v3-zero, as I have to disable psram anyway.
Its my fault not checking pin configuration carefully before odering a PCB. It's confusing me that ESP32-PICO chips have those internally connected pins wired out.
Anyway, thanks for you guys helping solving this problem. I will close this issue.
Board
ESP32-PICO-V3-02
Device Description
Custom made PCB with a ESP32-PICO-V3-02 and a TF card slot. Since both reading and writing exsisting files works fine, I don't think it is a hardware problem.
IDE Name
PlatformIO
Operating System
Windows11
Description
Open an exists file on sd card for writing, reading or appending works just fine. But when I want to create some file/dir, just crashed.
For example, when "/test1.txt" does not exists, it crashes. When it exists, code works fine and content is actually written to the file.
Sketch
Debug Message
Crash:
No crash: