Hi,
I have successfully added nvs in my project and able to store and retrieve data in flash.
But, i can't able to write after initializing mesh.
Could you guide me on this??
Thanks.
Hi,
I have successfully added nvs in my project and able to store and retrieve data in flash.
But, i can't able to write after initializing mesh.
Could you guide me on this??
Thanks.
Hi
Please share some more information on what SDK version you're using, whether you're using an nRF52 or nRF53 series device, and what exactly you're trying to do with the NVS in Mesh? As of NCS 2.2.0 we added sections describing FOTA in Bluetooth Mesh for example. Here for nRF52 and here for nRF53.
Also, please share details on what exactly is going wrong. Are you seeing an error message of any kind when trying to write to flash after initializing Mesh or what?
Best regards,
Simon
Hi,
I'm using version 2.0.2 sdk in nrf52, and i'm trying to store a user structure in flash with nvs.
I have also successfully implemented FOTA in my project too.
Update: Now i can able to write data to flash after mesh initialization,
previously i have called the following functions only once that too before initializing mesh
fs.flash_device = FLASH_AREA_DEVICE(STORAGE_NODE_LABEL);
if (!device_is_ready(fs.flash_device)) {
printk("Flash device %s is not ready\n", fs.flash_device->name);
return;
}
fs.offset = FLASH_AREA_OFFSET(storage);
rc = flash_get_page_info_by_offs(fs.flash_device, fs.offset, &info);
if (rc) {
printk("Unable to get page info\n");
return;
}
fs.sector_size = info.size;
fs.sector_count = 3U;
rc = nvs_mount(&fs);
if (rc) {
printk("Flash Init failed\n");
return;
}
and then followed by nvs_write() and nvs_read() wherever i wanted to write/read, that didn't work.
After that i tried calling the fs_init(code in above section) before each nvs_write() or nvs_read() and it worked.
Now i wanted to confirm that, is this the correct procedure for nvs implementation?
Hi
No, it shouldn't be necessary to reinitialize the entire fs every time you write or read, but one of the init functions are probably necessary. What exactly "isn't working". Do you get any error codes/messages that tell you what it is that fails exactly if you don't reinitialize the fs? Do you perhaps uninit the filesystem after a write/read in your application?
Either way, it might be worth checking out the Emergency data storage library instead of using NVS, which lets you do frequent storing of data while preventing wear and tear of the flash memory. Please check it out, as it may be a better option for you.
Best regards,
Simon
but one of the init functions are probably necessary.
Yes, the nvs_mount() needs to be called again right?.
Do you get any error codes/messages that tell you what it is that fails exactly if you don't reinitialize the fs?
the nvs_write returns the no.of bytes written(26 in my case) as mentioned in file. But when i read using nvs_read, the content didn't get updated as it shows the previously stored content.
Do you perhaps uninit the filesystem after a write/read in your application?
No, i dont think so, i have only used the previously mentioned lines for initializing and nvs_read ,nvs_write only.
I will check out the EMDS library, but now i also see in the device memory layout, whenever i reset and read the memory contents each time the size gets increased by 16 & 32 bytes erspectively on application area from F8.


Any idea why does this happen?. This happens each time only if i call nvs_write.
Hi
nvs_mount() should only be necessary to do when initializing the Flash, and not every time you do a read/write function. You can see the \<NCS_FOLDER>\v2.2.0\zephyr\samples\subsys\nvs for reference here.
After doing a new nvs_write() function, do you update the address from which you're reading in order to get the new data. If you get the previously stored data, that would point to you reading the same address(es) again.
Vignesh R said:whenever i reset and read the memory contents each time the size gets increased by 16 & 32 bytes
Can you explain/show what functions exactly are used when you read/reset the memory contents? Does a reset also result in an nvs_write perhaps? This should only increase if you write something new to the nRF device's flash I believe.
Best regards,
Simon