Concurrent usage of NV and settings on the same partition

Hi,

Is it safe to use NVS and Settings on the same partition at the same time (the same application, BLE is running, NVS can be called concurrently to eg. pairing process)?

Assumptions:

  • Code that is using NVS performs nvs_init() on the settings_storage partition
  • Code that is using NVS is not exceeding  NVS_NAMECNT_ID  id

Dominik,

Parents
  • Hello Dominik,

    I'll take a look at this today/Monday

    Best regards,

    Simon

  • Hi,

    Sorry for long idle time but we had to consider other options that could replace NVS. The discussion ends up with a statement that NV + Settings is what we really need to have in product. Please find attached reproduction app.


    Application flow is:
    - Initialize NV, do some read/write

    - Pair

    -Read/Write

    -Reboot

    After reboot there is no bounded device found.

    I wonder if NVS+Settings shopuld work using theirs own APIs or if I should provide custorm load/save implementation for settings that will use NVS that is initialized in sope of my application.

    Dominik,

    settings_nvs_ble.7z

  • Hello Dominik,

    I'll test your sample next week

    Best regards,

    Simon

  • I talked to a developer, and one thing we forgot to inform you about, is that you need to use the same nvs_fs struct as the settings backend.

    Please apply this patch to Zephyr v3.0.99-ncs1 (part of NCS v2.0.0):

    diff --git a/subsys/settings/src/settings_nvs.c b/subsys/settings/src/settings_nvs.c
    index 24e7a9e79e..85c5da8f0c 100644
    --- a/subsys/settings/src/settings_nvs.c
    +++ b/subsys/settings/src/settings_nvs.c
    @@ -273,9 +273,14 @@ int settings_nvs_backend_init(struct settings_nvs *cf)
     	return 0;
     }
     
    +static struct settings_nvs default_settings_nvs;
    +
    +struct nvs_fs* get_nvs_fs_structure(void){
    +	return &default_settings_nvs.cf_nvs;
    +}
    +
     int settings_backend_init(void)
     {
    -	static struct settings_nvs default_settings_nvs;
     	int rc;
     	uint16_t cnt = 0;
     	size_t nvs_sector_size, nvs_size = 0;
    

    I simply added an API to get the nvs_fs struct

    Then test the following sample:

    settings_nvs_ble_v2.zip

    I modified your sample to use the API to get the nvs_fs settings struct and use that for your nvs calls.

Reply
  • I talked to a developer, and one thing we forgot to inform you about, is that you need to use the same nvs_fs struct as the settings backend.

    Please apply this patch to Zephyr v3.0.99-ncs1 (part of NCS v2.0.0):

    diff --git a/subsys/settings/src/settings_nvs.c b/subsys/settings/src/settings_nvs.c
    index 24e7a9e79e..85c5da8f0c 100644
    --- a/subsys/settings/src/settings_nvs.c
    +++ b/subsys/settings/src/settings_nvs.c
    @@ -273,9 +273,14 @@ int settings_nvs_backend_init(struct settings_nvs *cf)
     	return 0;
     }
     
    +static struct settings_nvs default_settings_nvs;
    +
    +struct nvs_fs* get_nvs_fs_structure(void){
    +	return &default_settings_nvs.cf_nvs;
    +}
    +
     int settings_backend_init(void)
     {
    -	static struct settings_nvs default_settings_nvs;
     	int rc;
     	uint16_t cnt = 0;
     	size_t nvs_sector_size, nvs_size = 0;
    

    I simply added an API to get the nvs_fs struct

    Then test the following sample:

    settings_nvs_ble_v2.zip

    I modified your sample to use the API to get the nvs_fs settings struct and use that for your nvs calls.

Children
Related