Arduino Ecosystem

LittleFS Teensy: Program Flash, QSPI and SPI Storage Options

LittleFS on Teensy offers several storage back ends. Here is how each one behaves and which to pick for your project.

Illustration of a compact development board with program, QSPI and RAM storage tiles

LittleFS is part of Teensyduino, the add-on that brings PJRC's Teensy boards to the Arduino environment. Rather than a single filesystem object, the library offers a family of classes, each backed by a different kind of memory: program flash, external SPI or QSPI chips, FRAM and RAM. Choosing the right one matters, because each behaves differently when you upload new code or remove power. This article explains the options and when to use each.

LittleFS details in this article come from the PaulStoffregen/LittleFS repository, PJRC forum examples and the upstream littlefs project, checked on 23 November 2026. Board support differs between Teensy models, so we note restrictions where the documentation states them.

How LittleFS arrived on Teensy

LittleFS support was added in Teensyduino 1.54, according to the example sketches shipped with the library. The library wraps the upstream littlefs code and describes itself as providing support for RAM disks, NOR and NAND flash chips, and FRAM chips. Because it plugs into the same file abstraction as the SD library, code that reads and writes files on an SD card translates almost directly.

LittleFS on Teensy is used through a simple pattern: declare an object of the class matching your memory, call begin(), then open, read and write files as you would with SD.

The storage classes at a glance

LittleFS for Teensy exposes several classes. The names describe the memory each one uses.

Class Memory Typical use
LittleFS_Program Unused program flash on the microcontroller Small amounts of data with no extra hardware
LittleFS_SPIFlash External SPI NOR flash chip Data logging, larger files
LittleFS_QSPIFlash QSPI NOR flash on the Teensy 4.1 pads Fast, larger storage
LittleFS_QPINAND QSPI NAND flash on the Teensy 4.1 pads Large capacity
LittleFS_RAM RAM, DMAMEM or PSRAM Scratch space that need not survive power loss

LittleFS classes for SPI NAND and FRAM are also referenced in the library's documentation and examples. Check the README in your Teensyduino version for the full, current list.

Program flash: storage without extra hardware

LittleFS can carve a filesystem out of the unused program flash on the Teensy 4.0, Teensy 4.1 and Teensy MicroMod. The README notes this option is only available on those boards. You pass the size you want in bytes, which must be at least 65,536 and smaller than the actual unused program space.

#include <LittleFS.h>
LittleFS_Program myfs;

void setup() {
  Serial.begin(9600);
  if (!myfs.begin(1024 * 1024)) {      // reserve 1 MB
    Serial.println("Error starting program flash disk");
    while (1) {}
  }
}

LittleFS data in program flash has one significant catch. The README warns that uploading new code with Teensy Loader completely wipes the unused program space, erasing all stored files. The filesystem persists across reboots and power cycles, but not across firmware uploads. Treat it as storage for data the device generates in the field, not for assets you upload with the sketch.

External SPI and QSPI flash

LittleFS on an external chip avoids the upload problem entirely, because the flash is separate from program memory. For a chip on the SPI bus, declare a LittleFS_SPIFlash object and pass the chip-select pin to begin(). On the Teensy 4.1, which has pads for an extra memory chip on the underside, the QSPI classes need no arguments at all.

#include <LittleFS.h>
LittleFS_QSPIFlash myfs;      // NOR chip soldered to the Teensy 4.1 pads

void setup() {
  if (!myfs.begin()) {
    Serial.println("Error starting QSPI");
  }
}

LittleFS on QSPI NOR is a good default for data loggers, combining reasonable capacity, fast access and survival across both power cycles and uploads. QSPI NAND offers more capacity, with the trade-offs of NAND flash handled inside the library's NAND support.

RAM disks

LittleFS can also create a filesystem in RAM. On the Teensy 4.1, the README mentions using the optional PSRAM chip, while other boards can use DMAMEM or ordinary RAM. A RAM disk is fast and suffers no wear, but its contents disappear when power is removed. It suits temporary files, such as buffering data before writing it to an SD card in larger chunks.

Writing a simple data logger

LittleFS examples on Teensy follow the familiar Arduino pattern. The snippet below appends a line to a log file once per second.

void loop() {
  File f = myfs.open("datalog.txt", FILE_WRITE);
  if (f) {
    f.printf("%lu,%d\n", millis(), analogRead(A0));
    f.close();                    // commits the data
  } else {
    Serial.println("error opening datalog.txt");
  }
  delay(1000);
}

LittleFS commits the line when the file closes, so a power cut between writes never corrupts the log. For higher sample rates, keep the file open and call flush() periodically instead, balancing safety against flash wear and speed.

Dates and times

LittleFS on Teensy can store file timestamps, but forum discussion shows that correct dates depend on the time being set, for example through the Time library's sync provider. If file dates appear wrong, check that the real-time clock has been set before files are created.

Teensy and PC file access

LittleFS volumes are not readable by a computer over USB as a normal drive, because desktop systems do not understand the format. The Teensy community has developed MTP support so that files can be browsed from a PC while the Teensy runs, which is a convenient way to retrieve logs. Check PJRC's forum and the current Teensyduino release notes for the state of MTP support on your version.

Using LittleFS with PlatformIO

LittleFS from Teensyduino is a bundled library, so the Arduino IDE finds it automatically. Forum threads show PlatformIO users occasionally running into compile errors when they add a separate copy of the library manually. Using the version bundled with the Teensy platform package usually avoids conflicts.

Choosing the right class

LittleFS choices on Teensy can be summarised quickly:

  • Need storage with no extra parts, and accept losing files on upload? Use LittleFS_Program.
  • Need durable logs that survive uploads? Add a NOR chip and use LittleFS_SPIFlash or LittleFS_QSPIFlash.
  • Need large capacity on a Teensy 4.1? Consider LittleFS_QPINAND.
  • Need fast scratch space? Use LittleFS_RAM.

Troubleshooting

Symptom Likely cause Fix
Files gone after uploading a sketch Program flash is erased by Teensy Loader Use external flash for data that must persist
begin() fails with program flash Size below 64 KB or larger than free space Choose a size within the documented limits
QSPI chip not detected Chip not supported or poorly soldered Check the supported chip list and joints
Compile errors in PlatformIO Duplicate LittleFS library Use the bundled Teensyduino version
Wrong file dates Clock not set Configure the time source before writing

Flash wear and logging rates

LittleFS spreads wear across blocks, but flash still has a finite erase life, and a fast logger can approach it sooner than you might expect. Estimate how many bytes you write per day, divide by the filesystem size to find how many times the whole area is rewritten, and compare that with the endurance in your flash chip's datasheet. If the margin is thin, buffer more data in RAM before each write, compress records, or move high-frequency data to a RAM disk and save only summaries to flash. These steps cost little and can extend the life of a deployed logger considerably.

Copying data off the device

LittleFS files on a Teensy can be retrieved in several ways besides MTP. A sketch can print a file over the USB serial port on request, which a small script on the computer saves to disk. Alternatively, copy files to an SD card through the shared file interface and remove the card. For field devices, building a simple serial command that lists and dumps files is a worthwhile investment early in a project.

Choosing and validating storage

Start with the lifetime of the information you intend to save. Temporary samples used only during one session may fit in RAM, while calibration values and user settings need persistent storage. A growing log also needs enough capacity and a plan for retrieving or removing old records. Estimate the expected write rate and the period for which the data must remain available.

Check the exact Teensy board and storage hardware before selecting a filesystem class. Program flash, an external device and RAM have different capacities and different behaviour during firmware uploads or power loss. Confirm the behaviour on the board you ship instead of assuming that all models and upload methods preserve the same region.

Build a simple diagnostic sketch that mounts the selected storage, writes a known value, closes the file and reads it back after a restart. Report mount and write errors over the serial console. For external flash, also test the wiring and device selection before investigating filesystem settings. A successful mount alone does not prove that the entire capacity is usable.

For a logger, decide how often to flush and what the application should do when space runs low. Frequent commits reduce the amount of recent data at risk after a reset but add work to the storage device. Test with the actual sampling rate and power supply, then check that the retrieval method can read the files you created. Keep a separate backup of any calibration or settings that would be difficult to replace.

Frequently Asked Questions

Which Teensy boards support LittleFS_Program?

LittleFS_Program works on the Teensy 4.0, Teensy 4.1 and Teensy MicroMod, according to the library README.

Why did my files disappear after uploading new code?

LittleFS_Program stores files in unused program flash, which Teensy Loader wipes on every upload. Use an external flash chip if files must survive.

Is LittleFS on Teensy compatible with the SD library?

LittleFS for Teensy follows the same file interface as the SD library, so most file-handling code works with either.

Can I use LittleFS on a Teensy 3.x?

LittleFS can be used on Teensy 3.x boards with external storage such as SPI flash, and forum testers have run it on a Teensy 3.5. Program flash storage, however, is limited to the Teensy 4.x family and MicroMod.

How large can a QSPI filesystem be?

LittleFS capacity on QSPI depends entirely on the chip you solder to the Teensy 4.1 pads; check the library's list of supported parts.

How do I get log files off a Teensy?

LittleFS files can be retrieved over MTP where supported, printed over USB serial to a script on the computer, or copied to an SD card.

Does LittleFS on Teensy support directories?

LittleFS supports real directories on every Teensy storage class, so you can organise logs by date or sensor with mkdir() and list them by opening a directory and iterating its entries, just as with the SD library.

Conclusion

LittleFS on Teensy is unusually flexible, offering a storage class for nearly every kind of memory the boards can reach. The key decision is persistence: program flash survives power loss but not uploads, external flash survives both, and RAM survives neither. Pick the class that matches your data, close or flush files regularly, and Teensy logging becomes both quick and robust. For more on the shared Arduino file patterns, read LittleFS Arduino.

Keep reading

More LittleFS articles