Skip to content

Commit 45d51f0

Browse files
committed
Better NVS reset, late disk init
1 parent cbd4ede commit 45d51f0

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

ats-mini/Storage.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "Themes.h"
44
#include "Menu.h"
55
#include <LittleFS.h>
6+
#include "nvs_flash.h"
67

78
// Time of inactivity to start writing preferences
89
#define STORE_TIME 10000
@@ -345,3 +346,11 @@ bool diskInit(bool force)
345346
// Serial.println("Mounted LittleFS!");
346347
return(true);
347348
}
349+
350+
bool nvsErase()
351+
{
352+
return(nvs_flash_erase() == ESP_OK &&
353+
nvs_flash_init() == ESP_OK &&
354+
nvs_flash_erase_partition(STORAGE_PARTITION) == ESP_OK &&
355+
nvs_flash_init_partition(STORAGE_PARTITION) == ESP_OK);
356+
}

ats-mini/Storage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern Preferences prefs;
1717
void prefsTickTime();
1818
void prefsInvalidate();
1919
bool prefsAreWritten();
20+
bool nvsErase();
2021

2122
bool diskInit(bool force = false);
2223

ats-mini/ats-mini.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ void setup()
108108
// Enable serial port
109109
Serial.begin(115200);
110110

111-
// Initialize flash file system
112-
diskInit();
113-
114111
// Encoder pins. Enable internal pull-ups
115112
pinMode(ENCODER_PUSH_BUTTON, INPUT_PULLUP);
116113
pinMode(ENCODER_PIN_A, INPUT_PULLUP);
@@ -157,7 +154,7 @@ void setup()
157154
// Note: preferences reset is recommended after firmware updates
158155
if(digitalRead(ENCODER_PUSH_BUTTON)==LOW)
159156
{
160-
prefsInvalidate();
157+
nvsErase();
161158
diskInit(true);
162159

163160
ledcWrite(PIN_LCD_BL, 255); // Default value 255 = 100%
@@ -170,6 +167,9 @@ void setup()
170167
while(digitalRead(ENCODER_PUSH_BUTTON) == LOW) delay(100);
171168
}
172169

170+
// Initialize flash file system
171+
diskInit();
172+
173173
// Check for SI4732 connected on I2C interface
174174
// If the SI4732 is not detected, then halt with no further processing
175175
rx.setI2CFastModeCustom(100000);

0 commit comments

Comments
 (0)