FATFS and FreeRTOS again

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

FATFS and FreeRTOS again

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.

FATFS and FreeRTOS again

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

FATFS and FreeRTOS again

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

FATFS and FreeRTOS again

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.