platformio / platform-espressif32

Espressif 32: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/espressif32
Apache License 2.0
855 stars 570 forks source link

Version 6.7.0 crashes on ESP32 when trying to init NVS #1379

Closed ascillato closed 1 month ago

ascillato commented 1 month ago

The latest version of platform-espressif32 v6.7.0 makes that any firmware on ESP32 crashes as soon as it tries to init NVS.

This bug is not present in v6.6.0 Reverting back to 6.6.0 solves this issue and the firmware works as expected.

The firmware tested is:

#include "esp_log.h"

extern "C" void app_main() {
    static const char* TAG = "INIT";

    esp_err_t ret = nvs_flash_init();

    ESP_LOGI(TAG, "NVS ret=%d", ret);
}

Error output:

Guru Meditation Error: Core  0 panic'ed (Cache disabled but cached memory region accessed). 

Core  0 register dump:
PC      : 0x4019ee8c  PS      : 0x00060d35  A0      : 0x80082a43  A1      : 0x3ffbd330  
A2      : 0x3ffbe028  A3      : 0xffffffff  A4      : 0x00060d23  A5      : 0x00060d23  
A6      : 0x00000001  A7      : 0x0000cdcd  A8      : 0x800943ed  A9      : 0x3ffbd320  
A10     : 0x3ffbe028  A11     : 0xb33fffff  A12     : 0x0000cdcd  A13     : 0x3ffbd230  
A14     : 0x00000003  A15     : 0x00060023  SAR     : 0x00000010  EXCCAUSE: 0x00000007  
EXCVADDR: 0x00000000  LBEG    : 0x4000c46c  LEND    : 0x4000c477  LCOUNT  : 0x00000000  

Backtrace: 0x4019ee89:0x3ffbd330 0x40082a40:0x3ffbd350 0x400901eb:0x3ffbd370 0x400911b6:0x3ffbd390 0x4009002f:0x3ffbd3b0 0x40090109:0x3ffbd3d0 0x40188459:0x3ffbd400 0x4011dbb9:0x3ffbd440 0x401006d5:0x3ffbd480 0x401008a0:0x3ffbd520 0x401008d9:0x3ffbd540 0x4011d700:0x3ffbd560 0x4011c298:0x3ffbd580 0x4011ab94:0x3ffbd5b0 0x4011aba6:0x3ffbd5d0 0x400dbd8b:0x3ffbd5f0 0x400dbdbe:0x3ffbd610 0x400db2e3:0x3ffbd630 0x401a475f:0x3ffbd650
  #0  0x4019ee89 in xt_utils_set_breakpoint at /home/ascillato/.platformio/packages/framework-espidf/components/xtensa/include/xt_utils.h:122
      (inlined by) esp_cpu_set_breakpoint at /home/ascillato/.platformio/packages/framework-espidf/components/esp_hw_support/cpu.c:339
  #1  0x40082a40 in xPortEnterCriticalTimeoutSafe at /home/ascillato/.platformio/packages/framework-espidf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:583
      (inlined by) vPortEnterCriticalSafe at /home/ascillato/.platformio/packages/framework-espidf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:592
      (inlined by) esp_ipc_isr_stall_other_cpu at /home/ascillato/.platformio/packages/framework-espidf/components/esp_system/port/esp_ipc_isr.c:113
  #2  0x400901eb in Cache_Flush at /home/ascillato/.platformio/packages/framework-espidf/components/esp_rom/include/esp32/rom/cache.h:140
  #3  0x400911b6 in cache_sync at /home/ascillato/.platformio/packages/framework-espidf/components/esp_mm/cache_esp32.c:29
  #4  0x4009002f in s_do_cache_invalidate at /home/ascillato/.platformio/packages/framework-espidf/components/esp_mm/esp_mmu_map.c:378
  #5  0x40090109 in s_do_mapping at /home/ascillato/.platformio/packages/framework-espidf/components/esp_mm/esp_mmu_map.c:432
  #6  0x40188459 in esp_mmu_map at /home/ascillato/.platformio/packages/framework-espidf/components/esp_mm/esp_mmu_map.c:571
  #7  0x4011dbb9 in spi_flash_mmap at /home/ascillato/.platformio/packages/framework-espidf/components/spi_flash/flash_mmap.c:85
  #8  0x401006d5 in load_partitions at /home/ascillato/.platformio/packages/framework-espidf/components/esp_partition/partition.c:103
      (inlined by) ensure_partitions_loaded at /home/ascillato/.platformio/packages/framework-espidf/components/esp_partition/partition.c:259
  #9  0x401008a0 in ensure_partitions_loaded at /home/ascillato/.platformio/packages/framework-espidf/components/esp_partition/partition.c:306
      (inlined by) esp_partition_find at /home/ascillato/.platformio/packages/framework-espidf/components/esp_partition/partition.c:288
  #10 0x401008d9 in esp_partition_find_first at /home/ascillato/.platformio/packages/framework-espidf/components/esp_partition/partition.c:344
  #11 0x4011d700 in nvs::partition_lookup::lookup_nvs_partition(char const*, nvs::NVSPartition**) at /home/ascillato/.platformio/packages/framework-espidf/components/nvs_flash/src/nvs_partition_lookup.cpp:14
  #12 0x4011c298 in nvs::NVSPartitionManager::init_partition(char const*) at /home/ascillato/.platformio/packages/framework-espidf/components/nvs_flash/src/nvs_partition_manager.cpp:46
  #13 0x4011ab94 in nvs_flash_init_partition at /home/ascillato/.platformio/packages/framework-espidf/components/nvs_flash/src/nvs_api.cpp:135 (discriminator 1)
      (inlined by) nvs_flash_init_partition at /home/ascillato/.platformio/packages/framework-espidf/components/nvs_flash/src/nvs_api.cpp:127 (discriminator 1)
  #14 0x4011aba6 in nvs_flash_init at /home/ascillato/.platformio/packages/framework-espidf/components/nvs_flash/src/nvs_api.cpp:163

Compiled using Ubuntu.

Please, let me know how I can help on this and if any other information is needed.

ascillato commented 1 month ago

I think I found what is causing this issue.

One of the changes of 6.7.0, that differs from 6.6.0, is in espidf.py file:

            preserve_source_file_extension = board.get(
                "build.esp-idf.preserve_source_file_extension", True
            )

I changed it back to False, as 6.6.0 has, and now it works fine.

ascillato commented 1 month ago

Knowing this, I tried to add to platformio.ini the line:

board_build.esp-idf.preserve_source_file_extension = no

But seems that it is being overrided by espidf.py and the issue persists. I have to change the espidf.py file in order to make the firmware to work.

@valeros Why this change in 6.7.0 is affecting the compiled firmware which leaves the CPU cache disabled?

valeros commented 1 month ago

Hi @ascillato, thanks for reporting. I've reproduced the issue, please stick to v6.6.0 until I figure out the underlying reason.

valeros commented 1 month ago

@ascillato this issue should be fixed in the latest framework-espidf package, please pull the latest changes via pio pkg update -g -p espressif32 command.

ascillato commented 1 month ago

@valeros

Hi, thanks for the fast response!

Updating to new 6.7.0 fixes the issue!!!!!!!

Thanks!!!!! Very appreciated.


$ pio pkg update -g -p espressif32
Platform Manager: espressif32@2024.4.12 is already up-to-date
Tool Manager: framework-arduinoespressif32@3.0.0+sha.11140aa is already up-to-date
Tool Manager: tool-esptoolpy@4.7.2 is already up-to-date
Tool Manager: tool-mkfatfs@2.0.1 is already up-to-date
Tool Manager: tool-mklittlefs@3.2.0 is already up-to-date
Tool Manager: tool-ninja@1.7.1 is already up-to-date
Tool Manager: tool-openocd-esp32@2.1100.20220706 is already up-to-date
Tool Manager: tool-riscv32-esp-elf-gdb@12.1.0+20221002 is already up-to-date
Tool Manager: tool-xtensa-esp-elf-gdb@12.1.0+20221002 is already up-to-date
Tool Manager: toolchain-esp32ulp@1.23500.220830 is already up-to-date
Tool Manager: toolchain-riscv32-esp@12.2.0+20230208 is already up-to-date
Tool Manager: toolchain-xtensa-esp32@12.2.0+20230208 is already up-to-date
Tool Manager: toolchain-xtensa-esp32s3@12.2.0+20230208 is already up-to-date

After pio pkg update -g -p espressif32 command, it said that it is up to date but the resulting firmware (clean and build) continued to crash.

So, I just removed all framework-espidf and espressif32 folders inside .platformio folder. PIO downloaded all that again and now I have the latest 6.7.0 which works great!

Thanks!!!


EDIT: As I'm using platform = espressif32@6.7.0 in platformio.ini maybe I needed to use pio pkg update -g -p espressif32@6.7.0. Well, I just removed all folders and worked fine. I just leave the comment here for anyone interested.

ascillato commented 1 month ago

@valeros

Just to learn, what was the issue? What changed? Can you link to the commit that fixed this? Thanks.

valeros commented 1 month ago

Our package was missing the patch from the commit https://github.com/espressif/esp-idf/commit/bd56ca48be81763872d1562822b94843eed12fdc.

QuAzI commented 2 weeks ago

It looks like build https://registry.platformio.org/platforms/platformio/espressif32 still has this issue as esphome still build wrong firmwares (for ESP32-WROOM-32/nodemcu-32s in my case)

Jason2866 commented 2 weeks ago

@QuAzI The Platformio registry has latest bug fixed versions.