NVS corrupt after applying sys_reboot() directly after nvs_write() #nrf52840


Phil Hipp
 

Hi,

in my application, I want to apply a reboot via sys_reboot(SYS_REBOOT_WARM) directly after writing a specific value to NVS via nvs_write() to cleanly reinitialize the system with that value in NVS.

But somehow it seems that the NVS got corrupted by the reboot. When I try to initialize the NVS with nvs_init() after the reboot it always returns -22 (-EINVAL). The error seems to appear in nvs_gc().

Can anybody tell me, what I'm doing wrong here?

 

Best

Philipp


Phil Hipp
 

I found out that NVS seems to interfere with the settings fcb. I'm using that for the bt settings (pairing keys, etc.). Is there any way to use the settings fcb and NVS concurrently?


Phil Hipp
 

Alright, I fixed that issue by splitting the predefined flash storage partition (storage_partition) in the board's dts in half. Leaving the name of the first one as is and naming the second one storage_partition_nvs. I now have following layout:

- storage_partiton - size 0x2000 - used by FCB.
- storage_partiton_nvs - size 0x2000 - used by NVS.

Hope this will work.