SPIRAM data lost after writing to flash

vla_zava
Posts: 3
Joined: Thu Jan 16, 2020 11:21 am

SPIRAM data lost after writing to flash

Postby vla_zava » Thu Jan 16, 2020 11:31 am

Hello!
I have some troubles with extended SPI RAM.

Hardware: custom board with 4 MB SPI RAM. Esp32 rev: 1.
SDK version: 3.3.1 release

sdkconfig settings for SPIRAM:

CONFIG_SPIRAM_SUPPORT=y
CONFIG_SPIRAM_BOOT_INIT=y
CONFIG_SPIRAM_IGNORE_NOTFOUND=
CONFIG_SPIRAM_USE_MEMMAP=
CONFIG_SPIRAM_USE_CAPS_ALLOC=
CONFIG_SPIRAM_USE_MALLOC=y
CONFIG_SPIRAM_TYPE_AUTO=y
CONFIG_SPIRAM_TYPE_ESPPSRAM32=
CONFIG_SPIRAM_TYPE_ESPPSRAM64=
CONFIG_SPIRAM_SIZE=-1
CONFIG_SPIRAM_SPEED_40M=y
CONFIG_SPIRAM_MEMTEST=y
CONFIG_SPIRAM_CACHE_WORKAROUND=y
CONFIG_SPIRAM_BANKSWITCH_ENABLE=y
CONFIG_SPIRAM_BANKSWITCH_RESERVE=8


After staring of system I can allocate data in SPIRAM (via malloc), set values to it and check, that all data are correct by reading them back.
During writing any data to flash, cache for SPI RAM is disabled. At that moment my data in SPI RAM inaccessible and that is ok. But after finishing of flash write and enabling cache again all my data are lost.

Example. Beginning of SPIRAM before writing any data to flash:
Firsts bytes - internal data of esp32 IDF allocator - size of malloc segment.

Code: Select all

3FFAE7D0 003FFFD8 003FFFD8 3FBFFFF4 3F800019 3F800018 3FBFFFF5 3FBFFFF4 FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF
FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF
FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF
FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF
FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF
FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF
At that moment free heap size ~ 4 MB

After finishing writing to flash and re-enabled cache I have this data at the beginning of SPIRAM:

Code: Select all

FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF
FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF
FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF
FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF
FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF
FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FF3F0000 FFFFFFFF
After that free heap size will be hundreds of MB and system reboots because of broken data in memory.

I've tried workaround listed here:
https://github.com/espressif/esp-idf/issues/2892
(different cross-tools and recompiled libc) - but that can't fix my broken data in SPIRAM, problem still exist.

Could you tell me please where seems to be the problem and how can I fix it?

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

Re: SPIRAM data lost after writing to flash

Postby ESP_Sprite » Sun Jan 19, 2020 9:55 am

That is strange... any chance you can whittle down your project to the minimum required to reproduce this and post a link to it here?

vla_zava
Posts: 3
Joined: Thu Jan 16, 2020 11:21 am

Re: SPIRAM data lost after writing to flash

Postby vla_zava » Mon Jan 20, 2020 10:05 am

ESP_Sprite
Ok, I will post a link with simplified project. Thank you.

vla_zava
Posts: 3
Joined: Thu Jan 16, 2020 11:21 am

Re: SPIRAM data lost after writing to flash

Postby vla_zava » Tue Jan 21, 2020 4:25 pm

ESP_Sprite
Sorry, it was just hardware problem of our board. On new one everything is all right.

Who is online

Users browsing this forum: No registered users and 29 guests