Check and format NVS partition if size has changed
This commit is contained in:
parent
80322311f1
commit
b465858563
@ -18,6 +18,8 @@
|
||||
#include "freertos/task.h"
|
||||
#include "esp_attr.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "nvs.h"
|
||||
#include "esp_partition.h"
|
||||
#include <sys/time.h>
|
||||
|
||||
void yield()
|
||||
@ -76,7 +78,21 @@ void init() {}
|
||||
|
||||
void initArduino()
|
||||
{
|
||||
nvs_flash_init();
|
||||
esp_err_t err = nvs_flash_init();
|
||||
if(err == ESP_ERR_NVS_NO_FREE_PAGES){
|
||||
const esp_partition_t* partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, NULL);
|
||||
if (partition != NULL) {
|
||||
err = esp_partition_erase_range(partition, 0, partition->size);
|
||||
if(!err){
|
||||
err = nvs_flash_init();
|
||||
} else {
|
||||
log_e("Failed to format the broken NVS partition!");
|
||||
}
|
||||
}
|
||||
}
|
||||
if(err) {
|
||||
log_e("Failed to initialize NVS! Error: %u", err);
|
||||
}
|
||||
init();
|
||||
initVariant();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user