From 74d07469f276aff862a99423ded03f08ec5006b3 Mon Sep 17 00:00:00 2001
From: Andrew Leech <andrew.leech@planetinnovation.com.au>
Date: Mon, 25 Mar 2019 11:20:54 +1100
Subject: [PATCH] extmod/vfs_fat: Fallback to FAT32 if standard FAT16/SFD
 format fails.

This allows formatting SD cards, larger flash etc which do not support the
default FAT16/SFD format mode.
---
 extmod/vfs_fat.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c
index 024cecfe9..ec7aaed38 100644
--- a/extmod/vfs_fat.c
+++ b/extmod/vfs_fat.c
@@ -113,6 +113,9 @@ STATIC mp_obj_t fat_vfs_mkfs(mp_obj_t bdev_in) {
     // make the filesystem
     uint8_t working_buf[FF_MAX_SS];
     FRESULT res = f_mkfs(&vfs->fatfs, FM_FAT | FM_SFD, 0, working_buf, sizeof(working_buf));
+    if (res == FR_MKFS_ABORTED) { // Probably doesn't support FAT16
+        res = f_mkfs(&vfs->fatfs, FM_FAT32, 0, working_buf, sizeof(working_buf));
+    }
     if (res != FR_OK) {
         mp_raise_OSError(fresult_to_errno_table[res]);
     }
-- 
GitLab