Nios II and FatFs


First some notes from

FatFs is a generic FAT file system module for small embedded systems. The FatFs is written in compliance with ANSI C and completely separated from the disk I/O layer. Therefore it is independent of hardware architecture. It can be incorporated into low cost microcontrollers, such as AVR, 8051, PIC, ARM, Z80, 68k and etc..., without any change.


  • Windows compatible FAT file system.
  • Platform independent. Easy to port.
  • Very small footprint for code and work area.
  • Various configuration options:
    • Multiple volumes (physical drives and partitions).
    • Multiple ANSI/OEM code pages including DBCS.
    • Long file name support in ANSI/OEM or Unicode.
    • RTOS support.
    • Multiple sector size support.
    • Read-only, minimized API, I/O buffer and etc...

(Source: FatFs web page)


For this project an Altera DE1 Board was used:


At the beginning a very simple PIO implementation is used for the SPI interface of the SD Card.
A write transfer rate of about 75 kBytes/sec was reached with a Nios II/e running at 100 MHz
and a 256 MB SD Card.

The RS-232 (115200, 8, N, 1) port of the DE1 is used for the FatFs test monitor.
Here the di, fi, fm, fs and fl command was used:

If you insert a SD Card, the di 0 and fi 0 commands must be used before other file system commands. The fm command was used to format the SD Card. For more information about the test monitor commands use h for help. The following commands was used for the write performance test:

And the following for the read performance:

Remember, a software SPI is used. With a hardware SPI implementation the performance can be increased. Here a write/read performance of more than 900 kBytes/sec was reached.


fatfs_de1_sw_spi_20130811 project (software SPI) for the Altera DE1 board (362 KB)

fatfs_de1_hw_spi_20130817 project (hardware SPI) for the Altera DE1 board (372 KB)