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




Loading

use fatfs on freertos

Posted by ntaxyz on March 18, 2017

Hi. I would like to use fatfs on freertos (stm32f407) so I write this 2 functions for read and write with mutex. but, it just work first time and after that I got "FRDISKERR", when try to open file. could you please guide me why this code not work more than one time?! ~~~ FATFS SDFatFs;

bool WriteToSDCard(uint8t* FileName,uint8t* Data,uint32t Seek,uint32t ByteToWrite) { while((osMutexWait(SDMutexHandle,0)!=osOK)) { DebuggerSendData("-MSWL-"); osDelay(500); }

FIL MyFile;
uint32_t byteswritten;
char SDPath[4]; bool FinalStatus=false;

while(!FinalStatus) {
if(fmount(&SDFatFs, (TCHAR const*)SDPath, 0) == FROK) { if(fopen(&MyFile,(const TCHAR*) FileName, FAOPENALWAYS | FAWRITE | FAREAD) == FROK) { if(flseek(&MyFile, Seek)==FROK) { if(fwrite(&MyFile, Data, ByteToWrite, (void *)&byteswritten) == FROK) { FinalStatus= true; } } } } fclose(&MyFile); fmount(NULL,(TCHAR const*)SDPath, 0); } osMutexRelease(SDMutexHandle);

return FinalStatus; }

bool ReadFromSDCard(uint8t* FileName,uint8t* Data,uint32t Seek,uint32t ByteToRead) { while((osMutexWait(SDMutexHandle,0)!=osOK)) { DebuggerSendData("-MSRL-"); osDelay(500); }

FIL MyFile;
uint32_t bytesReed;
char SDPath[4]; bool FinalStatus=false;

while(!FinalStatus) { memset(Data,0,ByteToRead); if(fmount(&SDFatFs, (TCHAR const*)SDPath, 0) == FROK) { if(fopen(&MyFile,(const TCHAR*) FileName, FAOPENALWAYS | FAWRITE | FAREAD) == FROK) { if(flseek(&MyFile, Seek)==FROK) { if(fread(&MyFile, Data, ByteToRead, (void *)&bytesReed) == FROK) { FinalStatus= true; } } } } fclose(&MyFile); fmount(NULL,(TCHAR const*)SDPath, 0); } osMutexRelease(SDMutexHandle);

return FinalStatus; } ~~~


use fatfs on freertos

Posted by rtel on March 18, 2017

FatFS support is out of scope for this forum, although there are some examples that use FatFS and demonstrate how to set up FatFS for use in a multi-threaded environment. As I recall there is a configuration setting that crudely wraps all the FatFS functions inside macros that take a mutex at the start of the function and return the mutex at the end of the function.

osMutexWait(SDMutexHandle,0)

I'm afraid we can only support use of the native FreeRTOS API, and not third party abstractions which are unknown to us.

osDelay(500);

I'm not sure why you are using a block time of zero when attempting to take the Mutex, then a separate 500 tick delay if the mutex could not be obtained. If you instead use a block time when attempting to obtain the mutex then you are guaranteed to have the highest priority waiting task obtain the mutex as soon as the mutex becomes available.


[ 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