File tree 1 file changed +17
-1
lines changed
1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 18
18
#include "freertos/task.h"
19
19
#include "esp_attr.h"
20
20
#include "nvs_flash.h"
21
+ #include "nvs.h"
22
+ #include "esp_partition.h"
21
23
#include <sys/time.h>
22
24
23
25
void yield ()
@@ -76,7 +78,21 @@ void init() {}
76
78
77
79
void initArduino ()
78
80
{
79
- nvs_flash_init ();
81
+ esp_err_t err = nvs_flash_init ();
82
+ if (err == ESP_ERR_NVS_NO_FREE_PAGES ){
83
+ const esp_partition_t * partition = esp_partition_find_first (ESP_PARTITION_TYPE_DATA , ESP_PARTITION_SUBTYPE_DATA_NVS , NULL );
84
+ if (partition != NULL ) {
85
+ err = esp_partition_erase_range (partition , 0 , partition -> size );
86
+ if (!err ){
87
+ err = nvs_flash_init ();
88
+ } else {
89
+ log_e ("Failed to format the broken NVS partition!" );
90
+ }
91
+ }
92
+ }
93
+ if (err ) {
94
+ log_e ("Failed to initialize NVS! Error: %u" , err );
95
+ }
80
96
init ();
81
97
initVariant ();
82
98
}
You can’t perform that action at this time.
0 commit comments