Hello, I'm working with nRF5340DK, and need to initialize some variables - long arrays of approximately 16 KB each
- they must be included at compile time (without depending on any external serial transmission on runtime)
- they must be stored in QSPI external flash MX25R64, already available in the kit
- if it is possible, I would prefer not to use any storage system (LittleFS, NVS, FAT), but straight linker description and variables locating on specified memory regions
This post is highly related, with the only difference that it refers to internal instead of external flash, but nevertheless that post does not seem to be solved yet.
I have already enabled external flash from proj.conf :
CONFIG_NORDIC_QSPI_NOR=y CONFIG_FLASH=y CONFIG_FLASH_PAGE_LAYOUT=y CONFIG_NVS=y CONFIG_NVS_LOG_LEVEL_DBG=y CONFIG_MPU_ALLOW_FLASH_WRITE=y
I have also enabled external flash from overlay file:
/ { chosen { nordic,pm-ext-flash = &mx25r64; }; };
I have created a custom .ld file and declared a memory region located in external_flash:
SECTION_PROLOGUE(my_external_flash, 0x00000000 (NOLOAD),) { __my_external_flash_start = 0x00000000; KEEP(*(".my_external_flash*")); __my_external_flash_end = 0x000E0000; } GROUP_LINK_IN(external_flash)
I have added the instruction in CMakeLists.txt to use that linker file:
zephyr_linker_sources(SECTIONS custom-sections.ld)
I have declared a variable in my source file to be located in the previously defined region:
uint32_t __attribute__((section ("my_external_flash"))) testArray4[1024] = {0} ;
When the size of the variable is below or equal to 4096 bytes (1024 uint32_t), I can read and write values to that variable.
But, if I raise the size by one, I get a bus fault error during run time.
Is there some obvious mistake that I am making in any of the steps?
I have also tried locating the storage partition on external flash, through my pm_static.yml file, and even after verifying the partition was correctly created and located on both partitions.yml and zephyr.dts, I keep getting the same error described above when I declare the variable in "storage" region/partition (?).
Would you have any recomendation on how to achieve this? How to locate a variable on external flash at compile time?
Another acceptable alternative, no so efficient as what we are looking for above, but still acceptable, would be to be able to create arrays to be stored at NVS located on external flash, at compile time. (which means that this initialized values must be defined and stored during compilation, without taking any primary flash or ram space). Is there a way to do this?
Thanks in advance!
Leopoldo