From def103e62fd35f87f917588edbf905acd77981f3 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Thu, 23 Jan 2025 14:53:37 +0100 Subject: [PATCH 1/2] feat: enhance fat type support add EXFAT type support available since FatFS R0.12c. Signed-off-by: Frederic Pillon --- examples/CardInfo/CardInfo.ino | 19 +++++++++++++++---- keywords.txt | 5 +++++ src/SdFatFs.cpp | 18 ++++++++++++++---- src/SdFatFs.h | 9 +++++++++ src/ffconf_default_68300.h | 2 +- src/ffconf_default_80286.h | 2 +- 6 files changed, 45 insertions(+), 10 deletions(-) diff --git a/examples/CardInfo/CardInfo.ino b/examples/CardInfo/CardInfo.ino index cdc8e4d..768cf9a 100644 --- a/examples/CardInfo/CardInfo.ino +++ b/examples/CardInfo/CardInfo.ino @@ -56,15 +56,26 @@ void setup() { // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 if (!fatFs.init()) { - Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); + Serial.println("Could not find FAT partition.\nMake sure you've formatted the card"); return; } // print the type and size of the first FAT-type volume uint64_t volumesize; - Serial.print("\nVolume type is FAT"); - Serial.println(fatFs.fatType(), DEC); - Serial.println(); + Serial.print("\nVolume type is "); + uint8_t fatType = fatFs.fatType(); +#if defined(FAT_TYPE_EXFAT) + if (fatType == FAT_TYPE_EXFAT) { + Serial.println("exFAT"); + } else +#endif + { + if (fatType != FAT_TYPE_UNK) { + Serial.printf("FAT%u\n", fatFs.fatType()); + } else { + Serial.println("unknown"); + } + } volumesize = fatFs.blocksPerCluster(); // clusters are collections of blocks volumesize *= fatFs.clusterCount(); // we'll have a lot of clusters diff --git a/keywords.txt b/keywords.txt index dc9f811..d229e76 100644 --- a/keywords.txt +++ b/keywords.txt @@ -37,3 +37,8 @@ setDxDIR KEYWORD2 ####################################### FILE_READ LITERAL1 FILE_WRITE LITERAL1 +FAT_TYPE_EXFAT LITERAL1 +FAT_TYPE_FAT12 LITERAL1 +FAT_TYPE_FAT16 LITERAL1 +FAT_TYPE_FAT32 LITERAL1 +FAT_TYPE_UNK LITERAL1 diff --git a/src/SdFatFs.cpp b/src/SdFatFs.cpp index c59c6cc..a3bbf09 100644 --- a/src/SdFatFs.cpp +++ b/src/SdFatFs.cpp @@ -66,14 +66,24 @@ bool SdFatFs::deinit(void) uint8_t SdFatFs::fatType(void) { + uint8_t fatType = FAT_TYPE_UNK; switch (_SDFatFs.fs_type) { +#if defined(FS_EXFAT) + case FS_EXFAT: + fatType = FAT_TYPE_EXFAT; + break; +#endif case FS_FAT12: - return 12; + fatType = FAT_TYPE_FAT12; + break; case FS_FAT16: - return 16; + fatType = FAT_TYPE_FAT16; + break; case FS_FAT32: - return 32; + fatType = FAT_TYPE_FAT32; + break; default: - return 0; + fatType = FAT_TYPE_UNK; } + return fatType; } diff --git a/src/SdFatFs.h b/src/SdFatFs.h index 6f7be73..a023774 100644 --- a/src/SdFatFs.h +++ b/src/SdFatFs.h @@ -42,6 +42,15 @@ /* FatFs includes component */ #include "FatFs.h" +/* Filesystem type (FATFS.fs_type) */ +#define FAT_TYPE_FAT12 12 // FS_FAT12 +#define FAT_TYPE_FAT16 16 // FS_FAT16 +#define FAT_TYPE_FAT32 32 // FS_FAT32 +#if defined(FS_EXFAT) + #define FAT_TYPE_EXFAT 64 // FS_EXFAT +#endif +#define FAT_TYPE_UNK 0 // Unknown + /* To match Arduino definition*/ #define FILE_WRITE FA_WRITE #define FILE_READ FA_READ diff --git a/src/ffconf_default_68300.h b/src/ffconf_default_68300.h index 058baa1..72f5479 100644 --- a/src/ffconf_default_68300.h +++ b/src/ffconf_default_68300.h @@ -230,7 +230,7 @@ / buffer in the file system object (FATFS) is used for the file data transfer. */ -#define _FS_EXFAT 0 +#define _FS_EXFAT 1 /* This option switches support of exFAT file system. (0:Disable or 1:Enable) / When enable exFAT, also LFN needs to be enabled. (_USE_LFN >= 1) / Note that enabling exFAT discards C89 compatibility. */ diff --git a/src/ffconf_default_80286.h b/src/ffconf_default_80286.h index 1c54994..c84c006 100644 --- a/src/ffconf_default_80286.h +++ b/src/ffconf_default_80286.h @@ -231,7 +231,7 @@ / buffer in the filesystem object (FATFS) is used for the file data transfer. */ -#define FF_FS_EXFAT 0 +#define FF_FS_EXFAT 1 /* This option switches support for exFAT filesystem. (0:Disable or 1:Enable) / To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1) / Note that enabling exFAT discards ANSI C (C89) compatibility. */ From 4e9eb2e2644e145f533b04bd864d82f50f986c96 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Tue, 4 Feb 2025 16:27:56 +0100 Subject: [PATCH 2/2] feat: add SDClass fatType method Signed-off-by: Frederic Pillon --- keywords.txt | 1 + src/STM32SD.h | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/keywords.txt b/keywords.txt index d229e76..f9fd880 100644 --- a/keywords.txt +++ b/keywords.txt @@ -31,6 +31,7 @@ setCMD KEYWORD2 setCKIN KEYWORD2 setCDIR KEYWORD2 setDxDIR KEYWORD2 +fatType KEYWORD2 ####################################### # Constants (LITERAL1) diff --git a/src/STM32SD.h b/src/STM32SD.h index ed52396..4c76f74 100644 --- a/src/STM32SD.h +++ b/src/STM32SD.h @@ -153,6 +153,11 @@ class SDClass { friend class File; + uint8_t fatType() + { + return _fatFs.fatType(); + } + private: Sd2Card _card; SdFatFs _fatFs;