当前位置: 首页 > news >正文

桌面小屏幕实战课程:DesktopScreen 7 文件系统

飞书文档http://https://x509p6c8to.feishu.cn/docx/doxcnPM42XBp7fgS9GtzNLRgGcj

spiffs文件系统移植

/home/kemp/work/esp/esp-idf/examples/storage/spiffs

复制分区表/home/kemp/work/esp/DesktopScreen/partitions.csv

idf.py menuconfig设置以下参数

CONFIG_PARTITION_TABLE_CUSTOM=y

CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"

CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"

源码下载方式参考:

源码下载方式

文件系统API

​​​​​​​SPIFFS 文件系统 - - ‒ ESP-IDF 编程指南 release-v4.1 文档

/* HTTP File Server ExampleThis example code is in the Public Domain (or CC0 licensed, at your option.)Unless required by applicable law or agreed to in writing, thissoftware is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES ORCONDITIONS OF ANY KIND, either express or implied.
*/#include <sys/param.h>
#include <stdio.h>
#include <string.h>
#include <sys/unistd.h>
#include <sys/stat.h>#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_spiffs.h"
#include "esp_err.h"#include "ds_spiffs.h"/* This example demonstrates how to create file server* using esp_http_server. This file has only startup code.* Look in file_server.c for the implementation */static const char *TAG="spiffs";esp_vfs_spiffs_conf_t conf = {.base_path = "/spiffs",.partition_label = NULL,.max_files = 5,   // This decides the maximum number of files that can be created on the storage.format_if_mount_failed = true
};/* Function to initialize SPIFFS */
esp_err_t init_spiffs(void)
{ESP_LOGI(TAG, "Initializing SPIFFS");esp_err_t ret = esp_vfs_spiffs_register(&conf);if (ret != ESP_OK) {if (ret == ESP_FAIL) {ESP_LOGE(TAG, "Failed to mount or format filesystem");} else if (ret == ESP_ERR_NOT_FOUND) {ESP_LOGE(TAG, "Failed to find SPIFFS partition");} else {ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));}return ESP_FAIL;}size_t total = 0, used = 0;ret = esp_spiffs_info(NULL, &total, &used);if (ret != ESP_OK) {ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret));return ESP_FAIL;}ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);return ESP_OK;
}void ds_spiffs_deinit(){// All done, unmount partition and disable SPIFFSesp_vfs_spiffs_unregister(conf.partition_label);ESP_LOGI(TAG, "SPIFFS unmounted");
}void ds_spiffs_test(){// Use POSIX and C standard library functions to work with files.// First create a file.ESP_LOGI(TAG, "Opening file");FILE* f = fopen("/spiffs/hello.txt", "w");if (f == NULL) {ESP_LOGE(TAG, "Failed to open file for writing");return;}fprintf(f, "Hello World!\n");fclose(f);ESP_LOGI(TAG, "File written");// Check if destination file exists before renamingstruct stat st;if (stat("/spiffs/foo.txt", &st) == 0) {// Delete it if it existsunlink("/spiffs/foo.txt");}// Rename original fileESP_LOGI(TAG, "Renaming file");if (rename("/spiffs/hello.txt", "/spiffs/foo.txt") != 0) {ESP_LOGE(TAG, "Rename failed");return;}// Open renamed file for readingESP_LOGI(TAG, "Reading file");f = fopen("/spiffs/foo.txt", "r");if (f == NULL) {ESP_LOGE(TAG, "Failed to open file for reading");return;}char line[64];fgets(line, sizeof(line), f);fclose(f);// strip newlinechar* pos = strchr(line, '\n');if (pos) {*pos = '\0';}ESP_LOGI(TAG, "Read from file: '%s'", line);
}
http://www.lqws.cn/news/505675.html

相关文章:

  • 01-StarRocks安装部署FAQ
  • HOW - 图片的一倍图、二倍图和三倍图
  • 【Pandas】pandas DataFrame merge
  • 鸿蒙开发 一 (八)、自定义绘制
  • 3DSwiper 好看的走马灯轮播图
  • Meson介绍及编译Glib库
  • 顺序表整理和单项链表01 day20
  • 对人工智能的厌倦感是真实存在的,而且它给品牌带来的损失远不止是参与度的下降
  • 【sklearn】K-means、密度聚类、层次聚类、GMM、谱聚类
  • Flutter 学习 之 mixin
  • CFDEM 介绍和使用指南
  • CUDA12.1+高版本pytorch复现Mtrans环境
  • FastMCP+python简单测试
  • 全面掌握 Nginx的功能和使用方法
  • Ingress-Nginx简介和配置样例
  • 最方便的应用构建——利用云原生快速搭建本地deepseek知识仓库
  • 程序猿成长之路之数据挖掘篇——聚类算法介绍
  • uniapp实现远程图片下载到手机相册功能
  • redis的安装及操作
  • 支持向量机(SVM):原理、实现与应用
  • Python核心库Pandas详解:数据处理与分析利器
  • 传输层协议TCP
  • 随机森林详解:原理、优势与应用实践
  • 【apache-maven3.9安装与配置】
  • C++ string类的操作
  • Python与Web3.py库交互实践
  • ref() 与 reactive()
  • Android中Navigation使用介绍
  • 跟着AI学习C#之项目实践Day5
  • 从0开始学习R语言--Day31--概率图模型