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. How to receive JSON as an MVC 5 action method parameter

    How to receive JSON as an MVC 5 action method parameter  解答1 Unfortunately, Dictionary has problems ...

  2. [Java/Reflect]使用反射机制获得一个对象的属性名和属性值

    一个辅助对象,用于给属性排序 class KeyValue implements Comparable<KeyValue>{ String key; Object value; @Over ...

  3. C/C++/Linux编程经典电子书pdf下载

    实际上目前Linux下C开发一般都是C++实现下的C,而不是最纯粹的C,使用g++而不是gcc编译,所以直接学习C++的过程性C部分是更加高效的. C++ Primer(中文版 第5版)C++学习头牌 ...

  4. OpenJudge 计算概论1007:点评赛车

    总时间限制: 1000ms 内存限制: 65536kB描述4名专家对4款赛车进行评论1)A说:2号赛车是最好的:2)B说:4号赛车是最好的:3)C说:3号赛车不是最好的:4)D说: B说错了.事实上只 ...

  5. 000 vue各种基本指令

    一:vue实例 1.实例 新建项目: 2.程序 <!DOCTYPE html> <html lang="en"> <head> <meta ...

  6. 006 GET API

    1.说明 The get API allows to get a JSON document from the index based on its id. GET通过基于id的索引获取JSON文档. ...

  7. IDEA优化配置,提高启动和运行速度

    IDEA优化配置,提高启动和运行速度   参考链接:https://blog.csdn.net/riju4713/article/details/83217013,http://www.pc0359. ...

  8. [Sklearn] Linear regression models to fit noisy data

    Ref: [Link] sklearn各种回归和预测[各线性模型对噪声的反应] Ref: Linear Regression 实战[循序渐进思考过程] Ref: simple linear regre ...

  9. Python - Django - ORM 多对多操作

    models.py: from django.db import models # 出版社 class Publisher(models.Model): id = models.AutoField(p ...

  10. ng2中 如何使用自定义属性data-id 以及赋值和取值操作

    项目环境:ng4.x 写法说明: [attr.data-nurseKey] <div [attr.data-nurseKey]="k.nurseKey"></di ...