From 65c22aa4347abc145493f44a4bc8d91a4f200860 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 28 Jul 2020 17:52:56 -0400 Subject: [PATCH] storage.erase_filesystem(): unmount and wait 1 second before resetting --- shared-module/storage/__init__.c | 3 +++ supervisor/shared/usb/usb.c | 4 ++++ supervisor/usb.h | 1 + 3 files changed, 8 insertions(+) diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index c3d4b50c8e..1ffd7d4cb8 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -30,6 +30,7 @@ #include "extmod/vfs.h" #include "py/mperrno.h" +#include "py/mphal.h" #include "py/obj.h" #include "py/runtime.h" #include "shared-bindings/microcontroller/__init__.h" @@ -159,6 +160,8 @@ void common_hal_storage_remount(const char *mount_path, bool readonly, bool disa } void common_hal_storage_erase_filesystem(void) { + usb_disconnect(); + mp_hal_delay_ms(1000); filesystem_init(false, true); // Force a re-format. common_hal_mcu_reset(); // We won't actually get here, since we're resetting. diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index edf8101188..3282bd22b9 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -73,6 +73,10 @@ void usb_init(void) { #endif } +void usb_disconnect(void) { + tud_disconnect(); +} + void usb_background(void) { if (usb_enabled()) { #if CFG_TUSB_OS == OPT_OS_NONE diff --git a/supervisor/usb.h b/supervisor/usb.h index 29280c725b..fb8d5b45f0 100644 --- a/supervisor/usb.h +++ b/supervisor/usb.h @@ -40,6 +40,7 @@ void init_usb_hardware(void); // Shared implementation. bool usb_enabled(void); void usb_init(void); +void usb_disconnect(void); // Propagate plug/unplug events to the MSC logic. void usb_msc_mount(void);