fatfs file system notes

Posted by dannyluked on Wed, 26 Jan 2022 15:00:29 +0100

Functions to be implemented for porting fatfs

Interrupt priority

When SDIO global interrupt and DMA interrupt are enabled at the same time, SDIO interrupt priority must be greater than DMA interrupt priority.

Physical drives, logical drives, and volumes

Physical drive is an entity. A hard disk is a physical drive, and an sd card is also a physical drive. After partitioning the physical drive, the logical drive is obtained. If not, a physical drive has only one partition, that is, one logical drive. The logical drive is formatted as a volume, such as drive C, drive D, etc. A logical drive corresponds to a volume.

working buffer

Some functions (such as f_mkfs) need to pass in the working buffer as the working memory or buffer of this function.

ffconf. Some configurations of H

Volume number and volume name

#define FF_VOLUMES		1
/* Number of volumes (logical drives) to be used. (1-10) */

#define FF_STR_VOLUME_ID          0	/* 0:Use only 0-9 for drive ID, 1:Use strings for drive ID */
#define FF_VOLUME_STRS            "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
/  When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive
/  number in the path name. FF_VOLUME_STRS defines the volume ID strings for each
/  logical drives. Number of items must not be less than FF_VOLUMES. Valid
/  characters for the volume ID strings are A-Z, a-z and 0-9, however, they are
/  compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is
/  not defined, a user defined volume string table needs to be defined as:
/
/  const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",...
*/

FF_VOLUMES is the number of volumes, that is, the number of logical drives.

  • FF_ STR_ VOLUME_ The default ID is 0, and the volume name (i.e. logical drive name) is represented by 0 ~ 9.
  • FF_ STR_ VOLUME_ When the ID is set to 1, the volume name (i.e. logical drive name) can be in FF_VOLUME_STRS is defined as a string, and the quantity must be less than FF_ Volumes, if FF is not defined_ VOLUME_ STRs needs to define const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb"

Multiple partitions or volumes

#define FF_MULTI_PARTITION	0
/* This option switches support for multiple volumes on the physical drive.
/  By default (0), each logical drive number is bound to the same physical drive
/  number and only an FAT volume found on the physical drive will be mounted.
/  When this function is enabled (1), each logical drive number can be bound to
/  arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
/  funciton will be available. */
  • The default is 0. At this time, a physical drive corresponds to a logical drive, so the logical drive letter is the physical drive letter. The physical drive letter needs to be defined by yourself, and different underlying driver codes need to be written according to the physical drive letter in the functions that need to be transplanted. In stm32cubemx, the drive number is in accordance with FatFs_ The order of linkdriver function is allocated from 0 to 9, but it needs to be less than FF_VOLUMES (max. 10).
  • When it is set to 1, you need to customize the PARTITION VolToPart [], that is, there are several partitions corresponding to each physical drive. Each logical drive can be bound to any physical drive and partition listed in VolToPart [], and F can be used on each physical device_ Fdisk () creates partitions, and F is required for each partition_ Mkfs format once. If you do not create a partition, mount it directly. At this time, the sum of all partitions on all physical devices cannot exceed FF_VOLUMES (max. 10).

reference resources

[1] fatfs official website
[2] Multiple physical devices

Topics: Single-Chip Microcomputer