The Microchip MDD File System is a library that allows you to access files and directories on FAT12, FAT16 and FAT32 formatted storage devices, such as SD cards, USB flash drives and CompactFlash cards. The library supports 8-bit, 16-bit and 32-bit PIC microcontrollers and can be integrated with various physical layers. The library also provides functions for creating, writing, reading, renaming, deleting and searching files and directories.
In this article, we will show you how to install the Microchip MDD File System 1.2.1 on your computer and use it with your PIC microcontroller project.
Step 1: Download the library
The latest version of the Microchip MDD File System library is available at https://www.microchip.com/mdd. You can download the zip file that contains the source code, documentation and examples for the library. Extract the zip file to a folder of your choice.
Step 2: Configure the library
The library comes with a configuration file called FSconfig.h that allows you to customize the library according to your needs. You can open this file with a text editor and modify the following parameters:
_FILE_SYSTEM: This defines the type of file system that you want to use. You can choose between FAT12 (_FAT12), FAT16 (_FAT16) or FAT32 (_FAT32). If you are not sure which one to use, you can select _MULTI_PARTITION which will automatically detect the file system type of your storage device.
_USE_LFN: This defines whether you want to use long file names (LFN) or not. LFN are file names that can have up to 255 characters, while standard file names (SFN) can only have up to 8 characters plus a 3-character extension. LFN are only supported by 16-bit and 32-bit PIC microcontrollers due to RAM limitations. If you want to use LFN, set this parameter to _USE_LFN_YES, otherwise set it to _USE_LFN_NO.
_MAX_LFN_LENGTH: This defines the maximum length of LFN that you want to use. The default value is 255, but you can reduce it if you want to save RAM space.
_FS_DYNAMIC_MEM: This defines whether you want to use dynamic memory allocation or not. Dynamic memory allocation allows you to allocate memory for file and directory structures at run time, while static memory allocation reserves a fixed amount of memory at compile time. Dynamic memory allocation requires more code space and may cause fragmentation issues, while static memory allocation requires more RAM space and may limit the number of files and directories that you can access. If you want to use dynamic memory allocation, set this parameter to _FS_DYNAMIC_MEM_YES, otherwise set it to _FS_DYNAMIC_MEM_NO.
_FS_MAX_FILES_OPEN: This defines the maximum number of files that can be open at the same time. This parameter is only relevant if you use static memory allocation (_FS_DYNAMIC_MEM_NO). The default value is 3, but you can increase it if you need more files open simultaneously.
_FS_MAX_FILES_OPEN_WITH_LFN: This defines the maximum number of files that can be open at the same time with LFN enabled. This parameter is only relevant if you use static memory allocation (_FS_DYNAMIC_MEM_NO) and LFN (_USE_LFN_YES). The default value is 1, but you can increase it if you need more files open simultaneously with LFN.
_MEDIA_: This defines the type of physical layer that you want to use with the library. You can choose between SD-SPI (_MEDIA_SD), USB (_MEDIA_USB), CF-PMP (_MEDIA_CF) or RAM (_MEDIA_RAM). You can also define your own custom physical layer by setting this parameter to _MEDIA_USER_DEFINED and implementing the required functions in a separate file called FSIO.c.
After configuring these parameters, save the FSconfig.h file.