From 2a4901c1fc5c53a83ac9963b0187f5a66b25571d Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 7 Nov 2017 21:05:49 -0500 Subject: [PATCH 1/2] Wait 2 secs before creating new filesystem in case power is jittery --- atmel-samd/main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/atmel-samd/main.c b/atmel-samd/main.c index 7bc4a87ed6c13..70fff403dfadf 100644 --- a/atmel-samd/main.c +++ b/atmel-samd/main.c @@ -120,6 +120,11 @@ void init_flash_fs(bool create_allowed) { if (res == FR_NO_FILESYSTEM && create_allowed) { // no filesystem so create a fresh one + // Wait two seconds before creating. Jittery power might + // fail before we're ready. This can happen if someone + // 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. From 0f063ec3b55878518d60ff2b61c378e960bc2ca1 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 29 Nov 2017 22:23:13 -0500 Subject: [PATCH 2/2] check twice for bad filesystem --- .gitignore | 9 +++++++++ atmel-samd/main.c | 22 +++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 6f19fe788eed7..61219390e7602 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,12 @@ _build # Generated rst files ###################### genrst/ + +# ctags and similar +################### +TAGS + +# Merge leftovers +################# +*.orig + diff --git a/atmel-samd/main.c b/atmel-samd/main.c index 70fff403dfadf..1abf4a42bca03 100644 --- a/atmel-samd/main.c +++ b/atmel-samd/main.c @@ -125,16 +125,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; }