integer.h     FATFS的数据类型定义(一般不需要更改,其他的文件都需要引用这个文件的内容)

ffcon.h    FATFS的配置文件,配置项的各个参数都需要在这里修改

一个细致的讲解fatfs文件系统的原理

https://www.cnblogs.com/amanlikethis/p/3793077.html

fatfs(API)函数的使用

FRESULT error;//定义fatfs操作返回结果
    FIL fsrc;   //FIL掌控一个已打开的文件,由f_open()创建,f_close()抛弃
    UINT bytesWritten;
    UINT bytesRead;  
    UINT readBuffer[50];
     error=f_mount(fs[1],"1:",1);                 //挂载FLASH.
    if(!error){
        printf("fs[1] load sd is ok\r\n");
    }else if(error==0X0D){//FLASH磁盘,FAT文件系统错误,重新格式化FLASH
        error=f_mkfs("1:",1,4096);//格式化FLASH,1,盘符;1,不需要引导区,8个扇区为1个簇
        if(error==0){
            printf("Flash Disk Format Finish");    //格式化完成
        }else{
            printf("Flash Disk Format Error ");    //格式化失败
        }
    }else{
        printf("fs[1] load sd err ,the error num is %d\r\n",error);
    }                                                        
#if 0    //这里是txt文件的创立和使用          
                                                      
    error = f_setlabel((const TCHAR *)"1:START");    //设置Flash磁盘的名字为:START
    if(!error){
        printf("set sd's name is ok\r\n");
    }else{
        printf("set sd's name err ,the error num is %d\r\n",error);
    }
    
    
    error = f_mkdir("1:/523");//创立文件夹(创建一次后再次创建会失败)          1:/523  盘符 + 名称        
    if(!error){
        printf("dir create ok\r\n");
    }else{
        printf("dir create err ,the error num is %d\r\n",error);
    }
    
    error = f_open(&fsrc, "1:523.txt",  FA_OPEN_ALWAYS|FA_WRITE|FA_READ  );  //创立txt文件  1:523.txt         FA_OPEN_ALWAYS(打开一个文件,如果不存在就创建该文件)
    if(!error){
        printf("file create ok\r\n");
    }else{
        printf("file create err ,the error num is %d\r\n",error);
    }
    
    error = f_write (&fsrc , "test" , 5 , &bytesWritten); //在 fsrc 文件内写入test字符串
    if(!error){
        printf("write 'test' is ok\r\n");
    }else{
        printf("write 'test' err ,the error num is %d\r\n",error);
    }
    
    error = f_close(&fsrc);    //关闭 fsrc 文件(打开之后必须关闭)
    if(!error){
        printf("close file ok\r\n");
    }else{
        printf("close file err ,the error num is %d\r\n",error);
    }
    
    error = f_open(&fsrc, "1:523.txt",  FA_READ  );  //打开一个可以读取的文件
    if(!error){
        printf("open a text for read is  ok\r\n");
    }else{
        printf("open a text for read err ,the error num is %d\r\n",error);
    }
    
    error = f_read(&fsrc, &readBuffer ,50,   &bytesRead);  //读取一个文件
    if(!error){
        printf("read a text is  ok\r\n");
    }else{
        printf("read a text err ,the error num is %d\r\n",error);
    }
    
    error = f_sync(&fsrc);    //刷新一个缓存
    if(!error){
        printf("crush a text is  ok\r\n");
    }else{
        printf("crush a text err ,the error num is %d\r\n",error);
    }
    
    error = f_rename("1:523.txt","1:524.txt");    //修改一个文件名(oldname  newname--不能跟其他文件名冲突  )
    if(!error){
        printf("rename a text is  ok\r\n");
    }else{
        printf("rename a text err ,the error num is %d\r\n",error);
    }
    
    
    error = f_unlink("1:524.txt");    //删除一个文件
    if(!error){
        printf("delete a text is  ok\r\n");
    }else{
        printf("detele a text err ,the error num is %d\r\n",error);
    }

fatfs系统的移植的更多相关文章

  1. 鸿蒙系统freeModbusTcp移植简介

    freeModebus是工业中常用的一种通信, 在鸿蒙系统来移植 细节查看代码中,博文只是一些参考以及注意点, 参考了 wifi连接: https://harmonyos.51cto.com/post ...

  2. FatFs文件系统的移植

    FatFs 的底层可以写一次命令,读写多个扇区.FatFs的设计的读写的思想就很好,小块的数据,我就经过Buffer来存储,大块的数据,我就直接进行存取,那样速度,效率高了很多,看图: FatFs文件 ...

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

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

  4. Android系统如何移植wpa_supplicant及wifi驱动

    一.WPA_SUPPLICANT简介 1. 什么是wpa_supplicant wpa_supplicant is a WPA Supplicant for Linux, BSD, Mac OS X, ...

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

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

  6. FATFS文件系统

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

  7. 玩转X-CTR100 l STM32F4 l SD卡FatFs文件系统

    我造轮子,你造车,创客一起造起来!塔克创新资讯[塔克社区 www.xtark.cn ][塔克博客 www.cnblogs.com/xtark/ ] X-CTR100控制器具有SD卡接口,本教程使用免费 ...

  8. STM32平台SD卡的FatFS文件系统开发

    STM32平台SD卡的FatFS文件系统开发 系统平台: STM32系列的STM32F103ZE SPI方式与SD卡通信 SD上移植FatFS系统 1 FatFS文件系统 1.1 FatFS简介 Fa ...

  9. 第25章 串行FLASH文件系统FatFs

    25.1  文件系统 即使读者可能不了解文件系统,读者也一定对“文件”这个概念十分熟悉.数据在PC上是以文件的形式储存在磁盘中的,这些数据的形式一般为ASCII码或二进制形式.在上一章我们已经写好了Q ...

随机推荐

  1. python oracle 写文件 多个SQL变量问题

  2. Robot Framework安装使用

    关于robotframework环境搭建安装请参考 另外一篇博文:Robot Framework的环境搭建(就是一些库文件的安装) 项目基本流程: 1.创建项目New Project----选择dir ...

  3. ActiveMQ相关API

    一.Producer 1,发送消息 MessageProducer send(Message message)发送消息到默认目的地,就是创建Producer时指定的目的地. send(Destinat ...

  4. 使用NGINX+LUA实现WAF功能 和nginx 防盗链

    使用NGINX+LUA实现WAF功能 一.了解WAF 1.1 什么是WAF Web应用防护系统(也称:网站应用级入侵防御系统 .英文:Web Application Firewall,简称: WAF) ...

  5. 小D课堂 - 零基础入门SpringBoot2.X到实战_第三节SpringBoot热部署devtool和配置文件自动注入实战_14、SpringBoot2.x使用Dev-tool热部署

    学习笔记 热部署 每次修改了代码都需要关闭应用重启 热部署就是有一个插件会监听我们应用的代码文件是否有变化,如果有变化就会有其他的类加载器加载 主要的依赖 复制到我们的pom.xml里面 安装完成ja ...

  6. openresty开发系列28--openresty中操作mysql

    openresty开发系列28--openresty中操作mysql Mysql客户端   应用中最常使用的就是数据库了,尤其mysql数据库,那openresty lua如何操作mysql呢?   ...

  7. linux无网络情况下安装rpm包

    首先理清楚两个东西:rpm和yum.rpm全称redhat package manager,用来管理软件包:yum全称yellow dog updater,modified,它是rpm的前端程序,因为 ...

  8. 常用快捷键 & BLOG & Website

    blog http://kejianttt.com/http://pptdesign.blogbus.com/ Website http://www.webdesignerdepot.com/   素 ...

  9. Python - Django - 模板语言之自定义过滤器

    自定义过滤器的文件: 在 app01 下新建一个 templatetags 的文件夹,然后创建 myfilter.py 文件 这个 templatetags 名字是固定的,myfilter 是自己起的 ...

  10. Docker学习笔记——1.2 Docker组件

    Docker的核心组件包括: Docker客户端和服务器,也称为Docker引擎: Docker镜像: Registry: Docker容器. 1.Docker客户端和服务器 Docker是一个客户端 ...