Skip to content

storage.erase_filesystem(): disconnect from USB and wait 1 second before resetting #3223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions shared-module/storage/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions supervisor/shared/usb/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions supervisor/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down