(一),什么是文件管理系统

答:数据在PC上是以文件的形式储存在磁盘中的。这些数据的形式一般为ASCII码或二进制形式。简单点说就是:管理磁盘上的文件的方法的代码!

如:我们写到SD卡上面的数据管理一下,更科学的方法来管理

http://elm-chan.org/fsw/ff/00index_e.html,官网介绍 Resources以下是源代码

(二)。我们在移植时主要是那些函数?

答:Device Control Interface(硬件接口函数)

  • disk_status - Get device status                                             选择操纵的模块,此处用SD卡
  • disk_initialize - Initialize device                                                   初始化函数
  • disk_read - Read sector(s)                                                          读
  • disk_write - Write sector(s)                                                         写
  • disk_ioctl - Control device dependent features
  • get_fattime - Get current time

(三),例程:

1,我们用的是0.09版本号的

2。CC936.c中文字体库

①新建工作区间

	/* Register work area for each volume (Always succeeds regardless of disk status) */
f_mount(0,&fs); //(文件管理系统)注冊一个工作区间,工作空间命名为0。

那么工作区间的命名范围是什么呢?

答:

FRESULT f_mount (
BYTE vol, /* Logical drive number to be mounted/unmounted */
FATFS *fs /* Pointer to new file system object (NULL for unmount)*/
)
{
FATFS *rfs; if (vol >= _VOLUMES) /* Check if the drive number is valid */
return FR_INVALID_DRIVE;

vol就是f_mount的第一个形參(命名),当他的值大于等于 _VOLUMES,就会返回错误

#define _VOLUMES	1  //can define 9
/* Number of volumes (logical drives) to be used. */

Parameters(官网)

Drive
Logical drive number (0-9) to register/unregister the work area.
FileSystemObject
Pointer to the work area (file system object) to be registered.

②然后再工作区间里面新建文件

/* function disk_initialize() has been called in f_open */

/* Create new file on the drive 0 */
res = f_open(&fnew, "0:newfile.txt", FA_CREATE_ALWAYS | FA_WRITE );

OPEN的属性:

1.怎么打开呢?

FA_CREATE_ALWAYS 总是以创建总是新建的形式打开这个文件

FA_WRITE:此文件仅仅能写

2.看下open函数

FRESULT f_open (

  FIL* FileObject,       /* Pointer to the blank file object structure */   文件指针,把打开的文件关联到这个指针连

  const TCHAR* FileName, /* Pointer to the file neme */        文件名称字

  BYTE ModeFlags         /* Mode flags */               属性     

);  

属性:

Value Description
FA_READ Specifies read access to the object. Data can be read from the file. Combine with
FA_WRITE for read-write access.
FA_WRITE Specifies write access to the object. Data can be written to the file. Combine with
FA_READ for read-write access.
FA_OPEN_EXISTING Opens the file. The function fails if the file is not existing. (Default)
FA_OPEN_ALWAYS Opens the file if it is existing. If not, a new file is created. To append data to the file, use
f_lseek function after file open in this method.
FA_CREATE_NEW Creates a new file. The function fails with FR_EXIST if the file is existing.
FA_CREATE_ALWAYS Creates a new file. If the file is existing, it is truncated and overwritten.

能够第一次打开用:FA_CREATE_NEW。之后打开用:FA_OPEN_EXISTING(已存在)就能够了

或者:总是打开。总是关闭

当用到:FA_CREATE_ALWAYS时,我们要将  #define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */    打开

3.对于返回值(Return Values):我们仅仅測试:FR_OK(是否成功)

③往该文件内写数据

if ( res == FR_OK )
{
res = f_write(&fnew, textFileBuffer, sizeof(textFileBuffer), &bw);
f_close(&fnew); 写完之后,把该文件关掉
}

④关掉之后再打开它

res = f_open(&fnew, "0:newfile.txt", FA_OPEN_EXISTING | FA_READ); 	// FA_READ:此时打开定义可读

⑤读取数据

res = f_read(&fnew, buffer, sizeof(buffer), &br);

⑥打印之后关闭

printf("\r\n %s ", buffer);

/* Close open files */
f_close(&fnew);

⑦在文件系统中注冊掉刚才开辟的“0”工作区间

/* Unregister work area prior to discard it */
f_mount(0, NULL);

(四)文件管理系统与SD卡的关联!

1。Application:就是我们主函数中使用的那些上层函数

2,中间是文件系统模块,文件系统要操纵底层SD卡的时候呢还须要  Low level disk I/O。这一部分驱动,这一部分驱动须要我们自己写

/*-------------------------- SD Init ----------------------------- */
Status = SD_Init();
if (Status!=SD_OK )
{
return STA_NOINIT;
}
else
{
return RES_OK;
} }

/*-----------------------------------------------------------------------*/
/* Return Disk Status */ DSTATUS disk_status (
BYTE drv /* Physical drive nmuber (0..) */
)
{
return RES_OK;
}

底层的磁盘的读/写

/*-----------------------------------------------------------------------*/
/* Read Sector(s) */ DRESULT disk_read (
BYTE drv, /* Physical drive nmuber (0..) */
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address (LBA) */
BYTE count /* Number of sectors to read (1..255) */
)
{ if (count > 1) //多个磁盘
{
SD_ReadMultiBlocks(buff, sector*BLOCK_SIZE, BLOCK_SIZE, count); /* Check if the Transfer is finished */
SD_WaitReadOperation(); //循环查询dma传输是否结束 /* Wait until end of DMA transfer */
while(SD_GetStatus() != SD_TRANSFER_OK);
}
else //单个磁盘
{ SD_ReadBlock(buff, sector*BLOCK_SIZE, BLOCK_SIZE); /* Check if the Transfer is finished */
SD_WaitReadOperation(); //循环查询dma传输是否结束 /* Wait until end of DMA transfer */
while(SD_GetStatus() != SD_TRANSFER_OK); }
return RES_OK;
} /*-----------------------------------------------------------------------*/
/* Write Sector(s) */ #if _READONLY == 0
DRESULT disk_write (
BYTE drv, /* Physical drive nmuber (0..) */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address (LBA) */
BYTE count /* Number of sectors to write (1..255) */
)
{ if (count > 1)
{
SD_WriteMultiBlocks((uint8_t *)buff, sector*BLOCK_SIZE, BLOCK_SIZE, count); /* Check if the Transfer is finished */
SD_WaitWriteOperation(); //等待dma传输结束
while(SD_GetStatus() != SD_TRANSFER_OK); //等待sdio到sd卡传输结束
}
else
{
SD_WriteBlock((uint8_t *)buff,sector*BLOCK_SIZE, BLOCK_SIZE); /* Check if the Transfer is finished */
SD_WaitWriteOperation(); //等待dma传输结束
while(SD_GetStatus() != SD_TRANSFER_OK); //等待sdio到sd卡传输结束
}
return RES_OK;
}
#endif /* _READONLY */

IO控制为空(直接返回OK)

/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */ DRESULT disk_ioctl (
BYTE drv, /* Physical drive nmuber (0..) */
BYTE ctrl, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
return RES_OK;
}

                           嵌入式刚開始学习的人,看到此文的大神们,有什么错误的地方多多意见啊!

FATFS的更多相关文章

  1. STM32下FatFs的移植,实现了坏块管理,硬件ECC,ECC纠错,并进行擦写均衡分析

    最近因项目需要,做一个数据采集的单片机平台.需要移植 FatFs .现在把最后成果贴上来. 1.摘要 在 STM32 单片机上,成功移植 FatFs 0.12b,使用的 Nand Flash 芯片为 ...

  2. 【液晶模块系列基础视频】3.1.fatfs文件系统的移植及接口函数的使用

    ============================== 技术论坛:http://www.eeschool.org 博客地址:http://xiaomagee.cnblogs.com 官方网店:h ...

  3. FATFS文件系统

    STM32移植文件系统,操作SD卡,对SD卡进行读写 FATFS文件系统与底层介质的驱动分离开来,对底层介质的操作都要交给用户去实现,它仅仅是提供了一个函数接口而已,函数为空,要用户添加代码.然后 F ...

  4. Petit FatFs

    FatFs is a generic FAT/exFAT file system module for small embedded systems. The FatFs module is writ ...

  5. FATFS外置UNICODE GBK双向转换码表(转)

    源:FATFS外置UNICODE GBK双向转换码表 将UtoG,GtoU双向码表放到存储卡里面实现长文件名,因为FATFS长文件名需要unicode支持, 首先将UtoG.sys,GtoU.sys两 ...

  6. unicode转GBK,GNK转unicode,解决FATFS中文码表占用ROM问题(转)

    源:unicode转GBK,GNK转unicode,解决FATFS中文码表占用ROM问题 之前一直使用的512KB ROM的STM32,但是最近使用的只有128KB,想用FATFS显示支持长文件名,发 ...

  7. 使用STM32Cube在STM32F7开发板上实现SD+Freertos+Fatfs

    简介 最近项目中可能需要使用到SD卡,所以需要对SD卡的配置和使用调研,在配置过程中遇到了一些问题,在此记录一下. STM32Cube配置 Pinout 只需要注意绿色部分的设定 Clock配置 这里 ...

  8. 配置 FATFS 支持长文件名

    FATFS 版本:Nov 09 14 R0.10c 在 FATFS 已经移植好的基础上,首先打开 ffconf.h 配置文件,找到如下图配置项: 可以将此值从 0 改为 1 使用 static wor ...

  9. 基于FATFS的磁盘分布

    1.前言 本文主要采用FAT32文件系统的磁盘各个部分是如何划分的 2. 磁盘分布总图 如包含两个分区的磁盘整体分布如下: 图 带有两个分区的磁盘分布 2.1 MBR 图  MBR的高层视图 主引导记 ...

  10. 【GMT43智能液晶模块】例程十三:FATFS实验——文件操作

    实验原理: STM32F429上带有SDIO控制器,GMT43液晶模块上将SDIO连接到TF卡座.本实验 将Micro SD卡插入TF卡座上即可.通过FATFS创建test.txt文件,并且写入数据0 ...

随机推荐

  1. PHP抓取页面中的邮箱

    <?php $url='http://www.cnblogs.com/tinyphp/p/3234926.html'; //当页已留邮箱 $content=file_get_contents($ ...

  2. EntityFramework:迁移工具入门

    背景 刚毕业做项目的时候,没有用“迁移”这个概念,系统发布和更新的过程让人非常痛苦,在学习 Ruby On Rails 的过程解除了“迁移”,以后的所有项目都会先确定好“迁移”的方案,本文介绍一下En ...

  3. [Hive]使用HDFS文件夹数据创建Hive表分区

    描写叙述: Hive表pms.cross_sale_path建立以日期作为分区,将hdfs文件夹/user/pms/workspace/ouyangyewei/testUsertrack/job1Ou ...

  4. Codeforces Round #261 (Div. 2)[ABCDE]

    Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...

  5. OpenSSL再曝CCS注入漏洞-心伤未愈又成筛子

    太戏剧了,昨晚看了佳片有约,还不错,2012版的<完美回顾>,像我这样的人依旧选择用电视或者去影院看电影,在没有中间插播广告的时候,体验憋尿得过程中,总是能突然有非常多的想法,这是用电脑或 ...

  6. linux、mac的bash和zsh如何切换

    1.hostname 192-23-2-2 修改主机名字 2.chsh -s /bin/bash和chsh -s /bin/zsh可以永久切换,也就是一登录进来的就是相应的界面 bash/zsh命令是 ...

  7. iOS: 详细的正则表达式

    一.简单的正则规则 1.由数字.26个英文字母或者下划线组成的字符串: ^[-9a-zA-Z_]{,}$ 2.非负整数(正整数 + 0 ): ^/d+$ 3. 正整数: ^[-]*[-][-]*$ 4 ...

  8. Linux ALSA音频PCM播放编程

    使用ALSA播放两个频率的单音,并使用GNU Radio中的Audio Source和FFT来观测声音的频谱. #include <alsa/asoundlib.h> #include & ...

  9. 解析Java的JNI编程中的对象引用与内存泄漏问题

    JNI,Java Native Interface,是 native code 的编程接口.JNI 使 Java 代码程序可以与 native code 交互——在 Java 程序中调用 native ...

  10. leetcode mock Shuffle an Array

    1. shuffle算法: http://www.cnblogs.com/huaping-audio/archive/2008/09/09/1287985.html 注意:我们一般用的是第二种swap ...