FatFS Demo
FatFS Demo
Contents
1. The Idea
3. The Demo
i. Introduction
ii. The Hardware
iii. System Layers View
iv. How disk I/O works?
v. The FatTest task
4. Download
5. Latest news
The Idea
To integrate the open source project FatFS in the ODeV framework. 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.
NOTE: fore more details about the FatFS API see the project web page:
Projects > FatFS Demo
Main Components
‣ELM - FatFS - version R0.08a.
‣STM3210E-EVAL evaluation board.
‣FreeRTOS.org real time scheduler.
‣OpenOCD On-Chip debug solution for embedded target systems.
‣Eclipse open development platform.
‣Sourcery G++ C/C++ tool chain.
‣Versaloon hardware IF.
The Demo
Introduction
The evaluation board is equipped with 128 Mbit NOR Flash. The demo makes a FAT filesystem (FS) in order to make the FLASH available to the application tasks. The concurrent access to the FAT is managed by the FatFS component itself as described in this application note.
The hardware
The demo uses the hardware resource of the evaluation board as displayed in Fig.1.
Fig. 1 - Hardware resources
The SRAM is used as swap area to implement the disk I/O function required by FatFS as explained below in this page. The LCD is used by the application test task to report some information during the access to the file system.
System Layers View
The system functionalities are logically divided into four layers as showed in Fig. 2.
Fig. 2 - System Layers
Above the hardware the Kernel layer is composed by FreeRTOS and STM32 Library modules. They provide the multi tasking environment and the basic MCU access library.
One step upper there is the Low Level API. This layer contains all modules needed to provide programmatic access to all the hardware but the MCU peripherals. In this case the External Memory Lib module (Ext Mem Lib) provides the API to operate the NOR FLASH and the SRAM connected to the STM32 via FSMC peripheral. Another module in this layer is the HMI Lib, that is part of the Board Support Package (BSP), and it exports the API to operate the LCD and it is not displayed in Fig.2.
The Service Layer contains all modules that export more complex algorithms and (when needed) service tasks. In this case the FAT Interface (FAT IF) implements the disk I/O driver required by the FatFS module.
The Application Layer implements all application task. In this case there is only one task that uses the FS.
NOTE: in this demo both FreeRTOS, STM32 Library and FatFS are Firmware Components that provide the source files to implement some modules of the demo.
The following table shows the files grouped by modules.
How disk I/O works?
The FatFS module needs some low level functions to operate the physical media, that is the NOR FLASH in this demo, as a block device. These functions are defined in the diskio2flash_a.c file. The FLASH chip is composed by 128 block of 128KB size. This is the physical organization of the FLASH. The FatFS module uses a logical organization of 16384 sectors of 1KB size. In this way each physical block of the FLASH is composed by 128 sectors.
When an application task operates on a file or directory, FatFS translates that operation in a set of read and write operations on one ore more sectors. But to write a sector in the FLASH it is needed to erase and write one block (128KB). There is not enough internal RAM in the STM32F103 device to perform this operation. This is why the external SRAM is used. The three steps algorithm that implement this operation is showed in Fig.3.
Fig. 3
The FAT IF module optimizes this algorithm by minimizing the data amount to move from the FLASH to SRAM and vice versa.
The FatTest task
The demo runs only one task that make some operation on the FS like formatting the FS, write and read a file. During each test some information message are displayed in the LCD.
Download
The latest version of the the demo is located in the Download page of the site.
The demo is available for the following host:
‣Windows: wFatFSDemo.psf
To use the demo you need also the FreeRTOS, FatFS and STM32F10x_StdPeriph_Lib components. They are automatically downloaded by the demo .psf file.
Latest news
Copyright © 2011 Stefano Oliveri
All the code is developed for test purpose and it is unsupported. The author assumes no responsibility for any damage caused by improper uses.