Comparison and Differences Between FatFS and LittleFS

Follow,Star Public Account Number, don’t miss wonderful content

Comparison and Differences Between FatFS and LittleFS

Source: Internet
Editor: strongerHuang

For many IoT devices, having a small and flexible file system is crucial.

There are not many file systems that run on MCUs, and most people should know about the FatFS file system. Today, I will talk about the content of FatFS and LittleFS, as well as some differences between them.

1. File System FatFS

FatFs is a generic file system (FAT/exFAT) module for implementing the FAT file system in small embedded systems.

Website:

http://elm-chan.org/fsw/ff/00index_e.html

The FatFs component is written following ANSI C (C89) and is completely separated from the disk I/O layer, thus it does not depend on the hardware platform. It can be embedded into resource-constrained microcontrollers such as 8051, PIC, AVR, ARM, Z80, RX, etc., without any modifications.

— from Baidu Encyclopedia

Features

a. DOS/Windows compatible FAT/exFAT file system.

b. Platform-independent and easy to port.

c. Very small footprint for program code and working space.

d. Supports various configuration options:

  • Long file names in ANSI/OEM or Unicode.
  • exFAT file system, 64-bit LBA, and GPT can store large amounts of data.
  • Thread safety for RTOS.
  • Multiple volumes (physical drives and partitions).
  • Variable sector size.
  • Multiple code pages, including DBCS.
  • Read-only, optional API, I/O buffers, etc…

Comparison and Differences Between FatFS and LittleFSComparison and Differences Between FatFS and LittleFS

If you use STM32CubeMX, it is very easy to use FatFS; with just a few steps, you can turn STM32 into a USB flash drive.

2. File System LittleFS

Few people know about the LittleFS file system, but most people who have used the Mbed OS system should know about it.

Mbed OS is a free and open-source embedded operating system developed by Arm for Cortex-M series processors, specifically designed for IoT development.

Comparison and Differences Between FatFS and LittleFS

LittleFS is just a part of Mbed, as shown in the block diagram below:

Comparison and Differences Between FatFS and LittleFS

Source code address:

https://github.com/armmbed/mbed-littlefs

LittleFS Features:

  • Small resource usage: IoT devices are limited by ROM and RAM.

  • Power failure recovery capability: requires the file system to maintain consistency and flush data to the underlying storage.

  • Average wear leveling: Generally, storage supports a limited number of erasures per block, so using the entire storage device is crucial for reliability.

Comparison and Differences Between FatFS and LittleFS

The usage is also quite simple; refer to the official example:

#include "LittleFileSystem2.h"
#include "SPIFBlockDevice.h"
// Physical block device, can be any device that supports the BlockDevice API
SPIFBlockDevice bd(PTE2, PTE4, PTE1, PTE5);
// Storage for the littlefs
LittleFileSystem2 fs("fs");
// Entry point
int main() {
    // Mount the filesystem
    int err = fs.mount(&bd);
    if (err) {
        // Reformat if we can't mount the filesystem,
        // this should only happen on the first boot
        LittleFileSystem2::format(&bd);
        fs.mount(&bd);
    }
    // Read the boot count
    uint32_t boot_count = 0;
    FILE *f = fopen("/fs/boot_count", "r+");
    if (!f) {
        // Create the file if it doesn't exist
        f = fopen("/fs/boot_count", "w+");
    }
    fread(&boot_count, sizeof(boot_count), 1, f);
    // Update the boot count
    boot_count += 1;
    rewind(f);
    fwrite(&boot_count, sizeof(boot_count), 1, f);
    // Remember that storage may not be updated until the file
    // is closed successfully
    fclose(f);
    // Release any resources we were using
    fs.unmount();
    // Print the boot count
    printf("boot_count: %ld\n", boot_count);
}

3. File System Comparison

Every product has its value, and file systems are no exception; each has its advantages and disadvantages. Below are some simple points listing their differences.

1. Resource RAM / ROM Size

LittleFS is a high-integrity embedded file system in Mbed OS, optimized for use with limited RAM and ROM MCUs.

Comparison and Differences Between FatFS and LittleFS

LittleFS uses 13K ROM and less than 4K RAM, significantly less than FAT.

2. Power Failure Recovery Capability

LittleFS has strong copy-on-write guarantees, and the storage on the disk is always kept in a valid state, making it suitable for systems that may experience random power failures.

3. Wear Leveling

Most storage chips used in embedded devices support a limited number of erasures per sector, and without leveling, the lifespan of embedded devices may be affected.

Reference source:

https://os.mbed.com/blog/entry/littlefs-high-integrity-embedded-fs/
Disclaimer: This article is sourced from the internet, and copyright belongs to the original author. If there are any copyright issues, please contact me for removal.
‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧  END  ‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧
Recommended reading:

Selected summary | Directory | Search
Why do CPU pipelines improve code execution efficiency?
How to identify counterfeit chips?

Follow the WeChat public account 'strongerHuang', reply '1024' to see more content, reply 'join group' to join the technical exchange group as per the rules.

Long press to follow the public account included in the image.

Leave a Comment