@@ -131,13 +131,34 @@ mp_obj_t storage_getmount(const mp_obj_t mnt_in) {
131131}
132132MP_DEFINE_CONST_FUN_OBJ_1 (storage_getmount_obj , storage_getmount );
133133
134+ //| .. function:: erase_filesystem()
135+ //|
136+ //| Erase and re-create the ``CIRCUITPY`` filesystem.
137+ //|
138+ //| On boards that present USB-visible ``CIRCUITPY`` drive (e.g., SAMD21 and SAMD51),
139+ //| then call `microcontroller.reset()` to restart CircuitPython and have the
140+ //| host computer remount CIRCUITPY.
141+ //|
142+ //| This function can be called from the REPL when ``CIRCUITPY``
143+ //| has become corrupted.
144+ //|
145+ //| .. warning:: All the data on ``CIRCUITPY`` will be lost, and
146+ //| CircuitPython will restart on certain boards.
147+
148+ mp_obj_t storage_erase_filesystem (void ) {
149+ common_hal_storage_erase_filesystem ();
150+ return mp_const_none ;
151+ }
152+ MP_DEFINE_CONST_FUN_OBJ_0 (storage_erase_filesystem_obj , storage_erase_filesystem );
153+
134154STATIC const mp_rom_map_elem_t storage_module_globals_table [] = {
135155 { MP_ROM_QSTR (MP_QSTR___name__ ), MP_ROM_QSTR (MP_QSTR_storage ) },
136156
137157 { MP_ROM_QSTR (MP_QSTR_mount ), MP_ROM_PTR (& storage_mount_obj ) },
138158 { MP_ROM_QSTR (MP_QSTR_umount ), MP_ROM_PTR (& storage_umount_obj ) },
139159 { MP_ROM_QSTR (MP_QSTR_remount ), MP_ROM_PTR (& storage_remount_obj ) },
140160 { MP_ROM_QSTR (MP_QSTR_getmount ), MP_ROM_PTR (& storage_getmount_obj ) },
161+ { MP_ROM_QSTR (MP_QSTR_erase_filesystem ), MP_ROM_PTR (& storage_erase_filesystem_obj ) },
141162
142163 //| .. class:: VfsFat(block_device)
143164 //|
0 commit comments