# freertos fat cycle issues

**URL:** <https://forums.freertos.org/t/freertos-fat-cycle-issues/5954>\
**Category:** Kernel\
**Created:** [May 26, 2016, 5:51am UTC](https://forums.freertos.org/t/freertos-fat-cycle-issues/5954 "2016-05-26T05:51:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 26, 2016, 5:51am UTC](https://forums.freertos.org/t/freertos-fat-cycle-issues/5954/1 "2016-05-26T05:51:51Z")

</div>

**[e12](https://sourceforge.net/u/e12/)** wrote on [Thursday, May 26, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/899c6777/#4c61):

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(;😉  
{  
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?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 26, 2016, 5:53am UTC](https://forums.freertos.org/t/freertos-fat-cycle-issues/5954/2 "2016-05-26T05:53:30Z")

</div>

**[e12](https://sourceforge.net/u/e12/)** wrote on [Thursday, May 26, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/899c6777/#6532):

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [May 26, 2016, 8:27am UTC](https://forums.freertos.org/t/freertos-fat-cycle-issues/5954/3 "2016-05-26T08:27:59Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, May 26, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/899c6777/#6532/11e7):

[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](http://www.freertos.org/vtaskdelayuntil.html)

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 30, 2016, 7:22am UTC](https://forums.freertos.org/t/freertos-fat-cycle-issues/5954/4 "2016-05-30T07:22:00Z")

</div>

**[e12](https://sourceforge.net/u/e12/)** wrote on [Monday, May 30, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/899c6777/#6532/11e7/1373):

what is your sdcard?  
Please recommend one

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 30, 2016, 7:22am UTC](https://forums.freertos.org/t/freertos-fat-cycle-issues/5954/5 "2016-05-30T07:22:02Z")

</div>

**[e12](https://sourceforge.net/u/e12/)** wrote on [Monday, May 30, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/899c6777/#6532/11e7/961a):

what is your sdcard?  
Please recommend one

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [May 30, 2016, 8:45am UTC](https://forums.freertos.org/t/freertos-fat-cycle-issues/5954/6 "2016-05-30T08:45:47Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Monday, May 30, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/899c6777/#aabf):

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.

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [May 30, 2016, 10:21am UTC](https://forums.freertos.org/t/freertos-fat-cycle-issues/5954/7 "2016-05-30T10:21:26Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Monday, May 30, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/899c6777/#7a5d):

> 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.

---

<div class="post-metadata">

**Author:** ![tlafleur](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tlafleur](https://forums.freertos.org/u/tlafleur)\
**Post date:** [May 30, 2016, 3:57pm UTC](https://forums.freertos.org/t/freertos-fat-cycle-issues/5954/8 "2016-05-30T15:57:04Z")

</div>

**[tlafleur](https://sourceforge.net/u/tlafleur/)** wrote on [Monday, May 30, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/899c6777/#7a5d/28be):

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.

[SSD endurance myths and legends articles on StorageSearch.com](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](mailto: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](https://sourceforge.net/p/freertos/discussion/382005/thread/899c6777/?limit=25#7a5d)
> 
> Sent from [sourceforge.net](http://sourceforge.net) because you indicated interest in  
> [SourceForge.net: Log In to SourceForge.net](https://sourceforge.net/p/freertos/discussion/382005/)
> 
> To unsubscribe from further messages, please visit  
> [SourceForge.net: Log In to SourceForge.net](https://sourceforge.net/auth/subscriptions/)

–

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

Tom Lafleur

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [May 30, 2016, 6:11pm UTC](https://forums.freertos.org/t/freertos-fat-cycle-issues/5954/9 "2016-05-30T18:11:35Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Monday, May 30, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/899c6777/#44aa):

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.
