@@ -263,7 +263,7 @@ MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) {
263263}
264264
265265#if MICROPY_HW_HAS_SDCARD
266- STATIC bool init_sdcard_fs (bool first_soft_reset ) {
266+ STATIC bool init_sdcard_fs (void ) {
267267 bool first_part = true;
268268 for (int part_num = 1 ; part_num <= 4 ; ++ part_num ) {
269269 // create vfs object
@@ -308,12 +308,12 @@ STATIC bool init_sdcard_fs(bool first_soft_reset) {
308308 }
309309 }
310310
311- if ( first_soft_reset ) {
312- // use SD card as medium for the USB MSD
313- # if defined( USE_DEVICE_MODE )
311+ # if defined( USE_DEVICE_MODE )
312+ if ( pyb_usb_storage_medium == PYB_USB_STORAGE_MEDIUM_NONE ) {
313+ // if no USB MSC medium is selected then use the SD card
314314 pyb_usb_storage_medium = PYB_USB_STORAGE_MEDIUM_SDCARD ;
315- #endif
316315 }
316+ #endif
317317
318318 #if defined(USE_DEVICE_MODE )
319319 // only use SD card as current directory if that's what the USB medium is
@@ -470,13 +470,6 @@ int main(void) {
470470 #endif
471471 storage_init ();
472472
473- #if defined(USE_DEVICE_MODE )
474- // default to internal flash being the usb medium
475- pyb_usb_storage_medium = PYB_USB_STORAGE_MEDIUM_FLASH ;
476- #endif
477-
478- int first_soft_reset = true;
479-
480473soft_reset :
481474
482475 // check if user switch held to select the reset mode
@@ -558,11 +551,18 @@ int main(void) {
558551 if (sdcard_is_present ()) {
559552 // if there is a file in the flash called "SKIPSD", then we don't mount the SD card
560553 if (!mounted_flash || f_stat (& fs_user_mount_flash .fatfs , "/SKIPSD" , NULL ) != FR_OK ) {
561- mounted_sdcard = init_sdcard_fs (first_soft_reset );
554+ mounted_sdcard = init_sdcard_fs ();
562555 }
563556 }
564557#endif
565558
559+ #if defined(USE_DEVICE_MODE )
560+ // if the SD card isn't used as the USB MSC medium then use the internal flash
561+ if (pyb_usb_storage_medium == PYB_USB_STORAGE_MEDIUM_NONE ) {
562+ pyb_usb_storage_medium = PYB_USB_STORAGE_MEDIUM_FLASH ;
563+ }
564+ #endif
565+
566566 // set sys.path based on mounted filesystems (/sd is first so it can override /flash)
567567 if (mounted_sdcard ) {
568568 mp_obj_list_append (mp_sys_path , MP_OBJ_NEW_QSTR (MP_QSTR__slash_sd ));
@@ -688,6 +688,5 @@ int main(void) {
688688 pyb_thread_deinit ();
689689 #endif
690690
691- first_soft_reset = false;
692691 goto soft_reset ;
693692}
0 commit comments