Problems accessing flash memory

Dimych
Posts: 13
Joined: Tue Feb 05, 2019 6:09 am

Problems accessing flash memory

Postby Dimych » Sun Jun 27, 2021 8:39 am

Are there any check functions before using the read / write / erase functions of flash memory?

The code crashes periodically. I don't see any patterns. Maybe at the start, or maybe after half an hour of work. I read / write to 1 sector of flash memory every 10 seconds 16 bytes. And I get errors ...

idf: 4.2.2
ic: esp32-pico-v3-02

This crash occurred on the esp_partition_read function.

Code: Select all

I (367027) EVENT LOG: read page[0]
Re-enable cpu cache.
Guru Meditation Error: Core  0 panic'ed (Cache disabled but cached memory region accessed).

Core  0 register dump:
PC      : 0x4000c2e2  PS      : 0x00060134  A0      : 0x800972c6  A1      : 0x3ffe9890
A2      : 0x3ffedac4  A3      : 0x3ff42080  A4      : 0x00000040  A5      : 0x3ffedac4
A6      : 0xffffffff  A7      : 0x00000004  A8      : 0x00000000  A9      : 0x3ffe9880
A10     : 0x00000001  A11     : 0x3ffce3a8  A12     : 0x00000001  A13     : 0x3ffbedcc
A14     : 0x3ffc2acc  A15     : 0x00000001  SAR     : 0x00000020  EXCCAUSE: 0x00000007
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x00000003

Backtrace:0x4000c2df:0x3ffe9890 0x400972c3:0x3ffe98a0 0x40097643:0x3ffe98e0 0x400989d3:0x3ffe9900 0x4008be3a:0x3ffe9920 0x40142307:0x3ffe9950 0x400fc059:0x3ffe9980 0x400fc1e1:0x3ffe99e0 0x400fbd5e:0x3ffe9a00 0x400fa95d:0x3ffe9aa0 0x400fa0c5:0x3ffe9d30 0x4010df7a:0x3ffe9d50 0x40110d15:0x3ffe9d70 0x40125261:0x3ffe9db0 0x401264ab:0x3ffe9dd0
0x400972c3: spi_flash_ll_get_buffer_data at C:/esp/esp-idf/components/soc/src/esp32/include/hal/spi_flash_ll.h:146

0x40097643: spi_flash_hal_read at C:/esp/esp-idf/components/soc/src/hal/spi_flash_hal_common.inc:122

0x400989d3: spi_flash_chip_generic_read at C:/esp/esp-idf/components/spi_flash/spi_flash_chip_generic.c:155

0x4008be3a: esp_flash_read at C:/esp/esp-idf/components/spi_flash/esp_flash_api.c:557

0x40142307: esp_partition_read at C:/esp/esp-idf/components/spi_flash/partition.c:412
Maybe there is a way to do some kind of check before reading?

Code: Select all

const esp_partition_t * partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "events");
    assert(partition != NULL);

    uint8_t * read_data = (uint8_t*) malloc(SPI_FLASH_SEC_SIZE);
    if (read_data == NULL) {
        ESP_LOGE(EVENT_LOG_TAG, "error memory"); 
        return -1;
    }

        #ifdef ENABLED_EVENT_LOG
            ESP_LOGI(EVENT_LOG_TAG, "read page[%d]", i);
        #endif
        // Прочитать блок по адресу
        if (esp_partition_read(partition, i * SPI_FLASH_SEC_SIZE, read_data, SPI_FLASH_SEC_SIZE) == ESP_OK)
        {
        
        } 

biterror
Posts: 31
Joined: Thu Apr 30, 2020 11:00 am

Re: Problems accessing flash memory

Postby biterror » Sun Jun 27, 2021 9:03 am

Is it possible that some interrupt is triggered while you are reading the FLASH and the interrupt code is not locked in RAM and it's unable to load the code from FLASH?

Dimych
Posts: 13
Joined: Tue Feb 05, 2019 6:09 am

Re: Problems accessing flash memory

Postby Dimych » Mon Jun 28, 2021 5:07 am

I disabled my code, leaving only the read flash function. added attribute IRAM_ATTR to the function.
The error still persists. I cannot control the code in WIFI and BLE. It is possible that read operations are performed there.

It turns out that you cannot use a flash, in principle, when WIFI is working?

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

Re: Problems accessing flash memory

Postby ESP_Sprite » Mon Jun 28, 2021 6:55 am

Are you using psram?

Dimych
Posts: 13
Joined: Tue Feb 05, 2019 6:09 am

Re: Problems accessing flash memory

Postby Dimych » Mon Jun 28, 2021 7:28 am

yes, i use psram
if you use the flash no more than 30 seconds, then I see no errors (test for several hours).

sometimes crashes when writing to nvs..

Code: Select all

Guru Meditation Error: Core  0 panic'ed (Cache disabled but cached memory region accessed)
Core 0 register dump:
PC      : 0x400967bc  PS      : 0x00060334  A0      : 0x800839e4  A1      : 0x3ffbe350
0x400967bc: xQueueReceiveFromISR at C:/esp/esp-idf/components/freertos/queue.c:1622 (discriminator 1)

A2      : 0x3f8006ec  A3      : 0x00000000  A4      : 0x3ffbe390  A5      : 0xbad00bad
A6      : 0x3ff47024  A7      : 0x00000000  A8      : 0x8008c641  A9      : 0x3ffbe350
A10     : 0x00000000  A11     : 0x3ffb31d0  A12     : 0x00000655  A13     : 0x3f4049d4
A14     : 0x40087c80  A15     : 0x3ffed4d4  SAR     : 0x0000001f  EXCCAUSE: 0x00000007
0x40087c80: r_lld_evt_schedule at ??:?

EXCVADDR: 0x00000000  LBEG    : 0x40090efc  LEND    : 0x40090f18  LCOUNT  : 0xffffffff
0x40090efc: memcpy at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/machine/xtensa/memcpy.S:175

0x40090f18: memcpy at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/machine/xtensa/memcpy.S:197

Core 0 was running in ISR context:
EPC1    : 0x4008c4c1  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x400967bc
0x4008c4c1: timer_overflow_happened at C:/esp/esp-idf/components/esp32/esp_timer_esp32.c:149

0x400967bc: xQueueReceiveFromISR at C:/esp/esp-idf/components/freertos/queue.c:1622 (discriminator 1)


ELF file SHA256: a804289d8acdc373

Backtrace: 0x400967b9:0x3ffbe350 0x400839e1:0x3ffbe370 0x4008c962:0x3ffbe390 0x4008ccf4:0x3ffbe3d0 0x4008c8fa:0x3ffbe410 0x4008466d:0x3ffbe430 0x40088091:0x3ffbe450 0x40085022:0x3ffbe490 0x4008a4ee:0x3ffbe4b0 0x4008af9f:0x3ffbe4d0 0x400841b5:0x3ffbe4f0 0x4009b37b:0x3ffed380 0x4009bae9:0x3ffed3a0 0x4009b89b:0x3ffed3c0 0x4009b5bd:0x3ffed400 0x4009babb:0x3ffed430 0x4008c149:0x3ffed460 0x4008c1b5:0x3ffed4b0 0x40146823:0x3ffed4d0 0x4014685e:0x3ffed500 0x401468f5:0x3ffed520 0x4014758a:0x3ffed560 0x40145467:0x3ffed580 0x40145a6a:0x3ffed600 0x4014796f:0x3ffed670 0x4014502f:0x3ffed690 0x400e456b:0x3ffed6c0 0x400e511d:0x3ffed760 0x400e08e0:0x3ffed780 0x400d7e71:0x3ffed7a0 0x400dab65:0x3ffed7c0 0x400df26e:0x3ffed840 0x400dd58b:0x3ffed880
0x400967b9: xQueueReceiveFromISR at C:/esp/esp-idf/components/freertos/queue.c:1622 (discriminator 1)

0x400839e1: semphr_take_from_isr_wrapper at C:/esp/esp-idf/components/esp_wifi/esp32/esp_adapter.c:263

0x4008c962: coex_bb_reset_unlock at ??:?

0x4008ccf4: coex_core_request at ??:?

0x4008c8fa: coex_bt_request at ??:?

0x4008466d: coex_bt_request_wrapper at C:/esp/esp-idf/components/bt/controller/bt.c:1041

0x40088091: r_lld_evt_schedule at ??:?

0x40085022: r_ea_finetimer_isr at ??:?

0x4008a4ee: r_rwbt_isr at ??:?

0x4008af9f: r_rwbtdm_isr_wrapper at intc.c:?

0x400841b5: _xt_lowint1 at C:/esp/esp-idf/components/freertos/xtensa_vectors.S:1153

0x4009b37b: spi_flash_hal_host_idle at C:/esp/esp-idf/components/soc/src/hal/spi_flash_hal_iram.c:66

0x4009bae9: spi_flash_generic_wait_host_idle at C:/esp/esp-idf/components/spi_flash/spi_flash_chip_generic.c:247

0x4009b89b: spi_flash_chip_generic_wait_idle at C:/esp/esp-idf/components/spi_flash/spi_flash_chip_generic.c:269

0x4009b5bd: spi_flash_chip_generic_set_write_protect at C:/esp/esp-idf/components/spi_flash/spi_flash_chip_generic.c:216

0x4009babb: spi_flash_chip_generic_write at C:/esp/esp-idf/components/spi_flash/spi_flash_chip_generic.c:192

0x4008c149: esp_flash_write at C:/esp/esp-idf/components/spi_flash/esp_flash_api.c:617

0x4008c1b5: spi_flash_write at C:/esp/esp-idf/components/spi_flash/esp_flash_api.c:757

0x40146823: nvs::Page::alterEntryState(unsigned int, nvs::Page::EntryState) at C:/esp/esp-idf/components/nvs_flash/src/nvs_page.cpp:723

0x4014685e: nvs::Page::writeEntry(nvs::Item const&) at C:/esp/esp-idf/components/nvs_flash/src/nvs_page.cpp:108

0x401468f5: nvs::Page::copyItems(nvs::Page&) at C:/esp/esp-idf/components/nvs_flash/src/nvs_page.cpp:482

0x4014758a: nvs::PageManager::requestNewPage() at C:/esp/esp-idf/components/nvs_flash/src/nvs_pagemanager.cpp:177

0x40145467: nvs::Storage::writeMultiPageBlob(unsigned char, char const*, void const*, unsigned int, nvs::VerOffset) at C:/esp/esp-idf/components/nvs_flash/src/nvs_storage.cpp:180

0x40145a6a: nvs::Storage::writeItem(unsigned char, nvs::ItemType, char const*, void const*, unsigned int) at C:/esp/esp-idf/components/nvs_flash/src/nvs_storage.cpp:292
 (inlined by) nvs::Storage::writeItem(unsigned char, nvs::ItemType, char const*, void const*, unsigned int) at C:/esp/esp-idf/components/nvs_flash/src/nvs_storage.cpp:248

0x4014796f: nvs::NVSHandleSimple::set_blob(char const*, void const*, unsigned int) at C:/esp/esp-idf/components/nvs_flash/src/nvs_handle_simple.cpp:52
 (inlined by) nvs::NVSHandleSimple::set_blob(char const*, void const*, unsigned int) at C:/esp/esp-idf/components/nvs_flash/src/nvs_handle_simple.cpp:47

0x4014502f: nvs_set_blob at C:/esp/esp-idf/components/nvs_flash/src/nvs_api.cpp:400

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

Re: Problems accessing flash memory

Postby ESP_Sprite » Mon Jun 28, 2021 12:34 pm

A problem possibly may be that the memory for the malloc is allocated in PSRAM; I don't know if the esp_partition_read code has guards for that. You could try using heap_alloc_caps to always allocate internal memory there and see if the problem goes away.

Who is online

Users browsing this forum: Accound and 116 guests