Cache error on nvs_flash_init

BrettG
Posts: 29
Joined: Wed Feb 15, 2017 7:32 pm

Cache error on nvs_flash_init

Postby BrettG » Wed Dec 26, 2018 5:23 pm

Just running very simple nvs init code:

Code: Select all

void app_main(void){
    vTaskDelay(2000 / portTICK_PERIOD_MS);
    printf("Initing NVS\n");
    nvs_flash_init();
    printf("NVS init Done.\n");
    vTaskDelay(2000 / portTICK_PERIOD_MS);
}
I run across an NVS init error shown below. After researching this issue it seems to be generally caused by an interrupt not registered with IRAM. But I have not declared any interrupt functions. The only code is the one above. My only other thoughts are that it is a partition table issue (using partitions_two_ota.csv) or nvs corruption (however I can run nvs_flash_init via unity unit test framework).

I have been messing with make menuconfig for days trying to fis this issue. Any ideas would be greatly appreciated.
Thanks,
- Brett
  1. Guru Meditation Error: Core  0 panic'ed (Cache disabled but cached memory region
  2. Core 0 register dump:
  3. PC      : 0x400d1f94  PS      : 0x00060d34  A0      : 0x800853bc  A1      : 0x3f
  4. A2      : 0x00000001  A3      : 0x15122500  A4      : 0x00060d20  A5      : 0x40
  5. A6      : 0x3ffaffe8  A7      : 0x3ffb5d90  A8      : 0x80081a40  A9      : 0x3f
  6. A10     : 0x00000000  A11     : 0x15122500  A12     : 0x00060f20  A13     : 0x00
  7. A14     : 0x3ffb3b0c  A15     : 0x3ffb5d40  SAR     : 0x00000020  EXCCAUSE: 0x00
  8. EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xff
  9.  
  10. Backtrace: 0x400d1f94:0x3ffb5d90 0x400853b9:0x3ffb5dc0 0x40085925:0x3ffb5df0 0x4
  11. 0x400d1f94: portENTER_CRITICAL_NESTED at dport_access.c:?
  12.  
  13. 0x400853b9: Cache_Flush at flash_mmap.c:?
  14.  
  15. 0x40085925: spi_flash_mmap_pages at ??:?
  16.  
  17. 0x40085575: spi_flash_mmap at ??:?
  18.  
  19. 0x400fd4ef: load_partitions at partition.c:?
  20.  
  21. 0x400fd34d: esp_partition_find at ??:?
  22.  
  23. 0x400fd471: esp_partition_find_first at ??:?
  24.  
  25. 0x400fbf32: nvs_flash_init_partition at C:/msys32/home/brettG/Git/esp-idf/com
  26.  
  27. 0x400fbf72: nvs_flash_init at C:/msys32/home/brettG/Git/esp-idf/components/nv
  28.  
  29. 0x400e3fc1: app_main at ??:?
  30.  
  31. 0x400d1504: main_task at cpu_start.c:?

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: Cache error on nvs_flash_init

Postby mzimmers » Wed Dec 26, 2018 9:45 pm

Just out of curiosity, what does your partition table look like?

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: Cache error on nvs_flash_init

Postby ESP_igrr » Thu Dec 27, 2018 8:08 am

This looks like a bug in IDF that portENTER_CRITICAL_NESTED inline function doesn't have IRAM_ATTR attribute.

BrettG
Posts: 29
Joined: Wed Feb 15, 2017 7:32 pm

Re: Cache error on nvs_flash_init

Postby BrettG » Thu Dec 27, 2018 1:47 pm

ESP_igrr wrote: This looks like a bug in IDF that portENTER_CRITICAL_NESTED inline function doesn't have IRAM_ATTR attribute.
Thanks so much!! I added the IRAM_ATTR to portENTER_CRITICAL_NESTED definition and it went off without a hitch.

devlat
Posts: 15
Joined: Thu Oct 29, 2020 9:33 am

Re: Cache error on nvs_flash_init

Postby devlat » Thu Oct 29, 2020 10:40 am

I wanted to resurrect this old post to note that I had exactly same issue in ESP-IDF 4.2 and this info helped me to fix it.
Obviously by setting 'inline' attribute on portENTER_CRITICAL_NESTED ESP-IDF team assumed the problem would go away.
But this seems only a partial solution because when you build in debug mode with all optimisations disabled the 'inline'
attribute is just ignored and portENTER_CRITICAL_NESTED is compiled as normal function landing in cached region.
Just to note, i am using ESP-IDF as a backend for VisualDBG on ESP-WROVER-KIT V4.1 with JTAG debugging and my Debug config has all optimisations disabled, so this issue was reproduced 100% - CPU goes to panic and call stack always points to this function.
After inserting IRAM_ATTR the issue was fixed immediately.

Who is online

Users browsing this forum: Baidu [Spider], Majestic-12 [Bot] and 65 guests