@@ -127,16 +127,20 @@ void init_flash_fs(bool create_allowed) {
127127// is bobbling a bit when plugging in a battery.
128128mp_hal_delay_ms (2000 );
129129
130- uint8_t working_buf [_MAX_SS ];
131- res = f_mkfs (& vfs_fat -> fatfs ,FM_FAT ,0 ,working_buf ,sizeof (working_buf ));
132- // Flush the new file system to make sure its repaired immediately.
133- flash_flush ();
134- if (res != FR_OK ) {
135- return ;
136- }
130+ // Then try one more time to mount the flash in case it was late coming up.
131+ res = f_mount (& vfs_fat -> fatfs );
132+ if (res == FR_NO_FILESYSTEM ) {
133+ uint8_t working_buf [_MAX_SS ];
134+ res = f_mkfs (& vfs_fat -> fatfs ,FM_FAT ,0 ,working_buf ,sizeof (working_buf ));
135+ // Flush the new file system to make sure its repaired immediately.
136+ flash_flush ();
137+ if (res != FR_OK ) {
138+ return ;
139+ }
137140
138- // set label
139- f_setlabel (& vfs_fat -> fatfs ,"CIRCUITPY" );
141+ // set label
142+ f_setlabel (& vfs_fat -> fatfs ,"CIRCUITPY" );
143+ }
140144 }else if (res != FR_OK ) {
141145return ;
142146 }