Configuring µC/FS Application Specifics

In a previous blog, we discussed the layout of a FAT Filesystem’s boot sector which contains the FAT tables and root directory. To re-cap, the boot sector contains the FAT Type, FAT size and Root Directory size. The larger portion of the File System is the data area. We will go over this section of the File System and how it can be configured for your specific application.

For more information on the re-cap section you can read more here: https://www.micrium.com/basics-of-ucfs-fat-utilization/.

#define APP_CFG_FS_DEV_CNT          3 /* Max. num. of opened devices. */ 
#define APP_CFG_FS_VOL_CNT          3 /* Max. num. of opened volumes. */
#define APP_CFG_FS_FILE_CNT         5 /* Max. num. of opened files. */ 
#define APP_CFG_FS_DIR_CNT          5 /* Max. num. of opened directories. */
#define APP_CFG_FS_BUF_CNT (4 * APP_CFG_FS_VOL_CNT) /* Internal buffer count. */
#define APP_CFG_FS_DEV_DRV_CNT      3 /* Max. num. of different device drivers. */
#define APP_CFG_FS_WORKING_DIR_CNT  5 /* Max. num. of active working directories. */ 
#define APP_CFG_FS_MAX_SEC_SIZE   512 /* Max. sector size supported. */

The File System includes an application specific set of configurations for the overall layout of the File System and then specifics for the driver you are using (RAMDisk, NOR, NAND, SD Card). For the purposes of this blog we will cover the first section that goes over the File Systems overall configurations shown above.

Remembering, a sector is the smallest unit of measure for memory allocated within the file system. A FAT32 volume’s FIRST section always contains the Volume ID followed by a region of RESERVED sectors. This RESERVED section is made up of the boot sector, file system information sector and a few other reserved sectors.

Following these reserved sectors are the File Allocation Tables (FAT) which typically includes two copies of this. This FAT section is similar to a Table of Contents for navigating the data region for specific files or directories.

After that comes the Data Region made up of clusters and some unused area. This section of data contains the actual files and directories that are listed in the FAT regions.

FAT32 Volume Layout Example

FAT32 Volume Layout Example

As you create files and directories clusters are assigned to these depending on the amount of space they require. Remembering that a sector is the smallest unit that can be assigned for memory usage. If your file requires 1.6kB to contain all, depending on your clusters size depends on how many it would require to contain that file.

How this matter with the configuration values in uC/FS:

APP_CFG_FS_DEV_CNT defines how many open devices you plan to have at one time. This is important to consider as it adds resource requirement to your application.

APP_CFG_FS_VOL_CNT defines how many volumes to divide the memory region up into. This allows you to utilize one storage device to manage separate volumes for different purposes in your application.

APP_CFG_FS_FILE_CNT defines how many open files you can have at one time. This does NOT mean how many files you can create in total. Just how many can be open without needing to close other open files. This also has a strain on your application resources depending on how many you choose to support open at the same time.

APP_CFG_FS_DIR_CNT is similar to the file count define. This defines how many directories you allow the user to have open at one time. Not how many can be created in total. Adds resource overhead to your application as well.

APP_CFG_FS_BUF_CNT should be setup equally across the total number of volumes you configure. This is why you see it’s define configured with the desired buffer number multiplied by the number of volumes.

APP_CFG_FS_DEV_DRV_CNT defines how many device drivers you wish to support in your application. If your application is using multiple hardware devices and needs to utilize several different drivers this define must reflect that.

APP_CFG_FS_WORKING_DIR_CNT defines the maximum number of active working directories you want to store in the file system instance. Similarly to the file and directory this allows you to maintain several working directories in your application but adds overhead memory cost.

APP_CFG_FS_MAX_SEC_SIZE is typically set to 512 bytes so that clusters are constructed in multiples of 512 bytes. When trying to calculate the size of clusters and determining your devices storage capabilities this is the easiest approach to manage.

These configurations allow you to mold the overall layout of some features of your application file system instance. The next blog will go over how an actual cluster is sized in your system depending on the size of your device and sector max configured size.

Tags: ,

Questions or Comments?

Have a question or a suggestion for a future article?
Don't hesitate to contact us and let us know!
All comments and ideas are welcome.