Skip to content

Commit 07d7a82

Browse files
committed
Added FatFS
Added binaries in release section
1 parent 90a1724 commit 07d7a82

File tree

2 files changed

+77
-39
lines changed

2 files changed

+77
-39
lines changed

README.md

+25-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
11
# Arduino ESP32 filesystem uploader
22

3-
Arduino plugin which packs sketch data folder into SPIFFS or LittleFS filesystem image,
3+
Arduino plugin which packs sketch data folder into SPIFFS, LITTLEFS or FATFS filesystem image,
44
and uploads the image to ESP32 flash memory.
5-
</br> You can use either LITTLEFS or SPIFFS but not both simultaneously on given Arduino project.
5+
</br> You can have only of three filesystems on given Arduino project.
6+
7+
## Notes for LITTLEFS
8+
9+
- Uses same partition scheme as SPIFFS.
10+
- See [LITTLEFS esp32 library](https://github.com/lorol/LITTLEFS)
11+
12+
## Notes for FatFS
13+
14+
- On Arduino IDE menu: *Tools > Partition Scheme* select one with FAT partition
15+
- The usable size of FAT partition is reduced with 1 sector of 4096 bytes (0x1000) to resolve wear leveling space requirement
16+
- For same reason, the image file is flashed with +4096 bytes (0x1000) offset of partition address csv table entry
17+
- To flash the data folder as FAT partition by network port (uses espota), replace your esp32-core Update library with the [modified files here](https://github.com/lorol/arduino-esp32fatfs-plugin/tree/master/extra/esp32-modified-Update-lib-ffat-espota.zip)
18+
- You may need to decrease **maxOpenFiles** at FFat.begin() of your sketch , [see this note](http://marc.merlins.org/perso/arduino/post_2019-03-30_Using-FatFS-FFat-on-ESP32-Flash-With-Arduino.html)
19+
>The FFAT module uses 8KB plus 4KB per concurrent file that can be opened. By default, it allows 10 files to be opened, which means it uses 48KB. IF you want to reduce its memory use, you can tell it to only support one file, and you will save 36KB, leaving you with only 12KB used.
20+
```
21+
if (!FFat.begin(0, "", 1)) die("Fat FS mount failed. Not enough RAM?");
22+
```
623

724
## Installation
825

926
- Make sure you use one of the supported versions of Arduino IDE and have ESP32 core installed.
10-
- Download the tool from [here](https://github.com/lorol/arduino-esp32fs-plugin/releases/download/1.0%2C1/esp32fs.zip)
27+
- Download the tool from [here](https://github.com/lorol/arduino-esp32fs-plugin/releases/download/2.0/esp32fs.zip)
1128
- In your Arduino sketchbook directory, create tools directory if it doesn't exist yet.
1229
- Unpack the tool into tools directory (the path will look like ```<home_dir>/Arduino/tools/ESP32FS/tool/esp32fs.jar```).
13-
- If not already installed, for LITTLEFS you need an additional [mklittlefs tool](https://github.com/earlephilhower/mklittlefs) Download the [release](https://github.com/earlephilhower/mklittlefs/releases) and copy it to
14-
packages\esp32\tools\mkspiffs\<mklittlefs rev. x.x.x>\ or on checkout (dev) environment to: packages\esp32\hardware\esp32\<release>\tools\mklittlefs\
30+
- For LITTLEFS, you need an additional [mklittlefs tool](https://github.com/earlephilhower/mklittlefs) Download the [release](https://github.com/earlephilhower/mklittlefs/releases)
31+
- For FatFS, you need additional binary files for Windows and Linux (thanks @lbernstone for compiling) or take it from the author [here - mkfatfs tool](https://github.com/labplus-cn/mkfatfs/releases/tag/v1.0) Thanks to [labplus-cn](https://github.com/labplus-cn/mkfatfs)
32+
- Copy **mklittlefs[.exe]** and **mkfatfs[.exe]** to **/tools** folder of esp32 platform where **espota** and **esptool** (.py or.exe) tools are located
33+
- Alternatively see [here](https://github.com/lorol/arduino-esp32fs-plugin/releases/download/2.0/) , there are copy of the binaries. You can also use **package_esp32_index.template.json** and run get.py instead
1534
- Restart Arduino IDE.
1635

1736

18-
On the OS X create the tools directory in ~/Documents/Arduino/ and unpack the files there
19-
2037
## Usage
2138

2239
- Open a sketch (or create a new one and save it).
@@ -26,7 +43,7 @@ On the OS X create the tools directory in ~/Documents/Arduino/ and unpack the fi
2643
- Select *Tools > ESP32 Sketch Data Upload* menu item. This should start uploading the files into ESP32 flash file system.
2744
- When prompted, select SPIFFS or LITTLEFS image you want to make from your data folder.
2845

29-
When done, IDE status bar will display SPIFFS or LITTLEFS Image Uploaded message. Might take a few minutes for large file system sizes.
46+
When done, IDE status bar will display the status of Image Uploaded message. Might take a few minutes for large file system sizes.
3047

3148
## Credits and license
3249

src/ESP32FS.java

+52-31
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,11 @@ private long getIntPref(String name){
165165
}
166166

167167
private void createAndUpload(){
168-
long spiStart = 0, spiSize = 0, spiPage = 256, spiBlock = 4096;
168+
long spiStart = 0, spiSize = 0, spiPage = 256, spiBlock = 4096, spiOffset = 0;
169169
String partitions = "";
170170

171+
if (typefs == "FATFS") spiOffset = 4096;
172+
171173
if(!PreferencesData.get("target_platform").contentEquals("esp32")){
172174
System.err.println();
173175
editor.statusError(typefs + " Not Supported on "+PreferencesData.get("target_platform"));
@@ -192,10 +194,12 @@ private void createAndUpload(){
192194
String mkspiffsCmd;
193195
if(PreferencesData.get("runtime.os").contentEquals("windows"))
194196
if (typefs == "LITTLEFS") mkspiffsCmd = "mklittlefs.exe";
195-
else mkspiffsCmd = "mkspiffs.exe";
197+
else if (typefs == "FATFS") mkspiffsCmd = "mkfatfs.exe";
198+
else mkspiffsCmd = "mkspiffs.exe";
196199
else
197200
if (typefs == "LITTLEFS") mkspiffsCmd = "mklittlefs";
198-
else mkspiffsCmd = "mkspiffs";
201+
else if (typefs == "FATFS") mkspiffsCmd = "mkfatfs";
202+
else mkspiffsCmd = "mkspiffs";
199203

200204
String espotaCmd = "espota.py";
201205
if(PreferencesData.get("runtime.os").contentEquals("windows"))
@@ -234,7 +238,7 @@ private void createAndUpload(){
234238
BufferedReader partitionsReader = new BufferedReader(new FileReader(partitionsFile));
235239
String partitionsLine = "";
236240
while ((partitionsLine = partitionsReader.readLine()) != null) {
237-
if(partitionsLine.contains("spiffs")) {
241+
if(partitionsLine.contains("spiffs") || partitionsLine.contains("ffat")){
238242
partitionsLine = partitionsLine.substring(partitionsLine.indexOf(",")+1);
239243
partitionsLine = partitionsLine.substring(partitionsLine.indexOf(",")+1);
240244
partitionsLine = partitionsLine.substring(partitionsLine.indexOf(",")+1);
@@ -243,8 +247,8 @@ private void createAndUpload(){
243247
partitionsLine = partitionsLine.substring(partitionsLine.indexOf(",")+1);
244248
while(partitionsLine.startsWith(" ")) partitionsLine = partitionsLine.substring(1);
245249
String pSize = partitionsLine.substring(0, partitionsLine.indexOf(","));
246-
spiStart = parseInt(pStart);
247-
spiSize = parseInt(pSize);
250+
spiStart = parseInt(pStart) + spiOffset;
251+
spiSize = parseInt(pSize) - spiOffset;
248252
}
249253
}
250254
if(spiSize == 0){
@@ -295,18 +299,25 @@ private void createAndUpload(){
295299
esptool = new File(platform.getFolder()+"/tools", esptoolCmd);
296300
if(!esptool.exists() || !esptool.isFile()){
297301
esptool = new File(platform.getFolder()+"/tools/esptool_py", esptoolCmd);
298-
if(!esptool.exists()){
299-
esptool = new File(PreferencesData.get("runtime.tools.esptool_py.path"), esptoolCmd);
300-
if (!esptool.exists()) {
301-
System.err.println();
302-
editor.statusError(typefs + " Error: esptool not found!");
303-
return;
304-
}
302+
if(!esptool.exists() || !esptool.isFile()){
303+
esptool = new File(platform.getFolder()+"/tools/esptool", esptoolCmd);
304+
if(!esptool.exists() || !esptool.isFile()){
305+
esptool = new File(PreferencesData.get("runtime.tools.esptool_py.path"), esptoolCmd);
306+
if(!esptool.exists() || !esptool.isFile()){
307+
esptool = new File(PreferencesData.get("runtime.tools.esptool.path"), esptoolCmd);
308+
if(!esptool.exists() || !esptool.isFile()){
309+
System.err.println();
310+
editor.statusError("SPIFFS Error: esptool not found!");
311+
return;
312+
}
313+
}
314+
}
305315
}
306316
}
307-
System.out.println("esptool : "+esptool.getAbsolutePath());
308-
System.out.println();
309317
}
318+
System.out.println("esptool : "+esptool.getAbsolutePath());
319+
System.out.println();
320+
310321

311322
//load a list of all files
312323
int fileCount = 0;
@@ -335,23 +346,33 @@ private void createAndUpload(){
335346

336347
if(fileCount == 0 && JOptionPane.showOptionDialog(editor, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]) != JOptionPane.YES_OPTION){
337348
System.err.println();
338-
editor.statusError(typefs + " Warning: mkspiffs canceled!");
349+
editor.statusError(typefs + " Warning: mktool canceled!");
339350
return;
340351
}
341352

342353
editor.statusNotice(typefs + " Creating Image...");
343354
System.out.println("[" + typefs + "] data : "+dataPath);
355+
System.out.println("[" + typefs + "] offset : "+spiOffset);
344356
System.out.println("[" + typefs + "] start : "+spiStart);
345357
System.out.println("[" + typefs + "] size : "+(spiSize/1024));
346358
System.out.println("[" + typefs + "] page : "+spiPage);
347359
System.out.println("[" + typefs + "] block : "+spiBlock);
348360

349361
try {
350-
if(listenOnProcess(new String[]{toolPath, "-c", dataPath, "-p", spiPage+"", "-b", spiBlock+"", "-s", spiSize+"", imagePath}) != 0){
351-
System.err.println();
352-
editor.statusError(typefs + " Create Failed!");
353-
return;
362+
if (typefs == "FATFS") {
363+
if(listenOnProcess(new String[]{toolPath, "-c", dataPath, "-s", spiSize+"", imagePath}) != 0){
364+
System.err.println();
365+
editor.statusError(typefs + " Create Failed!");
366+
return;
367+
}
368+
} else {
369+
if(listenOnProcess(new String[]{toolPath, "-c", dataPath, "-p", spiPage+"", "-b", spiBlock+"", "-s", spiSize+"", imagePath}) != 0){
370+
System.err.println();
371+
editor.statusError(typefs + " Create Failed!");
372+
return;
373+
}
354374
}
375+
355376
} catch (Exception e){
356377
editor.statusError(e);
357378
editor.statusError(typefs + " Create Failed!");
@@ -386,21 +407,21 @@ private void createAndUpload(){
386407

387408
public void run() {
388409
String sketchName = editor.getSketch().getName();
389-
Object[] options = { "LittleFS", "SPIFFS", };
390-
int result = JOptionPane.showOptionDialog(editor,
410+
Object[] options = { "SPIFFS", "LITTLEFS", "FATFS" };
411+
typefs = (String)JOptionPane.showInputDialog(editor,
391412
"What FS you want for " + sketchName +
392413
" data folder?",
393414
"Select",
394-
JOptionPane.YES_NO_OPTION,
395-
JOptionPane.QUESTION_MESSAGE,
415+
JOptionPane.PLAIN_MESSAGE,
396416
null,
397417
options,
398-
options[1]);
399-
if (result == JOptionPane.YES_OPTION) {
400-
typefs = "LITTLEFS";
401-
} else {
402-
typefs = "SPIFFS";
403-
}
404-
createAndUpload();
418+
"SPIFFS");
419+
if ((typefs != null) && (typefs.length() > 0)) {
420+
createAndUpload();
421+
} else {
422+
System.out.println("Tool Exit.");
423+
return;
424+
}
425+
405426
}
406427
}

0 commit comments

Comments
 (0)