ESP32 NVS Crashes

I’m trying to build an application using an ESP32 and the AWS “Gettings started” guide:
https://docs.aws.amazon.com/freertos/latest/userguide/getting_started_espressif.html

The current state of the application is more or less identical to the MQTT demo, which I have gotten to run successfully. My application is however built outside of the freertos and espressif source, using instructions as provided in the “Getting started” guide.

My host machine is running Ubuntu 20.04
FreeRTOS version 202002.00

My application wants to connect to WiFi - but it crashes as soon as I try to initialize the NVS Flash using the provided espressif function nvs_flash_init(). This is the first thing my application does (which also the ESP32 Mqtt Demo does). Removing that the nvs_flash_init() allows the device to run (however, it is required for the WiFi)

The reason it seem to die is because the Cache is accessed even though its not yet enabled, and it seems to be because of the ISR connected to xTaskIncrementTick.
Sadly I have little control over that, as the way the espressif idf is designed the main entry point is through the app_main() function, whereas the true main() is obfuscated in the SDK. This function as I understand invokes the start of scheduler.

However, this is still not an issue in the provided demo.

I did find some useful reading with what seems to be the same issue, but I cant really get my head around it, and I would prefer to not having to use non-merged fork of FreeRTOS to continue (find the error report link in the README):

I have attached my error log when monitoring below, Any help would be greatly appreciated:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:7216
ho 0 tail 12 room 4
load:0x40078000,len:12620
load:0x40080400,len:6708
entry 0x40080778
I (75) boot: Chip Revision: 1
I (76) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (41) boot: ESP-IDF v3.3-163-g601a03e 2nd stage bootloader
I (41) boot: compile time 18:22:42
I (41) boot: Enabling RNG early entropy source...
I (46) boot: SPI Speed      : 40MHz
I (50) boot: SPI Mode       : DIO
I (54) boot: SPI Flash Size : 4MB
I (58) boot: Partition Table:
I (62) boot: ## Label            Usage          Type ST Offset   Length
I (69) boot:  0 nvs              WiFi data        01 02 00010000 00006000
I (77) boot:  1 otadata          OTA data         01 00 00016000 00002000
I (84) boot:  2 phy_init         RF data          01 01 00018000 00001000
I (92) boot:  3 ota_0            OTA app          00 10 00020000 00177000
I (99) boot:  4 ota_1            OTA app          00 11 001a0000 00177000
I (107) boot:  5 storage          WiFi data        01 02 00317000 00010000
I (114) boot: End of partition table
I (118) boot: ota rollback check done
I (123) boot_comm: chip revision: 1, min. application chip revision: 0
I (130) esp_image: segment 0: paddr=0x00020020 vaddr=0x3f400020 size=0x1476c ( 83820) map
I (168) esp_image: segment 1: paddr=0x00034794 vaddr=0x3ffbdb60 size=0x02b9c ( 11164) load
I (173) esp_image: segment 2: paddr=0x00037338 vaddr=0x40080000 size=0x00400 (  1024) load
0x40080000: _WindowOverflow4 at /home/fredrik/fsu/esp32-aws-cam/build/../external/freertos/freertos_kernel/portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_vectors.S:1713

I (176) esp_image: segment 3: paddr=0x00037740 vaddr=0x40080400 size=0x088d0 ( 35024) load
I (199) esp_image: segment 4: paddr=0x00040018 vaddr=0x400d0018 size=0x6b2a0 (438944) map
0x400d0018: _stext at ??:?

I (353) esp_image: segment 5: paddr=0x000ab2c0 vaddr=0x40088cd0 size=0x053f8 ( 21496) load
0x40088cd0: esp_rom_spiflash_read_data at /home/fredrik/fsu/esp32-aws-cam/build/../external/freertos/vendors/espressif/esp-idf/components/spi_flash/spi_flash_rom_patch.c:529

I (371) boot: Loaded app from partition at offset 0x20000
I (371) boot: Disabling RNG early entropy source...
I (371) cpu_start: Pro cpu up.
I (375) cpu_start: Application information:
I (380) cpu_start: Project name:     esp-idf
I (385) cpu_start: App version:      0.1-7-ge8ab7e6
I (390) cpu_start: Compile time:     Jun 28 2020 18:22:37
I (396) cpu_start: ELF file SHA256:  b89df9d9c13afd4f...
I (402) cpu_start: ESP-IDF:          v3.3-163-g601a03e
I (408) cpu_start: Single core mode
I (412) heap_init: Initializing. RAM available for dynamic allocation:
I (419) heap_init: At 3FFAE6E0 len 0000F480 (61 KiB): DRAM
I (426) heap_init: At 3FFC7930 len 000186D0 (97 KiB): DRAM
I (432) heap_init: At 3FFE0440 len 0001FBC0 (126 KiB): D/IRAM
I (438) heap_init: At 40078000 len 00008000 (32 KiB): IRAM
I (444) heap_init: At 4008E0C8 len 00011F38 (71 KiB): IRAM
I (450) cpu_start: Pro cpu start user code
I (133) cpu_start: Starting scheduler on PRO CPU.
I (174) wifi: wifi driver task: 3ffb58b8, prio:23, stack:3584, core=0
I (174) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (174) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
Guru Meditation Error: Core  0 panic'ed (Cache disabled but cached memory region accessed)
Core 0 register dump:
PC      : 0x400d1ef4  PS      : 0x00060034  A0      : 0x40088564  A1      : 0x3ffbe150  
0x400d1ef4: xTaskIncrementTick at /home/fredrik/fsu/esp32-aws-cam/build/../external/freertos/freertos_kernel/tasks.c:5162 (discriminator 4)

0x40088564: _frxt_timer_int at /home/fredrik/fsu/esp32-aws-cam/build/../external/freertos/freertos_kernel/portable/ThirdParty/GCC/Xtensa_ESP32/portasm.S:313

A2      : 0x00000000  A3      : 0x00050021  A4      : 0x4008145d  A5      : 0x3ffb6144  
0x4008145d: _xt_lowint1 at /home/fredrik/fsu/esp32-aws-cam/build/../external/freertos/freertos_kernel/portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_vectors.S:1126

A6      : 0x3ffb5777  A7      : 0x00000001  A8      : 0x800883f8  A9      : 0x3ffb54a0  
A10     : 0x00000000  A11     : 0x3ffb54d0  A12     : 0x00000001  A13     : 0x3ffb6144  
A14     : 0x000000ff  A15     : 0x3ffb56b0  SAR     : 0x00000019  EXCCAUSE: 0x00000007  
EXCVADDR: 0x00000000  LBEG    : 0x4000164d  LEND    : 0x40001667  LCOUNT  : 0xfffffffd  
Core 0 was running in ISR context:
EPC1    : 0x40088d55  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x400d1ef4
0x40088d55: esp_rom_spiflash_read_data at /home/fredrik/fsu/esp32-aws-cam/build/../external/freertos/vendors/espressif/esp-idf/components/spi_flash/spi_flash_rom_patch.c:529

0x400d1ef4: xTaskIncrementTick at /home/fredrik/fsu/esp32-aws-cam/build/../external/freertos/freertos_kernel/tasks.c:5162 (discriminator 4)


ELF file SHA256: ad0bd0baad0bd0baad0bd0baad0bd0baad0bd0baad0bd0baad0bd0baad0bd0ba

Backtrace: 0x400d1ef4:0x3ffbe150 0x40088561:0x3ffbe170 0x400814b2:0x3ffbe180 0x40088d52:0x00000000
0x400d1ef4: xTaskIncrementTick at /home/fredrik/fsu/esp32-aws-cam/build/../external/freertos/freertos_kernel/tasks.c:5162 (discriminator 4)

0x40088561: _frxt_timer_int at /home/fredrik/fsu/esp32-aws-cam/build/../external/freertos/freertos_kernel/portable/ThirdParty/GCC/Xtensa_ESP32/portasm.S:303

0x400814b2: _xt_lowint1 at /home/fredrik/fsu/esp32-aws-cam/build/../external/freertos/freertos_kernel/portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_vectors.S:1133

0x40088d52: esp_rom_spiflash_read_data at /home/fredrik/fsu/esp32-aws-cam/build/../external/freertos/vendors/espressif/esp-idf/components/spi_flash/spi_flash_rom_patch.c:529


Rebooting...

For anyone else stumbling into this problem, I can add that after looking further into some responses here:

I found that the issue can be somewhat circumvented by declaring the user-sources global in cmake. That solution works for me right now - but it is not ideal, and forces me to do tradeoffs with my wanted cmake structure.

1 Like

Hello @sturmgans, thank you for sharing your findings and solution.

There shouldn’t be a requirement of having your user-sources at the global scope of your root cmake file. If you are interested, here is a link to documentation that covers how to use the code found in the aws/amazon-freertos repository as a submodule to your project.

It should be possible to place your user-sources into a CMake module and then add the dependencies on the AWS libraries as required. This would prevent the source code from being at a global scope.