hyperlink-sw/components/nvs/src/nvs.cpp

27 lines
474 B
C++

#include <stdexcept>
#include "esp_err.h"
#include "nvs_flash.h"
namespace nvs {
void init() {
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
if (nvs_flash_erase() != ESP_OK)
throw std::runtime_error("Failed to erase NVS");
ret = nvs_flash_init();
}
if (ret != ESP_OK) throw std::runtime_error("Failed to initialize NVS");
}
} // namespace nvs