Espressif ESP32-S2 Programming Manual page 731

Table of Contents

Advertisement

Chapter 2. API Reference
• [in] handle: Storage handle obtained with nvs_open. Handles that were opened read only
cannot be used.
esp_err_t nvs_commit(nvs_handle_t
Write any pending changes to non-volatile storage.
After setting any values, nvs_commit() must be called to ensure changes are written to non-volatile storage.
Individual implementations may write to storage at other times, but this is not guaranteed.
Return
• ESP_OK if the changes have been written successfully
• ESP_ERR_NVS_INVALID_HANDLE if handle has been closed or is NULL
• other error codes from the underlying storage driver
Parameters
• [in] handle: Storage handle obtained with nvs_open. Handles that were opened read only
cannot be used.
void
nvs_close(nvs_handle_t
Close the storage handle and free any allocated resources.
This function should be called for each handle opened with nvs_open once the handle is not in use any more.
Closing the handle may not automatically write the changes to nonvolatile storage. This has to be done explicitly
using nvs_commit function. Once this function is called on a handle, the handle should no longer be used.
Parameters
• [in] handle: Storage handle to close
esp_err_t
nvs_get_stats(const char *part_name,
Fill structure nvs_stats_t. It provides info about used memory the partition.
This function calculates to runtime the number of used entries, free entries, total entries, and amount namespace
in partition.
// Example of nvs_get_stats() to get the number of used entries and
entries:
nvs_stats_t nvs_stats;
nvs_get_stats(NULL, &nvs_stats);
printf("Count: UsedEntries = (%d), FreeEntries = (%d), AllEntries = (%d)\n",
nvs_stats.used_entries, nvs_stats.free_entries, nvs_stats.total_
entries);
Return
• ESP_OK if the changes have been written successfully. Return param nvs_stats will be filled.
• ESP_ERR_NVS_PART_NOT_FOUND if the partition with label "name"is not found. Return
param nvs_stats will be filled 0.
• ESP_ERR_NVS_NOT_INITIALIZED if the storage driver is not initialized.
nvs_stats will be filled 0.
• ESP_ERR_INVALID_ARG if nvs_stats equal to NULL.
• ESP_ERR_INVALID_STATE if there is page with the status of INVALID. Return param nvs_stats
will be filled not with correct values because not all pages will be counted. Counting will be inter-
rupted at the first INVALID page.
Parameters
• [in] part_name: Partition name NVS in the partition table. If pass a NULL than will use
NVS_DEFAULT_PART_NAME ("nvs").
• [out] nvs_stats: Returns filled structure nvs_states_t. It provides info about used memory
the partition.
esp_err_t nvs_get_used_entry_count(nvs_handle_t
Calculate all entries in a namespace.
An entry represents the smallest storage unit in NVS. Strings and blobs may occupy more than one entry.
Note that to find out the total number of entries occupied by the namespace, add one to the returned value
used_entries (if err is equal to ESP_OK). Because the name space entry takes one entry.
Espressif Systems
handle)
handle)
nvs_stats_t
720
Submit Document Feedback
*nvs_stats)
handle, size_t *used_entries)
free␣
Return param
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents

Save PDF