@@ -60,6 +60,7 @@ FatVolume wipperFatFs_v2; ///< File system object from Adafruit SDFat library
6060Adafruit_USBD_MSC usb_msc_v2; /* !< USB mass storage object */
6161Adafruit_USBD_CDC usb_cdc; /* !< USB CDC object */
6262static bool _fs_changed = false ;
63+ static bool _did_init_msc = false ;
6364
6465/* *************************************************************************/
6566/* !
@@ -105,6 +106,7 @@ FRESULT format_fs_fat12(void) {
105106/* *************************************************************************/
106107Wippersnapper_FS::Wippersnapper_FS () {
107108 _fs_changed = false ;
109+ _did_init_msc = false ;
108110
109111 usb_cdc.begin (115200 );
110112 // Re-enumerate to allow cdc class begin() to take effect
@@ -121,7 +123,7 @@ Wippersnapper_FS::Wippersnapper_FS() {
121123 }
122124
123125 // If we are not formatted, attempt to format the filesystem as fat12
124- if (! wipperFatFs_v2.begin (&flash_v2)) {
126+ if (!wipperFatFs_v2.begin (&flash_v2)) {
125127 FRESULT rc = format_fs_fat12 ();
126128 if (rc != FR_OK) {
127129 setStatusLEDColor (RED);
@@ -141,10 +143,10 @@ Wippersnapper_FS::Wippersnapper_FS() {
141143 HaltFilesystem (" FATAL ERROR: Could not write filesystem contents!" );
142144 }
143145
144- // Initialize USB-MSC
145- #ifndef BUILD_OFFLINE_ONLY
146+ // Initialize USB-MSC
147+ #ifndef BUILD_OFFLINE_ONLY
146148 InitUsbMsc ();
147- #endif
149+ #endif
148150
149151 // If we wrote a fresh secrets.json file, halt until user edits the file and
150152 // RESETs the device Signal to user that action must be taken (edit
@@ -300,6 +302,7 @@ void Wippersnapper_FS::InitUsbMsc() {
300302 delay (10 );
301303 TinyUSBDevice.attach ();
302304 }
305+ _did_init_msc = true ;
303306}
304307
305308/* *************************************************************************/
@@ -679,6 +682,9 @@ void Wippersnapper_FS::WriteFileBoot(PGM_P str) {
679682*/
680683/* *************************************************************************/
681684void Wippersnapper_FS::HaltFilesystem (String msg) {
685+ if (!_did_init_msc) {
686+ InitUsbMsc ();
687+ }
682688 TinyUSBDevice.attach ();
683689 delay (500 );
684690 statusLEDSolid (WS_LED_STATUS_FS_WRITE);
@@ -699,6 +705,9 @@ void Wippersnapper_FS::HaltFilesystem(String msg) {
699705/* *************************************************************************/
700706void Wippersnapper_FS::HaltFilesystem (String msg,
701707 ws_led_status_t ledStatusColor) {
708+ if (!_did_init_msc) {
709+ InitUsbMsc ();
710+ }
702711 TinyUSBDevice.attach ();
703712 delay (500 );
704713 statusLEDSolid (ledStatusColor);
0 commit comments