Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


FreeRTOS and Filesystem integration

Posted by Peter on August 16, 2009
Hi Folks,
i was wondering how to integrate a Filesystem within FreeRTOS. The question is, does the filesystem needs its own task where it runs in or is it allowed to run outside of any tasks and is it still safe then, to call the FS functions from a task?
Probably someone knows a link where a sample implementation or documentation is available?
Kind regards,

RE: FreeRTOS and Filesystem integration

Posted by Marcelo Adrian Lorenzati Sanz on August 17, 2009
Hi Peter, I´ve used the Chan´s FAT implementation for FAT filesystems succesfully with Freertos.
This FAT driver only need the diskio implementation for your device (SD, MMC, NANDFlash etc), so in my case I developed an SD driver with SPI handling.
In my SPI driver I use FreeRTOS, so Chan´s Fat becomes FreeRTOS enabled (thread safe).

You can see the code in this forum (in spanish but the code is english commented).


Also I place it in google code:

With a AT91SAM7S at 47.9 Mhz I get 370Kbytes/sec for read and write files (maybe because I use old MMCs...)


RE: FreeRTOS and Filesystem integration

Posted by Peter on August 17, 2009
Hi Darukur,
thanks for your answer. Iam already using FatFS 0.07c with MMC/SD/SDHC and USB MSD. Now i've wanted to integrate the FatFS with Free RTOS. I've found the following options in ff.h: FS_REENTRANT 1 || 0 and the following macros: ff_req_grant, ff_rel_grant, ff_del_syncobj
/ and ff_cre_syncobj.

My questions are:
Do i have to place the FatFS in one task or do just the tasks call the FatFS functions?
How should th tasks to be organized? Should i use one task for card and filesystem initialization, and if this task completes it should start my two other tasks who want to access the filesystem?

I've hoped, that someone could tell me, how to implement that correctly ;-)

Besides that, I've already had a look to your project: Where do you excatly lock the resource (disk_init, disk_read and disk_write) if you have multi task access? Because you don't use FatFS in reentrant mode enabled.

Regarding your MMC/SD-Card speed: Probably you loose the same time on the SPI than i do with my PIC32MX3xx/MX4xx. The time of processing the received bytes takes nearly the same time than reading a byte. I've even could not optimize that quite well. So the speed on the 80MHz PIC32 is the same than on a 8-Bit SiLabs c8051F340 with 48MHz. I have a raw speed of about 520kB/s.

Kind regards,

RE: FreeRTOS and Filesystem integration

Posted by Peter on August 17, 2009
i've found a documentation about using the syncronization objects in FatFS. Its placed in the file syncobj.c which is located in the sample projects of chan.
Thanks anyway!

RE: FreeRTOS and Filesystem integration

Posted by Marcelo Adrian Lorenzati Sanz on August 17, 2009
Hi Peter, I have to look to that flag you say because I surely may be corrupting something but about your question about where I lock the resource, is in the SPI routines where Freertos is used.
FatFs and the diskIO are not aware of the RTOS handling and it shouldn´t do it anyway.
The serialization is made at SPI level.

RE: FreeRTOS and Filesystem integration

Posted by Prithwee on August 18, 2009
Hi Peter,

if you have implemented the Re-Entrent functionality for FAFS to access it from multiple tasks, then you have the freedom to design your system as you wish!!!!

I have implemented the Disk-Init and FS initilization and Mutex creation before the scheduler startup. i.e in the prvSetupHardware() function of the FreeRTOS. FATFS functions can be kept outside the task so that any task can access the FS whenever required.

Note: If you like to implement the hot-insertion (Auto SD-Card detection), then change the design so that all the Initilization will come under a new task-create and mutex-del/fsclose should be done and a task-delete at the end of card removal.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.1 is available for immediate download. MIT licensed, includes 64-bit RISC-V, NXP Cortex-M33 demo, Nuvoton Cortex-M23 demo & STM32H745 dual core (AMP) demo.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner