freertos fat cycle issues

e12 wrote on Thursday, May 26, 2016:

I raise this question during use freertos fat.
The development environment using iar compiler and MCU is using the cortex-m4.
I use the hal library and the contents of FreeRTOS FAT Config.h are as follows:

#define BUS_4BITS 1
#define SDIO_USES_DMA 1

I generated only one task, SDcard write, which write 400byte with 50hz
the task is as follows:

void SDCARD_WRITE_Task(void * pvParameters)
{
uint32_t PreviousWakeTime = 0;

SDcard_Init();
SDcard_SetFileName(“FDR”,"/FDR");

for(;:wink:
{
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_6,GPIO_PIN_SET); //pin high
PreviousWakeTime = osKernelSysTick();
SDcard_Write(ucFileName, SDCARD_Buffer, sizeof(SDCARD_Buffer)); //wirte 400byte
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_6,GPIO_PIN_RESET); // pin low
vTaskDelayUntil(&PreviousWakeTime, 20/portTICK_PERIOD_MS );
}
}

PG6, the pin is high at start, will be low state at the end of the cycle to check the processing time
SDcard Write the contents of the function is as follows:

void SDcard_Write(uint8_t * filename, uint8_t *buf, uint16_t size)
{
FF_FILE *pxFile;
int32_t lItemsWritten;
static int32_t cnt = 0;

pxFile = ff_fopen( (char const*)filename, "a" );        // open the file

    if ((pxFile) != 0){SDCARD_STATUS.SD_IsFileOpened = SD_FILEOPENED;}

memset( buf, 0, size);
snprintf( (char*)(buf + 5), (size-5), "FDR_%020d", cnt);
    cnt++;

*((buf + 0)) = 'S';
*((buf + (size-3))) = 'E';
*((buf + (size-2))) = '\r';
*((buf + (size-1))) = '\n';

lItemsWritten = ff_fwrite( buf, size, 1, pxFile );      // write 400 byte
    SDCARD_STATUS.SD_FileWrittenSize = lItemsWritten*400;

ff_fclose( pxFile );
    
    SDCARD_STATUS.SD_FileAffordSize = SDcard_Capacity_MB(pxDisk);  // check SDcard Capacity 

}

SDCARD WRITE Task oscilloscope results confirmed cases unexpected time length occurred during the test, I set it up 50hz to write 400byte but, sometime it takes 200~250ms oftenly

even if I change the length of bytes the problem still occurred

Why does this problem happen?

is there any chance I can write 512bytes with 50hz?

or is there any limitation of bytes or frequency for SDcard writing?

e12 wrote on Thursday, May 26, 2016:

rtel wrote on Thursday, May 26, 2016:

[to repeat my reply elsewhere on the web]

It looks like the timing your are measuring is related to the driver
that is performing the actual write to the SD card, so I would suggest
taking timings inside the driver. Also, have you tried different SD
cards - our experience is that the difference in performance between
different manufacturers is very large, to the point where some cards are
almost unusable while others are very fast when subjected to the same tests.

One other unrelated note, PreviousWakeTime should only be initialised
once, before it is used for the first time. See
http://www.freertos.org/vtaskdelayuntil.html

e12 wrote on Monday, May 30, 2016:

what is your sdcard?
Please recommend one

e12 wrote on Monday, May 30, 2016:

what is your sdcard?
Please recommend one

heinbali01 wrote on Monday, May 30, 2016:

About the type of card: you can take any SDHC card. +FAT is not yet prepared for SDXC cards.
There are great differences in speed and difference in durability between cards.
All cards can run in both 1- and 4-bit mode. Some cards showed errors when using 1-bit at higher speeds.

When developing +FAT, many different types (brands) of SDHC cards were tested.

Normally you don’t need the highest class or the highest speed. For me durability would be more important. I would not choose a card in the lowest price range. They may show errors earlier and have a shorter life time.

heinbali01 wrote on Monday, May 30, 2016:

is there any chance I can write 512bytes with 50hz?

I’m not sure if understand your question.

Do you want to write 512 bytes every 20 ms?

Yes but I would gather 8 or 16 sectors first, and then write them in a single call.
If you write 16 sectors, you have like 320 ms between two writes.
And better: make some elactic: reserve 8 sectors for filling and 8 sectors for writing.

Writing to an SD card has a lot of overhead. Writing 16 sectors is relatively much faster than writing a single sector.

tlafleur wrote on Monday, May 30, 2016:

You need to look at the data sheet for the SD device your using or talk
with the manufacture of the SD device, you will find that it has a finite
life of write cycles as is with most NAND memory systems.

I suspect that at 50hz rate you may KILL the SD card in a few weeks or
months…

Lots of good and bad info on the web about using NAND memory and SD cards.

http://www.storagesearch.com/ssdmyths-endurance.html <-- talks about SSD
devices issues

On Mon, May 30, 2016 at 3:21 AM, Hein Tibosch heinbali01@users.sf.net
wrote:

is there any chance I can write 512bytes with 50hz?

I’m not sure if understand your question.

Do you want to write 512 bytes every 20 ms?

Yes but I would gather 8 or 16 sectors first, and then write them in a
single call.
If you write 16 sectors, you have like 320 ms between two writes.
And better: make some elactic: reserve 8 sectors for filling and 8 sectors
for writing.

Writing to an SD card has a lot of overhead. Writing 16 sectors is
relatively much faster than writing a single sector.

freertos fat cycle issues
https://sourceforge.net/p/freertos/discussion/382005/thread/899c6777/?limit=25#7a5d

Sent from sourceforge.net because you indicated interest in
https://sourceforge.net/p/freertos/discussion/382005/

To unsubscribe from further messages, please visit
https://sourceforge.net/auth/subscriptions/

~~ _/) _/) _/) ``` _/) ~~

Tom Lafleur

heinbali01 wrote on Monday, May 30, 2016:

Thanks for the URL!

I suspect that at 50hz rate you may KILL the SD card
in a few weeks or months

It depends on how often the same block gets erased. If you fill your SD-card from the beginning to the end, there is no problem, but yes I would buy a good one.

The FAT gets overwritten more often, but it is located in a more robust area of the flash memory. SD cards are designed to hold a FAT which has frequent updates.

Don’t forget to make the writes as big as possible, like at least 16 KB per write, the more the better.