Skip to content

Commit b76d37f

Browse files
authored
Merge pull request adafruit#3223 from dhalbert/unmount-before-reset
storage.erase_filesystem(): disconnect from USB and wait 1 second before resetting
2 parents 05a1519 + 65c22aa commit b76d37f

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
@@ -74,6 +74,10 @@ void usb_init(void) {
7474
#endif
7575
}
7676

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

supervisor/usb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ void init_usb_hardware(void);
4545
// Shared implementation.
4646
bool usb_enabled(void);
4747
void usb_init(void);
48+
void usb_disconnect(void);
4849

4950
// Propagate plug/unplug events to the MSC logic.
5051
void usb_msc_mount(void);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy