diff --git a/include/zephyr/settings/settings.h b/include/zephyr/settings/settings.h index 0bae0658d43..99b9fc21077 100644 --- a/include/zephyr/settings/settings.h +++ b/include/zephyr/settings/settings.h @@ -303,6 +303,16 @@ int settings_load_subtree_direct( */ int settings_save(void); +/** + * Save limited set of currently running serialized items. All serialized items + * that belong to subtree and which are different from currently persisted + * values will be saved. + * + * @param[in] subtree name of the subtree to be loaded. + * @return 0 on success, non-zero on failure. + */ +int settings_save_subtree(const char *subtree); + /** * Write a single serialized value to persisted storage (if it has * changed value). diff --git a/subsys/settings/src/settings_store.c b/subsys/settings/src/settings_store.c index d47b24f064b..b697f993d94 100644 --- a/subsys/settings/src/settings_store.c +++ b/subsys/settings/src/settings_store.c @@ -116,6 +116,11 @@ int settings_delete(const char *name) } int settings_save(void) +{ + return settings_save_subtree(NULL); +} + +int settings_save_subtree(const char *subtree) { struct settings_store *cs; int rc; @@ -132,6 +137,9 @@ int settings_save(void) rc = 0; STRUCT_SECTION_FOREACH(settings_handler_static, ch) { + if (subtree && !settings_name_steq(ch->name, subtree, NULL)) { + continue; + } if (ch->h_export) { rc2 = ch->h_export(settings_save_one); if (!rc) { @@ -143,6 +151,9 @@ int settings_save(void) #if defined(CONFIG_SETTINGS_DYNAMIC_HANDLERS) struct settings_handler *ch; SYS_SLIST_FOR_EACH_CONTAINER(&settings_handlers, ch, node) { + if (subtree && !settings_name_steq(ch->name, subtree, NULL)) { + continue; + } if (ch->h_export) { rc2 = ch->h_export(settings_save_one); if (!rc) {