summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2017-11-29 22:23:13 -0500
committerScott Shawcroft <scott@tannewt.org>2017-12-20 09:02:30 -0800
commitec1d29f4aeab2f611f288a11e94adbf39655340f (patch)
treee0a1beda0a3f7fff3de4e1bb1c2e9e6e6385286b
parent23dd19757aadbb64112b882cd4ee2082d04791ee (diff)
check twice for bad filesystem
-rw-r--r--atmel-samd/main.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/atmel-samd/main.c b/atmel-samd/main.c
index 0013f3e20..2cbe6f88d 100644
--- a/atmel-samd/main.c
+++ b/atmel-samd/main.c
@@ -127,16 +127,20 @@ void init_flash_fs(bool create_allowed) {
// is bobbling a bit when plugging in a battery.
mp_hal_delay_ms(2000);
- uint8_t working_buf[_MAX_SS];
- res = f_mkfs(&vfs_fat->fatfs, FM_FAT, 0, working_buf, sizeof(working_buf));
- // Flush the new file system to make sure its repaired immediately.
- flash_flush();
- if (res != FR_OK) {
- return;
- }
+ // Then try one more time to mount the flash in case it was late coming up.
+ res = f_mount(&vfs_fat->fatfs);
+ if (res == FR_NO_FILESYSTEM) {
+ uint8_t working_buf[_MAX_SS];
+ res = f_mkfs(&vfs_fat->fatfs, FM_FAT, 0, working_buf, sizeof(working_buf));
+ // Flush the new file system to make sure its repaired immediately.
+ flash_flush();
+ if (res != FR_OK) {
+ return;
+ }
- // set label
- f_setlabel(&vfs_fat->fatfs, "CIRCUITPY");
+ // set label
+ f_setlabel(&vfs_fat->fatfs, "CIRCUITPY");
+ }
} else if (res != FR_OK) {
return;
}