Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: Using the program flash as a file system

  1. #1
    Junior Member
    Join Date
    Apr 2021
    Posts
    4

    Using the program flash as a file system

    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

  2. #2
    Junior Member
    Join Date
    Apr 2021
    Posts
    4
    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.

  3. #3
    Senior Member
    Join Date
    Jul 2014
    Posts
    3,150
    Quote Originally Posted by ChrisCurl View Post
    So ... how would I go about downloading it to include in my Arduino project?
    It's already included in latest Teensyduino (1.54-beta7) (don't worry about beta)

  4. #4
    Junior Member
    Join Date
    Apr 2021
    Posts
    4
    Quote Originally Posted by WMXZ View Post
    It's already included in latest Teensyduino (1.54-beta7) (don't worry about beta)
    Thanks, I have what the Teensy site says is the latest, 1.53.

    https://www.pjrc.com/teensy/td_download.html

    Where do get 1.54?

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,280
    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.

  6. #6
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    4,027
    Quote Originally Posted by ChrisCurl View Post
    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.

  7. #7
    Junior Member
    Join Date
    Apr 2021
    Posts
    4
    Quote Originally Posted by MichaelMeissner View Post
    If you are not wedded to the Teensy 4.0, consider the Teensy 4.1.
    Thanks. I considered the 4.1. I chose the 4.0 because of the lower price.
    Last edited by ChrisCurl; 04-10-2021 at 07:06 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •