Skip to content

Commit ec1d29f

Browse files
dhalberttannewt
authored andcommitted
check twice for bad filesystem
1 parent 23dd197 commit ec1d29f

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

atmel-samd/main.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,20 @@ void init_flash_fs(bool create_allowed) {
127127
// is bobbling a bit when plugging in a battery.
128128
mp_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) {
141145
return;
142146
}

0 commit comments

Comments
 (0)