Skip to content

Commit 5d61fca

Browse files
Merge pull request #171 from erwinschrodinger1/master
feat(fat_format): add fat file format on kconfig to change MKFS_PARM format options (IEC-294)
2 parents 515f693 + 9e2336a commit 5d61fca

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

device/esp_tinyusb/Kconfig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,36 @@ menu "TinyUSB Stack"
185185
default "/data"
186186
help
187187
MSC Mount Path of storage.
188+
189+
menu "TinyUSB FAT Format Options"
190+
choice TINYUSB_FAT_FORMAT_TYPE
191+
prompt "FatFS Format Type"
192+
default TINYUSB_FAT_FORMAT_ANY
193+
help
194+
Select the FAT filesystem type used when formatting storage.
195+
196+
config TINYUSB_FAT_FORMAT_ANY
197+
bool "FM_ANY - Automatically select from FAT12/FAT16/FAT32"
198+
199+
config TINYUSB_FAT_FORMAT_FAT
200+
bool "FM_FAT - Allow only FAT12/FAT16"
201+
202+
config TINYUSB_FAT_FORMAT_FAT32
203+
bool "FM_FAT32 - Force FAT32 only"
204+
205+
config TINYUSB_FAT_FORMAT_EXFAT
206+
bool "FM_EXFAT - Force exFAT (requires exFAT enabled)"
207+
208+
endchoice
209+
210+
config TINYUSB_FAT_FORMAT_SFD
211+
bool "FM_SFD - Use SFD (no partition table)"
212+
default n
213+
help
214+
Format as a Super Floppy Disk (no partition table).
215+
This is typical for USB flash drives and small volumes.
216+
endmenu
217+
188218
endmenu # "Massive Storage Class"
189219

190220
menu "Communication Device Class (CDC)"

device/esp_tinyusb/tusb_msc_storage.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,29 @@ static esp_err_t _mount(char *drv, FATFS *fs)
253253
CONFIG_WL_SECTOR_SIZE,
254254
4096);
255255
ESP_LOGW(TAG, "formatting card, allocation unit size=%d", alloc_unit_size);
256-
const MKFS_PARM opt = {(BYTE)FM_FAT, 0, 0, 0, alloc_unit_size};
256+
257+
BYTE format_flags;
258+
#if defined(CONFIG_TINYUSB_FAT_FORMAT_ANY)
259+
format_flags = FM_ANY;
260+
261+
#elif defined(CONFIG_TINYUSB_FAT_FORMAT_FAT)
262+
format_flags = FM_FAT;
263+
264+
#elif defined(CONFIG_TINYUSB_FAT_FORMAT_FAT32)
265+
format_flags = FM_FAT32;
266+
267+
#elif defined(CONFIG_TINYUSB_FAT_FORMAT_EXFAT)
268+
format_flags = FM_EXFAT;
269+
#else
270+
271+
#error "No FAT format type selected"
272+
273+
#endif
274+
275+
#ifdef CONFIG_TINYUSB_FAT_FORMAT_SFD
276+
format_flags |= FM_SFD;
277+
#endif
278+
const MKFS_PARM opt = {format_flags, 0, 0, 0, alloc_unit_size};
257279
fresult = f_mkfs("", &opt, workbuf, workbuf_size); // Use default volume
258280
if (fresult != FR_OK) {
259281
ret = ESP_FAIL;

0 commit comments

Comments
 (0)