Pi file system


This file system was developed for embedded systems which use NOR flash as storage. It was designed mainly for ARM Cortex processors, but it can be ported to any 16/32-bit processor. The development started as teach-myself project and I released the code in hope that it will be useful for someone else as well.

NOR flash ICs have very low price nowadays (2017) and can be used to store files. But there are few problems to consider when designing a file system as they are not working like magnetic devices (hard drives or floppy disks):

NOR flashes can be programmed (set bits to zero) by pages, but only can be erased (set bits to one) in a larger quantity, which are mostly called block in the datasheets. One page is usually 256 or 512 bytes, one block consits of 16, 256, 1024, etc. pages. So typical block sizes are 4 KiB, 64 KiB, 256 KiB.

Blocks can be erased  10,000–100,000 times. After that data retention is not guaranteed. Therefore all blocks should be erased uniformly. This method is called wear leveling.

Pifs can be scaled from 4 Mbit (512 KiB), 256 Mbit (32 MiB), theoretically up to 1 Gbit (128 MiB) memory sizes.

The code is not MISRA compatible, but I’ve written MISRA code earlier and I tend to use the rules. So I tried to use ’return’ only at the end of functions, use ’break’ once in ’while’ cycles or not use it at all and call one function from expressions (or not call functions at all from expressions). I didn’t use ’goto’ in the sources of file system, but you may find them in STM32 HAL’s sources.

Features of the pifs

Small memory footprint

Files can be opened for update ("r+", "w+", "a+" modes are supported)

Size of logical page is user-defined

Cache buffer for page (currently only one page is cached)

Directory handling

Dynamic wear-leveling

Static wear-leveling (limited, work-in-progress)

User data can be added for files: permissions, owner IDs, etc.

At the beginning of flash memory reserved blocks can be defined, which are not used by the file system

File names are case-sensitive

Limitations of the pifs

Only one flash chip can be used (one volume is supported)

Memory and file system configuration cannot be changed during run-time

One directory can only store pre-defined number of files or directories

Partial OS support: file system can be used from multiple tasks, but there is only one working directory for all tasks

Incompatible with FAT file system, therefore cannot be used for USB mass storage devices 


Sources, demo projects, documentation can be downloaded from: 


Previous page: iSerTerm
Next page: How-to