fatfs文件系统笔记

移植fatfs需要实现的函数


在这里插入图片描述

中断优先级


当同时开启SDIO全局中断和DMA中断时,SDIO中断优先级必须大于DMA中断优先级。

物理驱动器、逻辑驱动器和卷


物理驱动器是实体,一个硬盘就是一个物理驱动器,一张sd卡也是一个物理驱动器。对物理驱动器进行分区后得到逻辑驱动器,不分区的话一个物理驱动器只有一个分区,即一个逻辑驱动器。逻辑驱动器格式化之后为卷,例如C盘、D盘等。一个逻辑驱动器对应一个卷。

working buffer


有一些函数(如f_mkfs)里需要传入working buffer,作为这个函数的工作内存或缓冲区。

ffconf.h的一些配置


卷数量和卷名称

#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为卷的数量,即逻辑驱动器的数量。

  • FF_STR_VOLUME_ID默认为0,卷名(即逻辑驱动器名)用0~9表示。
  • FF_STR_VOLUME_ID设置为1时,卷名(即逻辑驱动器名)可以在FF_VOLUME_STRS中自定义为字符串形式,数量必须小于FF_VOLUMES,如果没有定义FF_VOLUME_STRS则需要定义const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",...

多个分区或卷

#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. */
  • 默认为0,这时一个物理驱动器对应一个逻辑驱动器,所以逻辑驱动器号就是物理驱动器号。物理驱动器号需要自己定义,并且需要移植的函数中需要根据物理驱动器号写不同的底层驱动代码。在stm32cubemx中驱动器号码按照FATFS_LinkDriver函数的先后顺序从0~9分配但需要小于FF_VOLUMES(最大为10)。
  • 当设置为1时,需要自定义PARTITION VolToPart[],即每个物理驱动器对应有几个分区。每个逻辑驱动器可以绑定到在VolToPart[]中列出来的任意物理驱动器和分区,每个物理设备上可以使用f_fdisk()创建分区,每个分区都需要用f_mkfs格式化一次。如果不创建分区则直接挂载。这时所有物理设备上的所有分区加起来不能超过FF_VOLUMES(最大为10)。
    在这里插入图片描述

参考


[1] fatfs官网
[2] 多个物理设备


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部