Hi,
I want to use the external flash on nRF9151-DK (gd25wb256).
Having set all the necessary files (prj.conf, nrf9151dk_nrf9151_ns.overlay) and some parameters in the main.c (code below) I eventually gained access and ability to store data in flash memory using NVS. However ,I have encountered two problems:
- The first one was having an error (overflow of nvs_fs.sector_size) during the initialization of the NVS, which I have resolved by changing the type (uint16_t to uint32_t inside the nvs.h file - as suggested in this issue: https://github.com/zephyrproject-rtos/zephyr/issues/36590). Is there any cleaner way to get the NVS to work with this memory?
- I set the config to 256 sectors of 65536 bytes to get it working, but it results in only about 16MiB (16707592 bytes reported by library) of memory. However, setting the config to 512 (accordingly to the datasheet I found) results in having corrupted data (error during reading). Why is that?
nrf9151dk_nrf9151_ns.overlay:/ { chosen { nordic,pm-ext-flash = &gd25wb256; }; }; &gd25wb256 { status = "okay"; };
prj.conf:CONFIG_LOG=y CONFIG_LOG_MODE_IMMEDIATE=y CONFIG_NVS_LOG_LEVEL_DBG=y CONFIG_GPIO=y CONFIG_NVS=y CONFIG_FLASH=y CONFIG_FLASH_MAP=y CONFIG_SPI=y CONFIG_SPI_NOR=y CONFIG_SPI_NOR_SFDP_DEVICETREE=y CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y CONFIG_PM_PARTITION_REGION_NVS_STORAGE_EXTERNAL=y
main.c:#include <zephyr/kernel.h> #include <zephyr/device.h> #include <zephyr/drivers/flash.h> #include <zephyr/storage/flash_map.h> #include <zephyr/fs/nvs.h> #include <string.h> #include <zephyr/drivers/uart.h> #include <zephyr/drivers/gpio.h> #define NVS_PARTITION external_flash #define NVS_PARTITION_DEVICE FIXED_PARTITION_DEVICE(NVS_PARTITION) #define NVS_PARTITION_OFFSET FIXED_PARTITION_OFFSET(NVS_PARTITION) static struct nvs_fs fs; int main(void) { int rc = 0; struct flash_pages_info info; fs.flash_device = NVS_PARTITION_DEVICE; printk("Flash device name: %s\n", fs.flash_device->name); if (!device_is_ready(fs.flash_device)) { printk("Flash device %s is not ready\n", fs.flash_device->name); return 0; } fs.offset = NVS_PARTITION_OFFSET; rc = flash_get_page_info_by_offs(fs.flash_device, fs.offset, &info); if (rc) { printk("Unable to get page info\n"); return 0; } fs.sector_size = info.size; printk("Sector size: %u", fs.sector_size); fs.sector_count = 256; rc = nvs_mount(&fs); if (rc) { printk("Flash Init failed\n"); printk("Flash device name: %s\n", fs.flash_device->name); return 0; } ssize_t free_space = nvs_calc_free_space(&fs); printk("Free space on NVS partition NVS: %zd bytes\n", free_space); return 0; }
output:[00:00:00.428,619] <inf> spi_nor: gd25wb256e3ir@1: 32 MiBy flash *** Booting nRF Connect SDK v3.1.1-e2a97fe2578a *** *** Using Zephyr OS v4.1.99-ff8f0c579eeb *** Flash device name: gd25wb256e3ir@1 Sector size: 65536[00:00:00.489,471] <dbg> fs_nvs: nvs_recover_last_ate: Recovering last ate from sector 0 [00:00:02.482,360] <inf> fs_nvs: 256 Sectors of 65536 bytes [00:00:02.488,311] <inf> fs_nvs: alloc wra: 0, ffe8 [00:00:02.493,621] <inf> fs_nvs: data wra: 0, 0 Free space on NVS partition NVS: 16707592 bytes
Is there any way to gain acces to whole memory using NVS? Is there any more elegant way to fix the header file (nvs.h).
I will be grateful for any feedback, thanks!
Best regards,
Michal
