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


FATFS and FreeRTOS again

Posted by Sergio Sider on March 11, 2009
Hi All,

Does anyone ported successfully Elm Chan's FATFS to FreeRTOS ?

The author suggested using mutexes for using fatfs from more than 1 thread, but where do I really have to use them?

a) just to protect the hardware dependent calls ?
b) to protect every call to the fatfs api ?

I searched this forum and found some messages from a person that apparently used mutexes in a higher level (just freeing the resource when the file was closed).

Any ideas?
Sergio P. Sider

RE: FATFS and FreeRTOS again

Posted by Prithwee on March 11, 2009

Yes, FATFS need a mutex if your are accesing the filesytem from different Tasks.

FATFS is Global declaration for the entire Filesystem.

So, you must protect the all calls with mutex.
(f_open,f_read,f_readdir,f_lseek,f_write,f_close... etc)

Meanwhile give a try to access without mutex for 2 tasks,
it should welcome an error FR_INVALID_OBJECT or FR_NO_FILESYSTEM.

Please post your results.


RE: FATFS and FreeRTOS again

Posted by Sergio Sider on March 11, 2009

Hi Prithwee,

Thanks for your response,

I wraped all fatfs api calls (f_open, f_read....) with a mutex ,

I wraped all access to SPI port (that I plan to use for another device) in the hardware dependant calls (disk_initialize,disk_read, etc) with another mutex.

To mimic the timer interrupt routines (disk_timerproc), I created a task to fire at 10ms intervals:

void vFATFSTimerTask (void* pvParameters)
portTickType xLastWakeTime = xTaskGetTickCount();
for (;;)
vTaskDelayUntil (&xLastWakeTime, (10 / portTICK_RATE_MS)); //each 10ms

I did not have time to test it from multiple threads, but as soon I do, I will post my results...

Thanks again!
Sergio P. Sider

RE: FATFS and FreeRTOS again

Posted by Sergio Sider on March 11, 2009

Hi again,

Just to post my results.

I made a test, 2 task writing to different files , 1000 lines of text, one writing 1 line each 100ms and the other at 200ms, both tasks started at the same time, but obviously file1 took half long to complete.

Both files writen successfully, no aparent problem.


RE: FATFS and FreeRTOS again

Posted by Prithwee on March 12, 2009

Hi Sergio,


Just a Note:
If you have planed to use SPI for other device and not using FATFS in multiple tasks simaltanously, then its sufficient to lock/unlock just SPI calls.

Aceesing the FATFS calls for writing to a SDcard from multiple tasks with mutex, decreses the card read/write speed in realtime.

Example:Writing a PCM Audio data @44.1Khz is not possible in realtime with SPI interface.


[ 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