Re: Bluetooth: about using of NVS & setting Layer in single App


laczenJMS
 

Hi Vikrant,

The dts changes you propose might work, but there are some
disadvantages with it: if you are overlapping the scratch area with
NVS you will loose the data in NVS persistent storage after FOTA.

I guess this is related to your problem on using persistent storage
with btmesh. According to me the best way to use persistent storage in
combination with "btsettings" is to use "btsettings" to store and
retrieve your persistent variables. I don't have the time at the
moment to write a complete example but I can give you some guidelines:

Suppose we need to store a variable named: VID, and its value is
VID_VALUE. The values will be stored under "bt/ps". We will need to
define routines to apply the data at startup from flash: this is a set
routine. Other routines that we could define are export (to save the
data) and commit (to apply the data). For simplicity I will only
describe the case where there is only a set routine and storage will
be done directly.

Registering the routines is done by: BT_SETTINGS_DEFINE(ps, ps_set,
NULL, NULL): this will define a routine ps_set that will be called if
a variable is found under "bt/ps" (e.g. "bt/ps/VID"). The routine
ps_set itself is something like:

static int ps_set(int argc, char **argv, char *val) {
if (argc!=1) {
return -EINVAL;
}
if (strcmp(argv[0],"VID")==0) {
len = sizeof(VID_VALUE);
err = settings_bytes_from_str(val, VID_VALUE, &len);
}
}

This routine will be called at startup and when VID is found under
"bt/ps" its value will be used to update VID_VALUE.

To store the variable you have to call two routines :
str = settings_str_from_bytes(&VID_VALUE, sizeof(VID_VALUE), buf,
sizeof(buf));
settings_save_one("bt/ps/VID", str);

The used buffer is a char array that can be defined as: char
buf[BT_SETTINGS_SIZE(sizeof(VID_VALUE))];
Op ma 24 sep. 2018 om 10:36 schreef Vikrant More <vikrant8051@gmail.com>:


Hi,

I've modified nrf52840_pca10056.dts as follow ......

&flash0 {
/*
* For more information, see:
* http://docs.zephyrproject.org/latest/devices/dts/flash_partitions.html
*/
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

boot_partition: partition@0 {
label = "mcuboot";
reg = <0x000000000 0x0000C000>;
};
slot0_partition: partition@c000 {
label = "image-0";
reg = <0x0000C000 0x000069000>;
};
slot1_partition: partition@75000 {
label = "image-1";
reg = <0x00075000 0x000069000>;
};
scratch_partition: partition@de000 {
label = "image-scratch";
reg = <0x000de000 0x0001B000>;
};
nvs_partition: partition@f9000 {
label = "storage";
reg = <0x000f9000 0x00003000>;
};

#if defined(CONFIG_FS_FLASH_STORAGE_PARTITION)
storage_partition: partition@fc000 {
label = "storage";
reg = <0x000fc000 0x00004000>;
};
#endif
};
};

That means some part of scratch partition will get utilize ( 12 KB) for #NVS storage.
After this I've to set #define NVS_STORAGE_OFFSET 0xF9000

Is it correct strategy to save App level data on SoC flash without disturbing
#settings_layer data as well feature of #FOTA ?

Thank You !!

Join devel@lists.zephyrproject.org to automatically receive all group messages.