Skip to content

Commit 870aa2d

Browse files
committed
espidf: Add function to erase nvs
This may be necessary for some cases of migrating from 6.3.0 to 7.0.0.
1 parent 54d7ddc commit 870aa2d

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

locale/circuitpython.pot

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ msgstr ""
12251225
msgid "Insufficient encryption"
12261226
msgstr ""
12271227

1228-
#: ports/raspberrypi/audio_dma.c
1228+
#: ports/atmel-samd/audio_dma.c ports/raspberrypi/audio_dma.c
12291229
msgid "Internal audio buffer too small"
12301230
msgstr ""
12311231

@@ -1392,7 +1392,8 @@ msgstr ""
13921392
#: ports/mimxrt10xx/common-hal/busio/SPI.c ports/nrf/common-hal/busio/I2C.c
13931393
#: ports/raspberrypi/common-hal/busio/I2C.c
13941394
#: ports/raspberrypi/common-hal/busio/SPI.c
1395-
#: ports/raspberrypi/common-hal/busio/UART.c
1395+
#: ports/raspberrypi/common-hal/busio/UART.c shared-bindings/busio/SPI.c
1396+
#: shared-bindings/busio/UART.c
13961397
msgid "Invalid pins"
13971398
msgstr ""
13981399

@@ -3915,8 +3916,10 @@ msgstr ""
39153916
#: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h
39163917
#: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h
39173918
#: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h
3919+
#: ports/esp32s2/boards/ai_thinker_esp_12k_nodemcu/mpconfigboard.h
39183920
#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h
39193921
#: ports/esp32s2/boards/atmegazero_esp32s2/mpconfigboard.h
3922+
#: ports/esp32s2/boards/crumpspace_crumps2/mpconfigboard.h
39203923
#: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h
39213924
#: ports/esp32s2/boards/espressif_kaluga_1.3/mpconfigboard.h
39223925
#: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h
@@ -3933,6 +3936,7 @@ msgstr ""
39333936
#: ports/esp32s2/boards/morpheans_morphesp-240/mpconfigboard.h
39343937
#: ports/esp32s2/boards/muselab_nanoesp32_s2_wroom/mpconfigboard.h
39353938
#: ports/esp32s2/boards/muselab_nanoesp32_s2_wrover/mpconfigboard.h
3939+
#: ports/esp32s2/boards/odt_pixelwing_esp32_s2/mpconfigboard.h
39363940
#: ports/esp32s2/boards/targett_module_clip_wroom/mpconfigboard.h
39373941
#: ports/esp32s2/boards/targett_module_clip_wrover/mpconfigboard.h
39383942
#: ports/esp32s2/boards/unexpectedmaker_feathers2/mpconfigboard.h

ports/esp32s2/bindings/espidf/__init__.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@
2626

2727
#include "py/obj.h"
2828
#include "py/runtime.h"
29+
#include "py/mphal.h"
30+
2931

3032
#include "bindings/espidf/__init__.h"
3133

34+
#include "nvs_flash.h"
3235
#include "components/heap/include/esp_heap_caps.h"
3336

3437
//| """Direct access to a few ESP-IDF details. This module *should not* include any functionality
@@ -65,6 +68,20 @@ STATIC mp_obj_t espidf_heap_caps_get_largest_free_block(void) {
6568
}
6669
MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_largest_free_block_obj, espidf_heap_caps_get_largest_free_block);
6770

71+
//| def erase_nvs() -> None:
72+
//| """Erase all data in the non-volatile storage (nvs), including data stored by with `microcontroller.nvm`
73+
//|
74+
//| This is necessary when upgrading from CircuitPython 6.3.0 or earlier to CircuitPython 7.0.0, because the
75+
//| layout of data in nvs has changed. The old data will be lost when you perform this operation."""
76+
STATIC mp_obj_t espidf_erase_nvs(void) {
77+
ESP_ERROR_CHECK(nvs_flash_deinit());
78+
ESP_ERROR_CHECK(nvs_flash_erase());
79+
ESP_ERROR_CHECK(nvs_flash_init());
80+
return mp_const_none;
81+
}
82+
MP_DEFINE_CONST_FUN_OBJ_0(espidf_erase_nvs_obj, espidf_erase_nvs);
83+
84+
6885
//| class IDFError(OSError):
6986
//| """Raised for certain generic ESP IDF errors."""
7087
//| ...
@@ -117,6 +134,8 @@ STATIC const mp_rom_map_elem_t espidf_module_globals_table[] = {
117134
{ MP_ROM_QSTR(MP_QSTR_heap_caps_get_free_size), MP_ROM_PTR(&espidf_heap_caps_get_free_size_obj)},
118135
{ MP_ROM_QSTR(MP_QSTR_heap_caps_get_largest_free_block), MP_ROM_PTR(&espidf_heap_caps_get_largest_free_block_obj)},
119136

137+
{ MP_ROM_QSTR(MP_QSTR_erase_nvs), MP_ROM_PTR(&espidf_erase_nvs_obj)},
138+
120139
{ MP_ROM_QSTR(MP_QSTR_IDFError), MP_ROM_PTR(&mp_type_espidf_IDFError) },
121140
{ MP_ROM_QSTR(MP_QSTR_MemoryError), MP_ROM_PTR(&mp_type_espidf_MemoryError) },
122141
};

0 commit comments

Comments
 (0)