55
66The settings subsystem gives modules a way to store persistent per-device
77configuration 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
1111subsystem is used by various Zephyr components and can be used simultaneously by
1212user applications.
1313
@@ -23,8 +23,8 @@ For an example of the settings subsystem refer to :zephyr:code-sample:`settings`
2323
2424.. note ::
2525
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 >`.
2828
2929Handlers
3030********
@@ -39,7 +39,7 @@ for static handlers.
3939 :c:func: `settings_runtime_get() ` from the runtime backend.
4040
4141**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
4343 :c:func: `settings_load() `, or when using :c:func: `settings_runtime_set() ` from the
4444 runtime backend.
4545
@@ -93,10 +93,12 @@ backend.
9393Zephyr Storage Backends
9494***********************
9595
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 `).
100102
101103You can declare multiple sources for settings; settings from
102104all 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
109111initializes the FCB area, so it must be called before calling
110112:c:func: `settings_fcb_dst() `. File read target is registered using
111113:c:func: `settings_file_src() `, and write target by using :c:func: `settings_file_dst() `.
114+
112115Non-volatile storage read target is registered using
113116:c:func: `settings_nvs_src() `, and write target by using
114117:c:func: `settings_nvs_dst() `.
115118
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+
116131Storage Location
117132****************
118133
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
120135partition with label "storage" by default. A different partition can be
121136selected by setting the ``zephyr,settings-partition `` property of the
122137chosen node in the devicetree.
123138
124139The file path used by the file backend to store settings is selected via the
125140option :kconfig:option: `CONFIG_SETTINGS_FILE_PATH `.
126141
127- Loading data from persisted storage
128- ***********************************
142+ Loading data from persistent storage
143+ ************************************
129144
130145A call to :c:func: `settings_load() ` uses an ``h_set `` implementation
131146to 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
146161settings data to the storage medium. A call to :c:func: `settings_save() ` uses an
147162``h_export `` implementation to store different data in one operation using
148163: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
150165by :c:func: `settings_save() ` call.
151166
152167For both FCB and file back-end only storage requests with data which
@@ -227,7 +242,7 @@ Example: Persist Runtime State
227242
228243This is a simple example showing how to persist runtime state. In this example,
229244only ``h_set `` is defined, which is used when restoring value from
230- persisted storage.
245+ persistent storage.
231246
232247In this example, the ``main `` function increments ``foo_val ``, and then
233248persists the latest number. When the system restarts, the application calls
0 commit comments