Any solution to using exFAT with Giga?

I was wondering if anyone has come up with a solution to allow the Giga to use exFAT formatted USB drives instead of only FAT32 and similar?

Looking at the mbed_config.h file, it says:

#define MBED_CONF_FAT_CHAN_FF_FS_EXFAT                                          0                                                                                                // set by library:fat_chan

Which suggests that it might be possible to use exFAT, but that it's turned off. This is also an automatically generated configuration file and any edits will be overwritten, so I can't just change the 0 to a 1 and have it work.

Looking in FATFileSystem.h, it also says:

     *  @param allocation_unit
     *      This is the number of bytes per cluster size. The valid value is N
     *      times the sector size. N is a power of 2, from 1 to 128, for the FAT
     *      volume, and up to 16MiB for the exFAT volume. If zero is given,
     *      the default allocation unit size is selected by the underlying
     *      file system, which depends on the volume size.

Which further suggests that exFAT can be used.

In ffconf.h, it also says:

/  To enable the LFN, ffunicode.c needs to be added to the project. The LFN function
/  requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and
/  additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.
/  The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can
/  be in range of 12 to 255. It is recommended to be set it 255 to fully support LFN
/  specification.
#define FF_LBA64		0
/* This option switches support for 64-bit LBA. (0:Disable or 1:Enable)
/  To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */
#define FF_FS_EXFAT		MBED_CONF_FAT_CHAN_FF_FS_EXFAT
/* 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. */

And in ff.h, it has multiple references to exFAT.

So I am thinking that it might be possible to modify the Giga's code to run exFAT. Has anyone tried this and found a solution? Or is it not allowed/accessible for some reason? Because it's really annoying that I can't use exFAT when it's getting harder and harder to find USB drives that aren't formatted in exFAT because of files size. And while yes, you can use third-party software to format larger USB drives to used FAT32 instead of exFAT, it would be nice just to be able to plug any USB in and have it work.

One option that was suggested was to regenerate libmbed.a using Linux commands after adding "fat_chan.ff_fs_exfat": 1, as a line in mbed_app.json, but I haven't tried this yet.

(All of these files are found in C:\Users\(your profile)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.6.0\variants\GIGA.)

This is the only way. I don't use exFAT but I have changed "ff_fs_lock": from 1 to 2 so that I can read a file while writing another. It requires a re-comp of the libmbed.a

I can confirm that you can recompile libmbed.a and get exFAT working for the USB A port. It's a Linux procedure though, so it is a bit more complicated that turning a 0 to a 1, and I used Ubuntu. I'm unable to attach the recompiled libmbed.a file because it is not a supported file type (ETA: I have attached the file as a ZIP file, and it goes in C:\Users\(your profile)\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.6.0\variants\GIGA\libs), so I am providing an explanation of the procedure. I had ChatGPT walk me through the process and explain the Linux commands that it was providing for me to use.

Because I don't entirely understand the process, I asked ChatGPT how to best explain what we did, and this is what it provided (it's written in the first person for me to post because I carried out the actions, but I didn't write this):

Enabling exFAT support on the Arduino GIGA R1 WiFi (Mbed core)

Back up your Arduino core before doing this. This procedure rebuilds files inside the installed Arduino Mbed core, including libmbed.a. A Boards Manager update/reinstall may overwrite the changes.

The current Arduino GIGA Mbed core contains FatFs exFAT support, but it is disabled at compile time. In variants/GIGA/mbed_config.h, the stock core has:

#define MBED_CONF_FAT_CHAN_FF_FS_EXFAT 0

Simply changing that generated header to 1 is not sufficient, because libmbed.a was already compiled with exFAT disabled. The Mbed core therefore needs to be rebuilt with fat_chan.ff_fs_exfat enabled.

I successfully rebuilt the Arduino Mbed core and tested it on the GIGA R1 WiFi with an exFAT USB flash drive using Arduino_USBHostMbed5.

1. Get Arduino's Mbed source

Arduino's GIGA core is based on its patched Mbed OS 6.17 tree. I cloned Arduino's extrapatches-6.17.0 branch:

mkdir -p ~/arduino-mbed
cd ~/arduino-mbed

git clone --branch extrapatches-6.17.0 --single-branch \
    https://github.com/arduino/mbed-os.git mbed-os

2. Enable exFAT

In the Mbed configuration used for the build, enable:

"fat_chan.ff_fs_exfat": 1

Long filename support also needs to be enabled for exFAT. In my resulting GIGA configuration this was:

#define MBED_CONF_FAT_CHAN_FF_FS_EXFAT 1
#define MBED_CONF_FAT_CHAN_FF_USE_LFN 3

3. Fix an exFAT compile error in Arduino's Mbed 6.17 FatFs

Enabling exFAT exposed a type mismatch in:

storage/filesystem/fat/ChaN/ff.cpp

The relevant INIT_NAMBUF macro allocated the buffer as a WCHAR *, but the result of ff_memalloc() required an explicit cast with the C++ compiler.

The working version was:

#define INIT_NAMBUF(fs) { \
    lfn = (WCHAR *)ff_memalloc((FF_MAX_LFN+1)*2 + MAXDIRB(FF_MAX_LFN)); \
    if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); \
    (fs)->lfnbuf = lfn; \
    (fs)->dirbuf = (BYTE*)(lfn+FF_MAX_LFN+1); \
}

4. Rebuild the GIGA Mbed core

I used Arduino's mbed-os-to-arduino script with the locally modified Mbed source:

./mbed-os-to-arduino \
    -r /home/<username>/arduino-mbed/mbed-os \
    GIGA:GIGA

The build should finish with:

[mbed-os-to-arduino] MbedOS core generation ended successfully.

The resulting configuration can be checked with:

grep -n "MBED_CONF_FAT_CHAN_FF_FS_EXFAT" variants/GIGA/mbed_config.h
grep -n "MBED_CONF_FAT_CHAN_FF_USE_LFN" variants/GIGA/mbed_config.h

which should show:

#define MBED_CONF_FAT_CHAN_FF_FS_EXFAT 1
#define MBED_CONF_FAT_CHAN_FF_USE_LFN 3

I also verified that the rebuilt libmbed.a actually contained the relevant FatFs objects:

arm-none-eabi-ar t variants/GIGA/libs/libmbed.a | grep -Ei 'ffunicode|ff\.o|fat'

which produced:

ff.o
ffunicode.o
FATFileSystem.o

5. Test

Using Arduino_USBHostMbed5 and mbed::FATFileSystem, I was then able to mount an exFAT-formatted USB flash drive on the GIGA, create a text file, write data to it, close it, reopen it, and read the contents successfully.

So exFAT does work on the GIGA's existing Mbed/FatFs stack; it just isn't enabled in the precompiled Arduino core.

I also encountered a few other issues that ChatGPT didn't mention in the above that had to do with getting the older Arduino build tooling to work with the new environment, but they weren't a conceptual part of enabling exFAT. For example:

  • I started with Python 3.12, but it turns out that I needed to be using Python 3.11 to recompile libmbed.a.
  • There were a lot of different tools that I had to install through Ubuntu to get things working, but it was a simple process.
  • There were also several cases of unquoted $ARDUINOVARIANT uses in mbed-os-to-arduino that caused issues and had to be fixed (the errors from this also had weird issues with the spaces in the directory address, expanding every space as a new error, but this was resolved once the quotes were in place in the file).
  • There were other things, such as mentions in ffconf.h that ffunicode.c was needed, but the Mbed repository has ffunicode.cpp, and when I downloaded the Mbed repository in Ubuntu, it was able to use that file without issue.
  • I built the recompile in a virtual environment, though I added the line "fat_chan.ff_fs_exfat": 1 to mbed_app.json manually as the second last item in the list (i.e., right before "target.macros_add": []).
  • Once I added the new libmbed.a file, I had to delete the sketch in my Arduino folder to force it to compile my code with the new libmbed.a file.

I hope that this helps anyone wanting to use exFAT with the Giga. Happy coding!

libmbed.zip (2.1 MB)

ZIP files are, so if you like you can put the file in a ZIP archive and attach that.

Thanks for the suggestion!