Crash when using stack on external PSRAM

jsam589
Posts: 74
Joined: Sat Aug 17, 2019 9:31 pm

Crash when using stack on external PSRAM

Postby jsam589 » Wed Feb 02, 2022 9:59 pm

It seems that the IDF system components in 4.4 take up a lot more internal RAM than 4.0. I am using ESP32-WROVER-E (ECO v3) and I saw that v3 silicon should allow free use of the external PSRAM for task stacks.

viewtopic.php?t=21520

However, I get crashes if my task accesses flash (e.g. to write to a log file).

I use sdkconfig.defaults for explicit setting of all my CONFIG_ params. I won't show them all here, but the relevant ones are shown.

I also use static task creation.

What more must I do so that my task can be compatible with occasional flash accesses?

Code: Select all

CONFIG_ESP32_REV_MIN_3=y
CONFIG_ESP32_SPIRAM_SUPPORT=y
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=512
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
CONFIG_SPIRAM_USE_MALLOC=y
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y

pstk = heap_caps_malloc( stackSize, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT );
xTaskCreateStaticPinnedToCore()  CPU_CORE_ANY

When attempts to add to log file in SPIFFS, this crashes:

assert failed: spi_flash_disable_interrupts_caches_and_other_cpu cache_utils.c:136 (esp_task_stack_is_sane_cache_disabled())

Backtrace:0x4008229e:0x3f87f1700x40093cc1:0x3f87f190 0x40099601:0x3f87f1b0 0x4008d1f5:0x3f87f2d0 0x4008e47d:0x3f87f2f0 0x4008e487:0x3f87f310 0x40091d45:0x3f87f330 0x4008df41:0x3f87f350 0x40162673:0x3f87f390 0x401557c3:0x3f87f3c0 0x40158bbe:0x3f87f3f0 0x401568f7:0x3f87f420 0x40156c9c:0x3f87f480 0x40158127:0x3f87f4d0 0x40155cc1:0x3f87f510 0x401553d1:0x3f87f550 0x400d68fb:0x3f87f5a0 0x401cb3f4:0x3f87f5c0 0x401cb49d:0x3f87f5f0 0x400dbd79:0x3f87f610 0x401e615d:0x3f87f660 0x400993a1:0x3f87f690 0x400ddc1e:0x3f87f6e0 
0x4008229e: panic_abort at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/esp_system/panic.c:402

0x40093cc1: esp_system_abort at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/esp_system/esp_system.c:121

0x40099601: __assert_func at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/newlib/assert.c:85

0x4008d1f5: spi_flash_disable_interrupts_caches_and_other_cpu at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/spi_flash/cache_utils.c:144 (discriminator 1)

0x4008e47d: cache_disable at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/spi_flash/spi_flash_os_func_app.c:70

0x4008e487: spi1_start at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/spi_flash/spi_flash_os_func_app.c:99

0x40091d45: spiflash_start_default at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/spi_flash/esp_flash_api.c:128

0x4008df41: esp_flash_read at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/spi_flash/esp_flash_api.c:821

0x40162673: esp_partition_read at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/spi_flash/partition.c:424

0x401557c3: spiffs_api_read at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/spiffs/spiffs_api.c:36

0x40158bbe: spiffs_phys_rd at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/spiffs/spiffs/src/spiffs_cache.c:146

0x401568f7: spiffs_object_find_object_index_header_by_name_v at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/spiffs/spiffs/src/spiffs_nucleus.c:1671

0x40156c9c: spiffs_obj_lu_find_entry_visitor at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/spiffs/spiffs/src/spiffs_nucleus.c:177 (discriminator 4)

0x40158127: spiffs_object_find_object_index_header_by_name at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/spiffs/spiffs/src/spiffs_nucleus.c:1694

0x40155cc1: SPIFFS_open at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/spiffs/spiffs/src/spiffs_hydrogen.c:230 (discriminator 2)

0x401553d1: vfs_spiffs_open at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/spiffs/esp_spiffs.c:479

0x400d68fb: esp_vfs_open at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/vfs/vfs.c:399 (discriminator 3)

0x401cb3f4: _fopen_r at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/fopen.c:129

0x401cb49d: fopen at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/fopen.c:168

0x400dbd79: ca_log_vprintf at /home/devel3/Develop/CareWork/I4rc3_8/carealert-esp32/build/../main/app_supp.c:435

0x401e615d: esp_log_writev at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/log/log.c:200

0x400993a1: esp_log_write at /home/devel3/Develop/Espress1/IDF_44/esp-idf/components/log/log.c:210

0x400ddc1e: task_health_loop at /home/devel3/Develop/CareWork/I4rc3_8/carealert-esp32/build/../main/task_health.c:318 (discriminator 6)

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Crash when using stack on external PSRAM

Postby WiFive » Thu Feb 03, 2022 4:15 am

Use a worker task to write to flash that doesn't have its stack in external ram

User avatar
bartvanhofwegen
Posts: 5
Joined: Mon Aug 15, 2022 5:25 pm
Location: The Netherlands

Re: Crash when using stack on external PSRAM

Postby bartvanhofwegen » Mon Aug 15, 2022 7:32 pm

Did this solve the problem? Thanks in advance!
Bart

Leander
Posts: 28
Joined: Thu Sep 26, 2019 8:50 pm

Re: Crash when using stack on external PSRAM

Postby Leander » Mon Aug 22, 2022 3:10 pm

Flash writes aren't supported from tasks allocated in the PSRAM as it uses the same SPI-bus. Queue writes and use other task to actually write them.

Who is online

Users browsing this forum: No registered users and 68 guests