Using the program flash as a file system

ChrisCurl

Active member
I am a new Teensy user, and am in the process of porting my Forth implementation (BoardForth) to the Teensy 4.x, and have one area that I need help with. I need a way to persist data to the Teensy at run-time.

If you are familiar with Forth, you probably know that older Forth systems have a approach that uses "blocks" as the persistent storage mechanism. BoardForth has something similar.

BoardForth uses (and only ever will use) a small fraction of the program data space, so there is more than enough flash there for my needs. I would like to, if possible, use some of that unused flash space for a simple filesystem-like area that I can read from and write to at runtime. Even 64k would be way more than I need.

I am sure this is not a new idea, or request, and has been talked about before on the forum, and there is probably already something out there I can use. The thread I found on the topic has hundreds of replies, and it very difficult to wade though all the replies to find what I'm looking for.

In my implementation of BoardForth for the PC, I use fopen(), fclose() ... , where the filename is "block-<nnn>.blk". Something similar on the Teensy would be awesome, but not required :). I'll learn how to use whatever is currently available.

FWIW, read/write speed is not a concern at all, as this would be used simply to be able to persist my interactively defined Forth words to the board and read them back them in when the board starts up.

Thanks for your consideration, Chris
 
Upon further research, it looks like the LittleFS at https://github.com/PaulStoffregen/LittleFS will probably provide the functionality I'm looking for:

So ... how would I go about downloading it to include in my Arduino project?

Sorry, I'm new to the Arduino IDE, so it's probably really easy, I just don't know how to do it yet.
 
See this Forum, "Announcements".

All your files will be deleted when you upload a new sketch.
As far as I know it is planned to change that. May take some months.
 
I am a new Teensy user, and am in the process of porting my Forth implementation (BoardForth) to the Teensy 4.x, and have one area that I need help with. I need a way to persist data to the Teensy at run-time.

If you are familiar with Forth, you probably know that older Forth systems have a approach that uses "blocks" as the persistent storage mechanism. BoardForth has something similar.

BoardForth uses (and only ever will use) a small fraction of the program data space, so there is more than enough flash there for my needs. I would like to, if possible, use some of that unused flash space for a simple filesystem-like area that I can read from and write to at runtime. Even 64k would be way more than I need.

I am sure this is not a new idea, or request, and has been talked about before on the forum, and there is probably already something out there I can use. The thread I found on the topic has hundreds of replies, and it very difficult to wade though all the replies to find what I'm looking for.

In my implementation of BoardForth for the PC, I use fopen(), fclose() ... , where the filename is "block-<nnn>.blk". Something similar on the Teensy would be awesome, but not required :). I'll learn how to use whatever is currently available.

FWIW, read/write speed is not a concern at all, as this would be used simply to be able to persist my interactively defined Forth words to the board and read them back them in when the board starts up.

Thanks for your consideration, Chris

As others have said, littlefs is now incorporated in the latest beta. In the beta, the file abstraction layer has been rewritten to provide things like access to flash memory systems.

If you are not wedded to the Teensy 4.0, consider the Teensy 4.1. It has 2 pads underneath the Teensy that allow you to add extra memory. Typically one pad might be used to add a PSRAM chip and the other might be used to solder in a non-volatile chip. In addition of course, you have a micro-SD card that you could mount.

One place you might look for inspiration is the Circuit Python code. Adafruit provides support for the Teensy 4.0 and Teensy 4.1, and they use the extra flash memory to hold files. Before you look at it, make sure you are comfortable with the source license they use and make sure your code is licensed appropriately for including their code.

Finally, if the space is real small, consider using the EEPROM library. On the Teensy 4.0 and 4.1, EEPROM is simulated and uses the flash memory. The 4.0 provides 1,080 bytes, and the 4.1 provides 4,284 bytes.
 
Back
Top