1@page fatfs 2 3[更正文档](https://gitee.com/alios-things/fatfs/edit/master/README.md)      [贡献说明](https://help.aliyun.com/document_detail/302301.html) 4 5# 概述 6**fatfs** is a generic FAT/exFAT filesystem module for small embedded system. The fatfs module is written in compliance with ANSI C (C89). It attempts to provide AOS-compatible filesystem behaviour. 7组件支持以下功能 8- DOS/Windows compatible FAT/exFAT filesystem 9- Very small footprint for program code and work area 10- Various configuration options to support for: 11 - Long file name in ANSI/OEM or Unicode. 12 - exFAT filesystem. 13 - Thread safe for RTOS. 14 - Multiple volumes (physical drives and partitions) 15 - Variable sector size. 16 - Multiple code page including DBCS. 17 - Read-only, optional API, I/O buffer and etc... 18 19## 版权信息 20> Apache license v2.0 21 22## 目录结构 23```tree 24fatfs 25├── src 26│ ├── mmc_disk 27│ │ ├── mmc_disk.c 28│ │ └── mmc_disk.h 29│ ├── ram_disk 30│ │ ├── ram_disk.c 31│ │ └── ram_disk.h 32│ ├── sd_disk 33│ │ ├── sd_disk.c 34│ │ └── sd_disk.h 35│ └── usb_disk 36│ ├── usb_disk.c 37│ └── usb_disk.h 38├── include 39│ ├── diskio.h 40│ ├── fatfs_diskio.h 41│ ├── fatfs.h 42│ ├── ff.h 43│ ├── ffconf.h 44│ ├── integer.h 45├── package.yaml # 编译配置文件 46├── example 47│ └── fatfs_example.c # 示例代码 48└─── README.md 49``` 50 51## 依赖组件 52* rhino 53* vfs 54 55# 常用配置 56 57```yaml 58def_config: 59 CONFIG_AOS_FATFS_SUPPORT_MMC: 1 60 AOS_COMP_VFS: 1 61 AOS_COMP_FATFS: 1 62``` 63 64# 使用示例 65 66组件使用示例相关的代码下载、编译和固件烧录均依赖AliOS Things配套的开发工具,所以首先需要参考[《AliOS Things集成开发环境使用说明之搭建开发环境》](https://help.aliyun.com/document_detail/302378.html),下载安装。 67待开发环境搭建完成后,可以按照以下步骤进行示例的测试。 68 69## 步骤1 创建或打开工程 70 71**打开已有工程** 72 73如果用于测试的案例工程已存在,可参考[《AliOS Things集成开发环境使用说明之打开工程》](https://help.aliyun.com/document_detail/302381.html)打开已有工程。 74 75**创建新的工程** 76 77组件的示例代码可以通过编译链接到AliOS Things的任意案例(solution)来运行,这里选择helloworld_demo案例。helloworld_demo案例相关的源代码下载可参考[《AliOS Things集成开发环境使用说明之创建工程》](https://help.aliyun.com/document_detail/302379.html)。 78 79## 步骤2 添加组件 80 81案例下载完成后,需要在helloworld_demo组件的package.yaml中添加对组件的依赖: 82 83```yaml 84 85depends: 86 - fatfs: master # helloworld_demo中引入fatfs组件 87 88``` 89 90## 步骤3 下载组件 91 92在已安装了 的开发环境工具栏中,选择Terminal -> New Terminal启动终端,并且默认工作路径为当前工程的workspace,此时在终端命令行中输入: 93 94```shell 95 96aos install fatfs 97 98``` 99 100上述命令执行成功后,组件源码则被下载到了./components/fatfs路径中。 101 102## 步骤4 添加示例 103 104在fatfs组件的package.yaml中添加[example示例代码](https://gitee.com/alios-things/a2sa/tree/master/example): 105示例代码参考example/fatfs_example.c。 106 107```yaml 108source_file: 109 - "src/*.c" 110 - "example/fatfs_example.c" # add fatfs_example.c 111``` 112 113## 步骤5 编译固件 114 115在示例代码已经添加至组件的配置文件,并且helloworld_demo已添加了对该组件的依赖后,就可以编译helloworld_demo案例来生成固件了,具体编译方法可参考[《AliOS Things集成开发环境使用说明之编译固件》](https://help.aliyun.com/document_detail/302384.html)。 116 117## 步骤6 烧录固件 118 119helloworld_demo案例的固件生成后,可参考[《AliOS Things集成开发环境使用说明之烧录固件》](https://help.aliyun.com/document_detail/302383.html)来烧录固件。 120 121## 步骤7 打开串口 122 123固件烧录完成后,可以通过串口查看示例的运行结果,打开串口的具体方法可参考[《AliOS Things集成开发环境使用说明之查看日志》](https://help.aliyun.com/document_detail/302382.html)。 124 125当串口终端打开成功后,可在串口中输入help来查看已添加的测试命令。 126 127## 步骤8 测试示例 128 129> CLI命令行输入: 130```sh 131fatfs_example 132``` 133 134**关键日志** 135> CLI日志: 136```sh 137fatfs component example start! 138aos_open fd1=xxx 139aos_write num=xxx 140aos_open fd2=xxx 141aos_lseek position=xxx 142aos_read: xxxx 143fatfs component example end ! 144``` 145 146