5
5
6
6
The settings subsystem gives modules a way to store persistent per-device
7
7
configuration and runtime state. A variety of storage implementations are
8
- provided behind a common API using FCB, NVS, or a file system. These different
9
- implementations give the application developer flexibility to select an
10
- appropriate storage medium, and even change it later as needs change. This
8
+ provided behind a common API using FCB, NVS, ZMS or a file system. These
9
+ different implementations give the application developer flexibility to select
10
+ an appropriate storage medium, and even change it later as needs change. This
11
11
subsystem is used by various Zephyr components and can be used simultaneously by
12
12
user applications.
13
13
@@ -23,8 +23,8 @@ For an example of the settings subsystem refer to :zephyr:code-sample:`settings`
23
23
24
24
.. note ::
25
25
26
- As of Zephyr release 2 .1 the recommended backend for non-filesystem
27
- storage is :ref: `NVS <nvs_api >`.
26
+ As of Zephyr release 4 .1 the recommended backends for non-filesystem
27
+ storage are :ref: `NVS <nvs_api >` and :ref: ` ZMS < zms_api >`.
28
28
29
29
Handlers
30
30
********
@@ -39,7 +39,7 @@ for static handlers.
39
39
:c:func: `settings_runtime_get() ` from the runtime backend.
40
40
41
41
**h_set **
42
- This gets called when the value is loaded from persisted storage with
42
+ This gets called when the value is loaded from persistent storage with
43
43
:c:func: `settings_load() `, or when using :c:func: `settings_runtime_set() ` from the
44
44
runtime backend.
45
45
@@ -93,10 +93,12 @@ backend.
93
93
Zephyr Storage Backends
94
94
***********************
95
95
96
- Zephyr has three storage backends: a Flash Circular Buffer
97
- (:kconfig:option: `CONFIG_SETTINGS_FCB `), a file in the filesystem
98
- (:kconfig:option: `CONFIG_SETTINGS_FILE `), or non-volatile storage
99
- (:kconfig:option: `CONFIG_SETTINGS_NVS `).
96
+ Zephyr offers the following storage backends:
97
+
98
+ * Flash Circular Buffer (:kconfig:option: `CONFIG_SETTINGS_FCB `).
99
+ * A file in the filesystem (:kconfig:option: `CONFIG_SETTINGS_FILE `).
100
+ * Non-Volatile Storage (:kconfig:option: `CONFIG_SETTINGS_NVS `).
101
+ * Zephyr Memory Storage (:kconfig:option: `CONFIG_SETTINGS_ZMS `).
100
102
101
103
You can declare multiple sources for settings; settings from
102
104
all of these are restored when :c:func: `settings_load() ` is called.
@@ -109,23 +111,36 @@ using :c:func:`settings_fcb_dst()`. As a side-effect, :c:func:`settings_fcb_src
109
111
initializes the FCB area, so it must be called before calling
110
112
:c:func: `settings_fcb_dst() `. File read target is registered using
111
113
:c:func: `settings_file_src() `, and write target by using :c:func: `settings_file_dst() `.
114
+
112
115
Non-volatile storage read target is registered using
113
116
:c:func: `settings_nvs_src() `, and write target by using
114
117
:c:func: `settings_nvs_dst() `.
115
118
119
+ Zephyr Memory Storage (ZMS) read target is registered using :c:func: `settings_zms_src() `,
120
+ and write target is registered using :c:func: `settings_zms_dst() `.
121
+
122
+ ZMS backend has the particularity of using hash functions to hash the settings
123
+ key before storing it to the persistent storage. This implementation implies
124
+ that some collisions between key's hashes could occur if a big number of
125
+ different keys are stored. This number depends on the selected hash function.
126
+
127
+ ZMS backend can handle :math: `2 ^n` maximum collisions where n is defined by
128
+ (:kconfig:option: `SETTINGS_ZMS_MAX_COLLISIONS_BITS `).
129
+
130
+
116
131
Storage Location
117
132
****************
118
133
119
- The FCB and non-volatile storage (NVS) backends both look for a fixed
134
+ The FCB, non-volatile storage (NVS) and ZMS backends look for a fixed
120
135
partition with label "storage" by default. A different partition can be
121
136
selected by setting the ``zephyr,settings-partition `` property of the
122
137
chosen node in the devicetree.
123
138
124
139
The file path used by the file backend to store settings is selected via the
125
140
option :kconfig:option: `CONFIG_SETTINGS_FILE_PATH `.
126
141
127
- Loading data from persisted storage
128
- ***********************************
142
+ Loading data from persistent storage
143
+ ************************************
129
144
130
145
A call to :c:func: `settings_load() ` uses an ``h_set `` implementation
131
146
to load settings data from storage to volatile memory.
@@ -146,7 +161,7 @@ A call to :c:func:`settings_save_one()` uses a backend implementation to store
146
161
settings data to the storage medium. A call to :c:func: `settings_save() ` uses an
147
162
``h_export `` implementation to store different data in one operation using
148
163
:c:func: `settings_save_one() `.
149
- A key need to be covered by a ``h_export `` only if it is supposed to be stored
164
+ A key needs to be covered by a ``h_export `` only if it is supposed to be stored
150
165
by :c:func: `settings_save() ` call.
151
166
152
167
For both FCB and file back-end only storage requests with data which
@@ -227,7 +242,7 @@ Example: Persist Runtime State
227
242
228
243
This is a simple example showing how to persist runtime state. In this example,
229
244
only ``h_set `` is defined, which is used when restoring value from
230
- persisted storage.
245
+ persistent storage.
231
246
232
247
In this example, the ``main `` function increments ``foo_val ``, and then
233
248
persists the latest number. When the system restarts, the application calls
0 commit comments