Quality RTOS & Embedded Software

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




Loading

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?
Thanks,
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.

Regards,
Prithwee.


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 (;;)
{
disk_timerproc();
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.

Regards,
Sergio



RE: FATFS and FreeRTOS again

Posted by Prithwee on March 12, 2009

Hi Sergio,

Congratulations.

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.

Regards,
Prithwee.


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




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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