ESP32 Arduino FAT文件系统详细使用教程

news2025/7/19 6:37:58

ESP32 Arduino FAT文件系统详细使用教程


  • 📌参考1(在 Linux环境下创建二进制文件):https://github.com/marcmerlin/esp32_fatfsimage
  • 📌参考2 http://marc.merlins.org/perso/arduino/post_2019-03-30_Using-FatFS-FFat-on-ESP32-Flash-With-Arduino.html
  • 📌参考3:https://techtutorialsx.com/2018/10/06/esp32-arduino-fat-file-system/
  • 📌参考4:https://github.com/lorol/arduino-esp32fs-plugin
  • 📍上传工具(esp32fs)下载地址:https://github.com/lorol/arduino-esp32fs-plugin/releases
  • 🔨 mkfatfs上传工具包:
https://github.com/labplus-cn/mkfatfs/releases/download/v2.0.1/mkfatfs.rar

🎉上面的资源不好下载,这里提供网盘资源:

//mkfatfs资源
链接: https://pan.baidu.com/s/17IQJNh9dzVH8UCEyBmeZVw
提取码: tf1j
//esp32fs插件
链接: https://pan.baidu.com/s/1o6oYHoMje2fwdm8Jz1QQTg
提取码: 4w4v
  • ✨利用核心固件自带的库,不需要加载其他第三方库。

🚩说明:FAT文件系统的使用,应该和littleFS以及SPIFFS文件系统使用类似,不仅可以通过程序中读写操作还可以通过工具mkfatfs创建FatFS文件上传文件到该文件系统当中。但是一直尝试后面这种方式,并没有实现对于文件打包和上传功能。本文仅对代码中创建文件并写入内容的使用说明。

  • 🔖存储结构:
    在这里插入图片描述
  • 🌿在使用Arduino框架下,使用FATFS文件系统文件架构和使用SPIFFS或littleFS一样,将需要上传的文件放置到data文件夹内。
    详细教程
  • 🌴项目树结构:
ffat
    │  ffat.ino
    │  
    └─data
            ESP32Explorer.html
            fatfsimage
            hello.txt
  • 在上面的参考4网页当作有这么一段话,在linux环境下,创建FatFS文件。
    在这里插入图片描述

✅FATFS文件上传操作说明:

  • 上传插件的安装,请下载上面提供的相关链接。
  • 安装方法也在参考4页面有说明:
    在这里插入图片描述
  • 🔧将上面的上传工具包下载下来,将文件并放置到下面的目录下:(如果是1.0.6固件版本那么就放置到对应的1.0.6的tools目录下)
    在这里插入图片描述

在这里插入图片描述

  • 🔨上传FATFS文件:
    在这里插入图片描述
  • 🌿选择FatFS

在这里插入图片描述

  • ⚡上传时,需要关闭串口,否则上传会失败。
    在这里插入图片描述

✨如果没有成功,提示:FatFS Error: mkfatfsnot found!, ,该提示信息,应该是说工具没有找到。没有将mkfatfs放置到指定文件夹了。

  • https://github.com/lorol/arduino-esp32fs-plugin/releases
  • https://github.com/lorol/arduino-esp32fs-plugin/releases/tag/2.0.1
    在这里插入图片描述
  • Universal tool for SPIFFS, LittleFS and FatFS:https://github.com/lorol/arduino-esp32fs-plugin/releases/tag/2.0.1
    在这里插入图片描述

🛠配置FAT分区

根据个人开发板的flash容量,选择合适的配置FATFS分区。

在这里插入图片描述
在这里插入图片描述

🍁自定义分区表配置

首先确定手上的开发板硬件配置,也就是flash容量大小,需要确定,才能进一步进行分区表配置,可以通过上面的示例代码烧录后,查看串口打印信息,可以看到flash容量,

  1. 找到Arduino框架下的ESP32固件分区表文件位置:(1.0.6固件版本)C:\Users\Administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\tools\partitions
  • (2.0.5固件版本)C:\Users\Administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5\tools\partitions

在这里插入图片描述

  • 🔖个人自定义配置的FATFS分区:
    在这里插入图片描述

📚固件自带例程

  • 📍位置:C:\Users\Administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5\libraries\FFat\examples

🔖所包含的2个例程几乎涵盖了FFAT所有对文件操作的函数。这里就不将具体代码贴出来了。

在这里插入图片描述

📝例程1

📋从程序代码中,创建一个名为test.txt文件并写入数据.保存到FATFS文件系统当中。

#include "FFat.h"

void setup() {

   Serial.begin(115200);

   if(!FFat.begin(true)){
        Serial.println("An Error has occurred while mounting FFat");
        return;
   }

    //--------- Write to file
    File fileToWrite = FFat.open("/test.txt", FILE_WRITE);

    if(!fileToWrite){
        Serial.println("There was an error opening the file for writing");
        return;
    }

    if(fileToWrite.println("ORIGINAL CONTENT")){
        Serial.println("File was written");;
    } else {
        Serial.println("File write failed");
    }

    fileToWrite.close();

    //--------- Apend content to file
    File fileToAppend = FFat.open("/test.txt", FILE_APPEND);

    if(!fileToAppend){
        Serial.println("There was an error opening the file for appending");
        return;
    }

    if(fileToAppend.println("APPENDED LINE")){
        Serial.println("Content was appended");
    } else {
        Serial.println("File append failed");
    }

    fileToAppend.close();

    //---------- Read file
    File fileToRead = FFat.open("/test.txt");

    if(!fileToRead){
        Serial.println("Failed to open file for reading");
        return;
    }

    Serial.println("Final file Content:");

    while(fileToRead.available()){

        Serial.write(fileToRead.read());
    }

    fileToRead.close();
}

void loop() {}

📝例程2

📑读取FATFS文件文件系统中的文件信息,也就是上面串口打印的信息截图。

/* Code gathered by Marc MERLIN <marc_soft@merlins.org> from code found
on gitter (license unknown) and in esp32-arduino's 
libraries/FFat/examples/FFat_Test/FFat_Test.ino */

#include <esp_partition.h>
#include "FFat.h"

void partloop(esp_partition_type_t part_type) {
  esp_partition_iterator_t iterator = NULL;
  const esp_partition_t *next_partition = NULL;
  iterator = esp_partition_find(part_type, ESP_PARTITION_SUBTYPE_ANY, NULL);
  while (iterator) {
     next_partition = esp_partition_get(iterator);
     if (next_partition != NULL) {
        Serial.printf("partition addr: 0x%06x; size: 0x%06x; label: %s\n", next_partition->address, next_partition->size, next_partition->label);  
     iterator = esp_partition_next(iterator);
    }
  }
}
 
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    Serial.printf("Listing directory: %s\r\n", dirname);

    File root = fs.open(dirname);
    if(!root){
        Serial.println("- failed to open directory");
        return;
    }
    if(!root.isDirectory()){
        Serial.println(" - not a directory");
        return;
    }

    File file = root.openNextFile();
    while(file){
        if(file.isDirectory()){
            Serial.print("  DIR : ");
            Serial.println(file.name());
            if(levels){
                listDir(fs, file.name(), levels -1);
            }
        } else {
            Serial.print("  FILE: ");
            Serial.print(file.name());
            Serial.print("\tSIZE: ");
            Serial.println(file.size());
        }
	file.close();
        file = root.openNextFile();
    }
}

void setup(){
    Serial.begin(115200);
    Serial.setDebugOutput(true);

    Serial.println("Partition list:");
    partloop(ESP_PARTITION_TYPE_APP);
    partloop(ESP_PARTITION_TYPE_DATA);

    Serial.println("\n\nTrying to mount ffat partition if present");
 
    // Only allow one file to be open at a time instead of 10, saving 9x4 - 36KB of RAM
    if(!FFat.begin( 0, "", 1 )){
        Serial.println("FFat Mount Failed");
        return;
    }
 
    Serial.println("File system mounted");
    Serial.printf("Total space: %10lu\n", FFat.totalBytes());
    Serial.printf("Free space:  %10lu\n\n", FFat.freeBytes());
    listDir(FFat, "/", 5);
}
 
void loop(){}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/363085.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Scala函数式编程(第五章:函数基础、函数高级详解)

文章目录第 5 章 函数式编程5.1 函数基础5.1.1 函数基本语法5.1.2 函数和方法的区别5.1.3 函数定义5.1.4 函数参数5.1.5 函数至简原则&#xff08;重点&#xff09;5.2 函数高级5.2.1 高阶函数5.2.2 匿名函数5.2.3 高阶函数案例5.2.4 函数柯里化&闭包5.2.5 递归5.2.6 控制抽…

GooglePlay SSL Error Handler

应用上架GooglePlay 收到邮件提示 出现这个原因是因为我在app中使用webview加载Https的H5界面&#xff0c;在onReceivedSslError()中处理SslErrorHandler时&#xff0c;出现白屏现象&#xff0c;原因是webview默认在加载有证书验证的url时&#xff0c;会默认使用handler.cancel…

SPDK vhost target

SPDK vhost target主流的I/O设备虚拟化的方案1.virtio2.vhost加速1&#xff09;QEMU virtio-scsiQemu 架构2&#xff09;Kernel vhost-scsi3&#xff09;SPDK vhost-user-scsi3.SPDK vhost-scsi加速4.SPDK vhost-NVMe加速主流的I/O设备虚拟化的方案 纯软件模拟&#xff1a;完全…

vTESTstudio - VT System CAPL Functions - VT7001(续1)

vtsSetInterconnectionMode - 设置VT7001的电源输出模式功能&#xff1a;设置电源模块VT7001的三个可能电源和两个电源输出的互连模式。注意&#xff1a;此函数不能在任何CAPL处理程序例程或ECU节点中调用。它只能在测试模块的MainTest方法上下文中调用&#xff1b;使用在测量开…

企业为什么需要数据可视化报表

数据可视化报表是在商业环境、市场环境已经改变之后&#xff0c;发展出来为当前企业提供替代解决办法的重要方案。而且信息化、数字化时代&#xff0c;很多企业已经进行了初步的信息化建设&#xff0c;沉淀了大量业务数据&#xff0c;这些数据作为企业的资产&#xff0c;是需要…

Logstash:在 Logstash 管道中的定制的 Elasticsearch update by query

我们知道 Elasticsearch output plugin 为我们在 Logstash 的 pipeline 中向 Elasticsearch 的写入提供了可能。我们可以使用如下的格式向 Elasticsearch 写入数据&#xff1a; elasticsearch {hosts > ["https://localhost:9200"]index > "data-%{YYYY.M…

ROS2手写自定义点云(PointCloud2)数据并发布

目录前言实现前言 继续学习ROS2&#xff0c;最近把navigation2的路径规划部分学习了一遍&#xff0c;但是还没有进行测试&#xff0c;于是先把这个部分先空出来后面再总结。先写一个与避障有关系的如何自己发点云数据。 在nav2里面有一个非常重要的部分就是costmap部分&#…

Python是未来的编程语言?学Python前景如何?薪资高吗?

Python是一种强大的语言&#xff0c;为世界各地的开发人员提供了多种用途。根据TIOBE指数&#xff0c;Python的排名还在继续攀升。开发人员和技术专业人员也不断发现Python的新用途&#xff0c;包括数据分析和机器学习等。 Python现在有着庞大的用户基础&#xff0c;并且它深深…

经纬度坐标点和距离之间的转换

1.纬度相同&#xff0c;经度不同 在纬度相同的情况下&#xff1a; 经度每隔0.00001度&#xff0c;距离相差约1米&#xff1b; 每隔0.0001度&#xff0c;距离相差约10米&#xff1b; 每隔0.001度&#xff0c;距离相差约100米&#xff1b; 每隔0.01度&#xff0c;距离相差约1000米…

Linux 远程登录

Linux 一般作为服务器使用&#xff0c;而服务器一般放在机房&#xff0c;你不可能在机房操作你的 Linux 服务器。 这时我们就需要远程登录到Linux服务器来管理维护系统。 Linux 系统中是通过 ssh 服务实现的远程登录功能&#xff0c;默认 ssh 服务端口号为 22。 Window 系统…

SpringCloud+Dubbo3 = 王炸 !

前言 全链路异步化的大趋势来了 随着业务的发展&#xff0c;微服务应用的流量越来越大&#xff0c;使用到的资源也越来越多。 在微服务架构下&#xff0c;大量的应用都是 SpringCloud 分布式架构&#xff0c;这种架构总体上是全链路同步模式。 全链路同步模式不仅造成了资源…

第二章 runtime-core初始化核心流程和runtime-core更新核心流程

runtime-core初始化核心流程 1 创建app 2 进行初始化 2.1 基于组件生成虚拟节点 2.2 进行render 调用patch 根据不同的vnode类型进行不同类型的组件处理 组件 2.2.1 创建component instance对象 2.2.2 setup component 初始化props slots 各种 2.2.3 setupRenderEffect…

通过Docker部署rancher

先创建k8s集群 https://blog.csdn.net/weixin_44371237/article/details/123974335 环境准备 一台linux主机&#xff0c;4G内存 通过Docker部署rancher 启动rancher docker run --privileged -d --restartunless-stopped -p 80:80 -p 443:443 rancher/rancher查看本地镜像…

python基础:简单实现从网页中获取小说名单列表并存入文件中

python基础&#xff1a;简单实现从网页中获取小说名单列表并存入文件中1.技术储备 requests&#xff1a;requests是使用Apache2 licensed 许可证的HTTP库&#xff0c;可以用于网页数据请求 requests.get():发起网络请求的一种方式&#xff0c;类似的还有post、 put、 delete、…

[MySQL]基本数据类型及表的基本操作

哈喽&#xff0c;大家好&#xff01;我是保护小周ღ&#xff0c;本期为大家带来的是 MySQL 数据库常用的数据类型&#xff0c;数据表的基本操作&#xff1a;创建、删除、修改表&#xff0c;针对修改表的结构进行了讲解&#xff0c;随后是如何向数据表中添加数据&#xff0c;浅浅…

Vulnhub_Venom

目录 一 测试 &#xff08;一&#xff09;信息收集 1 端口服务探测 2 目录扫描 3 前端源码信息收集 &#xff08;二&#xff09;漏洞发现 1 前端注释敏感信息泄露 2 CVE-2018-19422-Subrion CMS v 4.2.1任意文件上传 &#xff08;三&#xff09;提权 1 sudo…

4万字c++讲解+区分c和c++,不来可惜了(含代码+解析)

目录 1 C简介 1.1 起源 1.2 应用范围 1.3 C和C 2开发工具 3 基本语法 3.1 注释 3.2关键字 3.3标识符 4 数据类型 4.1基本数据类型 4.2 数据类型在不同系统中所占空间大小 4.3 typedef声明 4.4 枚举类型 5 变量 5.1 变量的声明和定义 5.2 变量的作用域 6 运算符…

面试之设计模式(简单工厂模式)

案例 在面试时&#xff0c;面试官让你通过面对对象语言&#xff0c;用Java实现计算器控制台程序&#xff0c;要求输入两个数和运算符号&#xff0c;得出结果。大家可能想到是如下&#xff1a; public static void main(String[] args) {Scanner scanner new Scanner(System.…

一文让你了解SpringCloud五大核心组件

&#x1f3c6;今日学习目标&#xff1a; &#x1f340;SpringCloud五大核心组件 ✅创作者&#xff1a;林在闪闪发光 ⏰预计时间&#xff1a;30分钟 &#x1f389;个人主页&#xff1a;林在闪闪发光的个人主页 &#x1f341;林在闪闪发光的个人社区&#xff0c;欢迎你的加入: 林…

2021-08-29

服务器 主&#xff1a;172.17.0.2 master 备:172.17.0.3 slave1 lvs虚拟IP:172.17.0.100 #nginx下载地址 http://nginx.org/download/ 本地文件路径 1.dockerfile构建nginx FROM centos:7 ADD nginx-1.6.0.tar.gz /usr/local COPY nginx_install.sh /usr/local RUN sh …