Skip to content

Commit c455d6f

Browse files
committed
Merge branch 'feature/nvs_version_check_v3.1' into 'release/v3.1'
nvs_flash: Version compatibility check for nvs storage (backport 3.1) See merge request idf/esp-idf!2958
2 parents b3eee7d + a3b5a23 commit c455d6f

File tree

44 files changed

+74
-47
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+74
-47
lines changed

components/driver/test/test_adc2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ TEST_CASE("adc2 work with wifi","[adc]")
5656
//init wifi
5757
printf("nvs init\n");
5858
esp_err_t r = nvs_flash_init();
59-
if (r == ESP_ERR_NVS_NO_FREE_PAGES) {
60-
printf("no free pages, erase..\n");
59+
if (r == ESP_ERR_NVS_NO_FREE_PAGES || r == ESP_ERR_NVS_NEW_VERSION_FOUND) {
60+
printf("no free pages or nvs version mismatch, erase..\n");
6161
TEST_ESP_OK(nvs_flash_erase());
6262
r = nvs_flash_init();
6363
}

components/esp32/esp_err_to_name.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ static const esp_err_msg_t esp_err_msg_table[] = {
157157
# ifdef ESP_ERR_NVS_PART_NOT_FOUND
158158
ERR_TBL_IT(ESP_ERR_NVS_PART_NOT_FOUND), /* 4367 0x110f Partition with specified name is not found
159159
in the partition table */
160+
# endif
161+
# ifdef ESP_ERR_NVS_NEW_VERSION_FOUND
162+
ERR_TBL_IT(ESP_ERR_NVS_NEW_VERSION_FOUND), /* 4368 0x1110 NVS partition contains data in new format
163+
and cannot be recognized by this version of
164+
code */
160165
# endif
161166
// components/ulp/include/esp32/ulp.h
162167
# ifdef ESP_ERR_ULP_BASE

components/esp32/test/test_esp32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ TEST_CASE("wifi stop and deinit","[wifi]")
8383
//init nvs
8484
ESP_LOGI(TAG, EMPH_STR("nvs_flash_init"));
8585
esp_err_t r = nvs_flash_init();
86-
if (r == ESP_ERR_NVS_NO_FREE_PAGES) {
87-
ESP_LOGI(TAG, EMPH_STR("no free pages, erase.."));
86+
if (r == ESP_ERR_NVS_NO_FREE_PAGES || r == ESP_ERR_NVS_NEW_VERSION_FOUND) {
87+
ESP_LOGI(TAG, EMPH_STR("no free pages or nvs version mismatch, erase.."));
8888
TEST_ESP_OK(nvs_flash_erase());
8989
r = nvs_flash_init();
9090
}

components/nvs_flash/include/nvs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ typedef uint32_t nvs_handle;
4444
#define ESP_ERR_NVS_NO_FREE_PAGES (ESP_ERR_NVS_BASE + 0x0d) /*!< NVS partition doesn't contain any empty pages. This may happen if NVS partition was truncated. Erase the whole partition and call nvs_flash_init again. */
4545
#define ESP_ERR_NVS_VALUE_TOO_LONG (ESP_ERR_NVS_BASE + 0x0e) /*!< String or blob length is longer than supported by the implementation */
4646
#define ESP_ERR_NVS_PART_NOT_FOUND (ESP_ERR_NVS_BASE + 0x0f) /*!< Partition with specified name is not found in the partition table */
47+
#define ESP_ERR_NVS_NEW_VERSION_FOUND (ESP_ERR_NVS_BASE + 0x10) /*!< NVS partition contains data in new format and cannot be recognized by this version of code */
4748

4849
#define NVS_DEFAULT_PART_NAME "nvs" /*!< Default partition name of the NVS partition in the partition table */
4950
/**

components/nvs_flash/src/nvs_page.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ esp_err_t Page::load(uint32_t sectorNumber)
6464
} else {
6565
mState = header.mState;
6666
mSeqNumber = header.mSeqNumber;
67+
if(header.mVersion < NVS_VERSION) {
68+
return ESP_ERR_NVS_NEW_VERSION_FOUND;
69+
} else {
70+
mVersion = header.mVersion;
71+
}
6772
}
6873

6974
switch (mState) {
@@ -628,6 +633,7 @@ esp_err_t Page::initialize()
628633
Header header;
629634
header.mState = mState;
630635
header.mSeqNumber = mSeqNumber;
636+
header.mVersion = mVersion;
631637
header.mCrc32 = header.calculateCrc32();
632638

633639
auto rc = spi_flash_write(mBaseAddress, &header, sizeof(header));
@@ -799,6 +805,15 @@ esp_err_t Page::setSeqNumber(uint32_t seqNumber)
799805
return ESP_OK;
800806
}
801807

808+
esp_err_t Page::setVersion(uint8_t ver)
809+
{
810+
if (mState != PageState::UNINITIALIZED) {
811+
return ESP_ERR_NVS_INVALID_STATE;
812+
}
813+
mVersion = ver;
814+
return ESP_OK;
815+
}
816+
802817
esp_err_t Page::erase()
803818
{
804819
auto sector = mBaseAddress / SPI_FLASH_SEC_SIZE;

components/nvs_flash/src/nvs_page.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class Page : public intrusive_list_node<Page>
5151
static const uint8_t NS_INDEX = 0;
5252
static const uint8_t NS_ANY = 255;
5353

54+
static const uint8_t NVS_VERSION = 0xff; // Decrement to upgrade
55+
5456
enum class PageState : uint32_t {
5557
// All bits set, default state after flash erase. Page has not been initialized yet.
5658
UNINITIALIZED = 0xffffffff,
@@ -83,6 +85,8 @@ class Page : public intrusive_list_node<Page>
8385
esp_err_t getSeqNumber(uint32_t& seqNumber) const;
8486

8587
esp_err_t setSeqNumber(uint32_t seqNumber);
88+
89+
esp_err_t setVersion(uint8_t version);
8690

8791
esp_err_t writeItem(uint8_t nsIndex, ItemType datatype, const char* key, const void* data, size_t dataSize);
8892

@@ -142,12 +146,13 @@ class Page : public intrusive_list_node<Page>
142146
public:
143147
Header()
144148
{
145-
std::fill_n(mReserved, sizeof(mReserved)/sizeof(mReserved[0]), UINT32_MAX);
149+
std::fill_n(mReserved, sizeof(mReserved)/sizeof(mReserved[0]), UINT8_MAX);
146150
}
147151

148152
PageState mState; // page state
149153
uint32_t mSeqNumber; // sequence number of this page
150-
uint32_t mReserved[5]; // unused, must be 0xffffffff
154+
uint8_t mVersion; // nvs format version
155+
uint8_t mReserved[19]; // unused, must be 0xff
151156
uint32_t mCrc32; // crc of everything except mState
152157

153158
uint32_t calculateCrc32();
@@ -198,6 +203,7 @@ class Page : public intrusive_list_node<Page>
198203
uint32_t mBaseAddress = 0;
199204
PageState mState = PageState::INVALID;
200205
uint32_t mSeqNumber = UINT32_MAX;
206+
uint8_t mVersion = NVS_VERSION;
201207
typedef CompressedEnumTable<EntryState, 2, ENTRY_COUNT> TEntryTable;
202208
TEntryTable mEntryTable;
203209
size_t mNextFreeEntry = INVALID_ENTRY;

components/nvs_flash/test/test_nvs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ TEST_CASE("various nvs tests", "[nvs]")
1616
{
1717
nvs_handle handle_1;
1818
esp_err_t err = nvs_flash_init();
19-
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
19+
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
2020
ESP_LOGW(TAG, "nvs_flash_init failed (0x%x), erasing partition and retrying", err);
2121
const esp_partition_t* nvs_partition = esp_partition_find_first(
2222
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, NULL);
@@ -83,7 +83,7 @@ TEST_CASE("calculate used and free space", "[nvs]")
8383
TEST_ASSERT_TRUE(h_count_entries == 0);
8484

8585
esp_err_t err = nvs_flash_init();
86-
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
86+
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
8787
ESP_LOGW(TAG, "nvs_flash_init failed (0x%x), erasing partition and retrying", err);
8888
const esp_partition_t* nvs_partition = esp_partition_find_first(
8989
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, NULL);

examples/bluetooth/a2dp_gatts_coex/main/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ void app_main()
636636

637637
// Initialize NVS.
638638
ret = nvs_flash_init();
639-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
639+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
640640
ESP_ERROR_CHECK(nvs_flash_erase());
641641
ret = nvs_flash_init();
642642
}
@@ -703,4 +703,4 @@ void app_main()
703703
bt_app_work_dispatch(bt_av_hdl_stack_evt, BT_APP_EVT_STACK_UP, NULL, 0, NULL);
704704
//gatt server init
705705
ble_gatts_init();
706-
}
706+
}

examples/bluetooth/a2dp_sink/main/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void app_main()
4646
{
4747
/* Initialize NVS — it is used to store PHY calibration data */
4848
esp_err_t ret = nvs_flash_init();
49-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
49+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
5050
ESP_ERROR_CHECK(nvs_flash_erase());
5151
ret = nvs_flash_init();
5252
}

examples/bluetooth/a2dp_source/main/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void app_main()
100100
{
101101
// Initialize NVS.
102102
esp_err_t ret = nvs_flash_init();
103-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
103+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
104104
ESP_ERROR_CHECK(nvs_flash_erase());
105105
ret = nvs_flash_init();
106106
}

examples/bluetooth/ble_adv/main/app_bt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ void app_main()
214214
{
215215
/* Initialize NVS — it is used to store PHY calibration data */
216216
esp_err_t ret = nvs_flash_init();
217-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
217+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
218218
ESP_ERROR_CHECK(nvs_flash_erase());
219219
ret = nvs_flash_init();
220220
}

examples/bluetooth/ble_hid_device_demo/main/ble_hidd_demo_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ void app_main()
265265

266266
// Initialize NVS.
267267
ret = nvs_flash_init();
268-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
268+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
269269
ESP_ERROR_CHECK(nvs_flash_erase());
270270
ret = nvs_flash_init();
271271
}

examples/bluetooth/ble_spp_server/main/ble_spp_server_demo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ void app_main()
655655

656656
// Initialize NVS
657657
ret = nvs_flash_init();
658-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
658+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
659659
ESP_ERROR_CHECK(nvs_flash_erase());
660660
ret = nvs_flash_init();
661661
}

examples/bluetooth/ble_throughput/throughput_client/main/example_ble_client_throughput.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ void app_main()
519519
{
520520
// Initialize NVS.
521521
esp_err_t ret = nvs_flash_init();
522-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
522+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
523523
ESP_ERROR_CHECK(nvs_flash_erase());
524524
ret = nvs_flash_init();
525525
}

examples/bluetooth/ble_throughput/throughput_server/main/example_ble_server_throughput.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ void app_main()
641641

642642
// Initialize NVS.
643643
ret = nvs_flash_init();
644-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
644+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
645645
ESP_ERROR_CHECK(nvs_flash_erase());
646646
ret = nvs_flash_init();
647647
}

examples/bluetooth/blufi/main/blufi_example_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void app_main()
381381

382382
// Initialize NVS
383383
ret = nvs_flash_init();
384-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
384+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
385385
ESP_ERROR_CHECK(nvs_flash_erase());
386386
ret = nvs_flash_init();
387387
}

examples/bluetooth/bt_discovery/main/bt_discovery.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ void app_main()
273273
{
274274
/* Initialize NVS — it is used to store PHY calibration data */
275275
esp_err_t ret = nvs_flash_init();
276-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
276+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
277277
ESP_ERROR_CHECK(nvs_flash_erase());
278278
ret = nvs_flash_init();
279279
}

examples/bluetooth/bt_spp_acceptor/main/example_spp_acceptor_demo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
108108
void app_main()
109109
{
110110
esp_err_t ret = nvs_flash_init();
111-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
111+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
112112
ESP_ERROR_CHECK(nvs_flash_erase());
113113
ret = nvs_flash_init();
114114
}

examples/bluetooth/bt_spp_initiator/main/example_spp_initiator_demo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void app_main()
202202
}
203203

204204
esp_err_t ret = nvs_flash_init();
205-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
205+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
206206
ESP_ERROR_CHECK(nvs_flash_erase());
207207
ret = nvs_flash_init();
208208
}

examples/bluetooth/bt_spp_vfs_acceptor/main/example_spp_vfs_acceptor_demo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static void esp_spp_stack_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param
108108
void app_main()
109109
{
110110
esp_err_t ret = nvs_flash_init();
111-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
111+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
112112
ESP_ERROR_CHECK(nvs_flash_erase());
113113
ret = nvs_flash_init();
114114
}

examples/bluetooth/bt_spp_vfs_initiator/main/example_spp_vfs_initiator_demo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void app_main()
187187
}
188188

189189
esp_err_t ret = nvs_flash_init();
190-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
190+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
191191
ESP_ERROR_CHECK(nvs_flash_erase());
192192
ret = nvs_flash_init();
193193
}

examples/bluetooth/controller_hci_uart/main/controller_hci_uart_demo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void app_main()
3737

3838
/* Initialize NVS — it is used to store PHY calibration data */
3939
ret = nvs_flash_init();
40-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
40+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
4141
ESP_ERROR_CHECK(nvs_flash_erase());
4242
ret = nvs_flash_init();
4343
}

examples/bluetooth/gatt_client/main/gattc_demo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ void app_main()
414414
{
415415
// Initialize NVS.
416416
esp_err_t ret = nvs_flash_init();
417-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
417+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
418418
ESP_ERROR_CHECK(nvs_flash_erase());
419419
ret = nvs_flash_init();
420420
}

examples/bluetooth/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void app_main()
4141
{
4242
// Initialize NVS.
4343
esp_err_t ret = nvs_flash_init();
44-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
44+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
4545
ESP_ERROR_CHECK(nvs_flash_erase());
4646
ret = nvs_flash_init();
4747
}
@@ -103,7 +103,7 @@ The main function starts by initializing the non-volatile storage library. This
103103

104104
```c
105105
esp_err_t ret = nvs_flash_init();
106-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
106+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
107107
ESP_ERROR_CHECK(nvs_flash_erase());
108108
ret = nvs_flash_init();
109109
}

examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ void app_main()
460460
{
461461
// Initialize NVS.
462462
esp_err_t ret = nvs_flash_init();
463-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
463+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
464464
ESP_ERROR_CHECK(nvs_flash_erase());
465465
ret = nvs_flash_init();
466466
}

examples/bluetooth/gatt_security_server/main/example_ble_sec_gatts_demo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ void app_main()
469469

470470
// Initialize NVS.
471471
ret = nvs_flash_init();
472-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
472+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
473473
ESP_ERROR_CHECK(nvs_flash_erase());
474474
ret = nvs_flash_init();
475475
}

examples/bluetooth/gatt_server/main/gatts_demo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ void app_main()
679679

680680
// Initialize NVS.
681681
ret = nvs_flash_init();
682-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
682+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
683683
ESP_ERROR_CHECK(nvs_flash_erase());
684684
ret = nvs_flash_init();
685685
}

examples/bluetooth/gatt_server/tutorial/Gatt_Server_Example_Walkthrough.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The entry point to this example is the app_main() function:
4444

4545
// Initialize NVS.
4646
ret = nvs_flash_init();
47-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
47+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
4848
ESP_ERROR_CHECK(nvs_flash_erase());
4949
ret = nvs_flash_init();
5050
}

examples/bluetooth/gatt_server_service_table/main/gatts_table_creat_demo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ void app_main()
517517

518518
/* Initialize NVS. */
519519
ret = nvs_flash_init();
520-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
520+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
521521
ESP_ERROR_CHECK(nvs_flash_erase());
522522
ret = nvs_flash_init();
523523
}

examples/bluetooth/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void app_main()
8181
8282
// Initialize NVS.
8383
ret = nvs_flash_init();
84-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
84+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
8585
ESP_ERROR_CHECK(nvs_flash_erase());
8686
ret = nvs_flash_init();
8787
}

examples/bluetooth/gattc_multi_connect/main/gattc_multi_connect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ static void esp_gattc_cb(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp
886886
void app_main()
887887
{
888888
esp_err_t ret = nvs_flash_init();
889-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
889+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
890890
ESP_ERROR_CHECK(nvs_flash_erase());
891891
ret = nvs_flash_init();
892892
}

examples/protocols/aws_iot/subscribe_publish/main/subscribe_publish_sample.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ void app_main()
321321
{
322322
// Initialize NVS.
323323
esp_err_t err = nvs_flash_init();
324-
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
324+
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
325325
ESP_ERROR_CHECK(nvs_flash_erase());
326326
err = nvs_flash_init();
327327
}

examples/protocols/aws_iot/thing_shadow/main/thing_shadow_sample.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ static void initialise_wifi(void)
356356
void app_main()
357357
{
358358
esp_err_t err = nvs_flash_init();
359-
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
359+
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
360360
ESP_ERROR_CHECK(nvs_flash_erase());
361361
err = nvs_flash_init();
362362
}

examples/protocols/esp_http_client/main/esp_http_client_example.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ static void http_test_task(void *pvParameters)
351351
void app_main()
352352
{
353353
esp_err_t ret = nvs_flash_init();
354-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
354+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
355355
ESP_ERROR_CHECK(nvs_flash_erase());
356356
ret = nvs_flash_init();
357357
}

0 commit comments

Comments
 (0)