Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


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 ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists