Skip to content

peergum/LittleExtFS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LittleExtFS

Acknowledgment and Disclaimer: This is a slightly modified version of LittleFS-RK library, adapted to run on Gen 3 Particle devices (tested on a Boron). It's a worse derived version from the original in a sense, since the posix functions (open, read, write, close,...) will not work on this version and are instead replaced with equivalents prefixed with lefs_. Don't blame me, the posix functions are implemented in the deviceOS, so there's not much I can do to fix that (or maybe there is, and someone will improve that).

Port of LittleFS for Particle Gen 3 devices (external memory chip, as opposed to Particle's own implementation of LittleFS on the 2MB internal memory).

Tested with a Boron on DeviceOS 5.1.0

Warning: This only works on Gen 3 devices (Argon, Boron, B Series...), although I actually only tested it on the Boron! For Gen 2 devices, please use Rick's version instead.

Warning: As this point in time, it's just a proof-of-concept for testing. There are almost certainly still bugs that haven't been found yet as it has not been extensively tested yet!

Usage

You'll probably need some includes:

#include "LittleExtFS.h"

#include <dirent.h>
#include <sys/stat.h>
#include <fcntl.h>

using namespace nsLittleExtFS;

This code uses the SpiFlashRK library to interface to the flash chip. You typically use one of these lines depending on the brand, SPI port, and CS line:

// Pick a chip, port, and CS line
// SpiFlashISSI spiFlash(SPI, A5);
// SpiFlashWinbond spiFlash(SPI, A5);
// SpiFlashMacronix spiFlash(SPI, A5);
// SpiFlashWinbond spiFlash(SPI, A5);
// SpiFlashMacronix spiFlash(SPI, A5);

You then allocate a LittleExtFS object as a global:

LittleExtFS fs(&spiFlash, 0, 256);

The parameters are:

  • &spiFlash the object for your flash chip
  • 0 the start sector for the file system (0 = beginning of chip)
  • 256 replace with the number of 4096-byte sectors to use for the file system. 256 * 4096 = 1,048,576 bytes = 1 Mbyte, the size of an 8 Mbit SPI flash chip.

Note: You must only ever allocate one LittleExtFS object. Bad things will happen if you create more than one. You can allocate it with new but don't allocate it on the stack.

Finally, in setup(), initialize the SPI flash and mount the file system. This will format it if it has not been formatted.

spiFlash.begin();
int res = fs.mount();
Log.info("fs.mount() = %d", res);

Testing

There is no functional test program yet, I'm still updating the example from the original library:

  • FileSystemTest: A simple app
  • LargeFileTest: A test that writes larger files to test performance

Version History

0.0.1 (2023-03-27)

  • Initial testing version. It probably still has bugs!

About

LittleFS port for External memory on Particle Gen 3 devices (adapted from @rickkas7's LittleFS-RK)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published