Arduino RP2040 LittleFS的使用
- 📌RP2040基于
Earle F. Philhower, III
的开发核心固件:https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
- 🎈相关开发文档在线说明:
https://arduino-pico.readthedocs.io/en/latest/fs.html
- 📍LittleFS插件下载地址:
https://github.com/earlephilhower/arduino-pico-littlefs-plugin/releases
- ⚡Arduino平台的文件系统,支持Arduino IDE
2.x.x
版本和1.8.x.x
版本下使用。
📘在Arduino IDE 1.8.x.x
版本下,上传LittleFS文件系统文件
- 📍在Arduino IDE
1.8.x.x
版本下,LittleFS文件系统 安装插件下载地址:https://github.com/earlephilhower/arduino-pico-littlefs-plugin
-
- 🌿安装位置:
C:\Users\perse\Documents\Arduino\tools\PicoLittleFS\tool
- 🌿安装位置:
- 🔖LittleFS插件安装好后,重启Arduino IDE
1.8.x.x
,:
- 🌿:上传时,选择对应端口号,进行上传,上传时,RP2040设备首先会有个复位重启动作,直接进入U盘下载模式。
📗在Arduino IDE 2.x.x
版本下,上传LittleFS文件系统文件
- 📍在Arduino IDE
2.x.x
版本下,LittleFS文件系统 安装插件下载地址:https://github.com/earlephilhower/arduino-littlefs-upload
-
- 🌿安装位置:
C:\Users\perse\.arduinoIDE\plugins
- 🌿安装位置:
- 📜上传文件:
- 🔖根据所传文件大小,所需花费的时间不同。上传进度没有进度显示。
- 📄上传文件成功后,重启并打开对应RP2040DE USB虚拟串口:
- 🍁项目文件架构
📘测试示例
- ✨例程可以核心固件中找到,也可以拷贝下面的代码自建工程。
- 🔖在项目目录下创建一个
data
文件夹,并新建一个file1.txt
,里面的内容随便输入。仅供测试使用。
// Released to the public domain
//
// This sketch will read an uploaded file and increment a counter file
// each time the sketch is booted.
// Be sure to install the Pico LittleFS Data Upload extension for the
// Arduino IDE from:
// https://github.com/earlephilhower/arduino-pico-littlefs-plugin/
// The latest release is available from:
// https://github.com/earlephilhower/arduino-pico-littlefs-plugin/releases
// Before running:
// 1) Select Tools->Flash Size->(some size with a FS/filesystem)
// 2) Use the Tools->Pico Sketch Data Upload tool to transfer the contents of
// the sketch data directory to the Pico
//上传命令窗口打开:Ctrl + Shift + P
//LittleFS上传命令:Upload LittleFS to Pico
#include <LittleFS.h>
void setup() {
Serial.begin(115200);
delay(5000);
LittleFS.begin();
char buff[32];
int cnt = 1;
File f = LittleFS.open("counts.txt", "r");
if (f) {
bzero(buff, 32);//将内存块(字符串)的前32个字节清零
if (f.read((uint8_t *)buff, 31)) {
sscanf(buff, "%d", &cnt);
Serial.printf("I have been run %d times\n", cnt);
}
f.close();
}
cnt++;
sprintf(buff, "%d\n", cnt);
f = LittleFS.open("counts.txt", "w");
if (f) {
f.write(buff, strlen(buff));
f.close();
}
Serial.println("---------------");
File i = LittleFS.open("file1.txt", "r");
if (i) {
while (i.available()) {
Serial.write(i.read());
}
Serial.println("---------------");
i.close();
}
}
void loop() {
}
本文含有隐藏内容,请 开通VIP 后查看