I am trying to use FreeRTOS and the FatFS library (inside the TivaWare third_party). However I keep getting a FR_DISK_ERR when i try to use f_write.
The function I am using is like this: basically it will pen the file and then try to write to it. I do not execute another task in between and the initTivaForSDC() reconfigures to pins. If I run a directory list, it lists all the files available, this suggests that it is still talking to the SD card.
void placeInQueue(VehicleData value, FileStruct* fStruct, char* name) { TCHAR message[SD_MESSAGE_LENGTH]; // 30 UINT bw; initTivaForSDC(); if (fStruct->fileInstruction == FILE_CREATE) { if (! fStruct->fileOpen) { iFResult = f_open(&g_sFileObject, fStruct->fileName, FA_WRITE | FA_OPEN_ALWAYS); fStruct->fileOpen = true; if(iFResult != FR_OK) { UARTprintf("Error Opening file: %s\nError: %s\n", fStruct->fileName, StringFromFResult(iFResult)); } else { UARTprintf("Successfully opened %s\n", fStruct->fileName); } usnprintf(message, SD_MESSAGE_LENGTH, "%u,%u,%u\n", 0, 1000, 50); } else { // Things went ok usnprintf(message, SD_MESSAGE_LENGTH, "%u,%u,%u,%u,%u\n", value.timeStamp, value.speed, value.odom, value.forAccel, value.latAccel); } UARTprintf("Attempting to write %s\t", message); iFResult = f_write(&g_sFileObject, message, SD_MESSAGE_LENGTH, &bw); if(iFResult != FR_OK) { UARTprintf("Wrote: %u\tError writing to file: %s\n", bw, StringFromFResult(iFResult)); } else { UARTprintf("Wrote:\t%s\n", message); } iFResult = f_sync(&g_sFileObject); if(iFResult != FR_OK) { UARTprintf("Error syncing to file: %s\n", StringFromFResult(iFResult)); } else { UARTprintf("Synced:\t%s\n", fStruct->fileName); } } else if (fStruct->fileInstruction == FILE_CLOSE) { iFResult = f_close(&g_sFileObject); if(iFResult != FR_OK) { UARTprintf("Error Stopping write to file: %s\nError: %s\n", fStruct->fileName, StringFromFResult(iFResult)); } else { UARTprintf("Successfully Stopped %s\n", fStruct->fileName); } } if(xQueueSendToFront(g_pDataQueue, &value, 0) != pdPASS) { char errorString[10]; usnprintf(errorString, 10, "xQS %s", name); // // Error. The queue should never be full. If so print the // error message on UART and wait for ever. // UARTprintf("%s Queue full. This should never happen.\n", name); errorScreen(errorString); } }
And the following is printed:
STARTING to Write to file: 1000-kg_500-mm_0.txt Successfully opened 1000-kg_500-mm_0.txt Attempting to write 0,1000,50 Wrote: 0 Error writing to file: FR_DISK_ERR
Synced: 1000-kg_500-mm_0.txt
Any tips would be greatly appreciated!