Hi Cezar,
Thank you for the reply and the information on the speeds.
OK so because I can't improve the write speed of small amounts of data I have been trying to find out what leads to the corruption of data I am seeing...
I have created a small function based on the test functions provided to write a certain number of bytes from a buffer to the SD card
int SDCardBuffer1_count = 0;
/* Data buffer for writing */
ALIGNED(4096U)
uint8_t SDCardBuffer1[DATA_BUFFER_SIZE] __attribute__((section(FEATURE_CUSTOM_DATA_SECTION)));
FRESULT WriteBuff_1()
{
/* File object */
FIL fd;
/* File stat object */
FILINFO fst;
/* API result code */
FRESULT status;
static UINT bytesWritten;
UINT bytesToWrite;
status = f_open(&fd, path, (BYTE)(FA_WRITE | FA_OPEN_APPEND));
if(FR_OK == status)
{
bytesToWrite = SDCardBuffer1_count;
bytesWritten = 0U;
//randomizeBuffer((uint8_t *)&g_dataWrite[0], bytesToWrite);
status = f_write(&fd,SDCardBuffer1 , bytesToWrite, &bytesWritten);
if(FR_OK == status)
{
status = f_sync(&fd);
}
if(FR_OK == status)
{
status = f_stat(path, &fst);
}
if(FR_OK == status)
{
printFileInfo(path, &fst);
status = f_close(&fd);
}
else
{
(void)f_close(&fd);
}
}
return status;
}
This function seems to work ok however I am seeing corruption of the data on the sd card with NULL characters added into the text files.

I used the debugger to see if there was any null data in my buffer but there isn't so i really don't know where it comes from. i have run some tests and have found the conditions that lead to the corruption... it seems as though if I only write small (< ~1000 characters) amounts of data to the SD file it works fine, if I only write large(> ~1000 chars) amounts of data its also ok...but if I do a mixture of writes some more than aprox 1000 characters and some below aprox 1000 characters then i will see corruption of the data (the boundary isn't 1024 though I checked that). the code below shows this.(the databuffers are prepopulated)
so this would work...
Mount();
for(i = 100;i < 1000;i = i + 10){
SDCardBuffer1_count = i;
timebefore = RTC_DRV_GetTicks(0);
(void)WriteBuff_1();
timenow = RTC_DRV_GetTicks(0);
}
UNMount();
and this would work...
Mount();
for(i = 2000;i < 40000;i = i + 100){
SDCardBuffer1_count = i;
timebefore = RTC_DRV_GetTicks(0);
(void)WriteBuff_1();
timenow = RTC_DRV_GetTicks(0);
}
UNMount();
but this would lead to corruption...
Mount();
for(i = 500;i < 1500;i = i + 10){
SDCardBuffer1_count = i;
timebefore = RTC_DRV_GetTicks(0);
(void)WriteBuff_1();
timenow = RTC_DRV_GetTicks(0);
}
UNMount();
Edit: I have just noticed when I was tidying up my code to put on here that there seems to be a time factor(how long waited between calls to WriteBuff_1()) that effects if there will or will not be corruption to the file.
If anyone could help me in figuring this out id be very grateful.
Many thanks
Liam