8000 storage.erase_filesystem(): unmount and wait 1 second before resetting · cwalther/circuitpython@65c22aa · GitHub
[go: up one dir, main page]

Skip to content

Commit 65c22aa

Browse files
committed
storage.erase_filesystem(): unmount and wait 1 second before resetting
1 parent 8abf8c2 commit 65c22aa

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

shared-module/storage/__init__.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "extmod/vfs.h"
3232
#include "py/mperrno.h"
33+
#include "py/mphal.h"
3334
#include "py/obj.h"
3435
#include "py/runtime.h"
3536
#include "shared-bindings/microcontroller/__init__.h"
@@ -159,6 +160,8 @@ void common_hal_storage_remount(const char *mount_path, bool readonly, bool disa
159160
}
160161

161162
void common_hal_storage_erase_filesystem(void) {
163+
usb_disconnect();
164+
mp_hal_delay_ms(1000);
162165
filesystem_init(false, true); // Force a re-format.
163166
common_hal_mcu_reset();
164167
// We won't actually get here, since we're resetting.

supervisor/shared/usb/usb.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ void usb_init(void) {
7373
#endif
7474
}
7575

76+
void usb_disconnect(void) {
77+
tud_disconnect();
78+
}
79+
7680
void usb_background(void) {
7781
if (usb_enabled()) {
7882
#if CFG_TUSB_OS == OPT_OS_NONE

supervisor/usb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void init_usb_hardware(void);
4040
// Shared implementation.
4141
bool usb_enabled(void);
4242
void usb_init(void);
43+
void usb_disconnect(void);
4344

4445
// Propagate plug/unplug events to the MSC logic.
4546
void usb_msc_mount(void);

0 commit comments

Comments
 (0)
0