# Can't read files bigger than 2Kb using FreeRTOS+FAT

**URL:** <https://forums.freertos.org/t/cant-read-files-bigger-than-2kb-using-freertos-fat/7546>\
**Category:** Kernel\
**Created:** [November 26, 2018, 10:24am UTC](https://forums.freertos.org/t/cant-read-files-bigger-than-2kb-using-freertos-fat/7546 "2018-11-26T10:24:46Z")\
**Posts on this page:** 3\
**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:** [November 26, 2018, 10:24am UTC](https://forums.freertos.org/t/cant-read-files-bigger-than-2kb-using-freertos-fat/7546/1 "2018-11-26T10:24:46Z")

</div>

**[spabla](https://sourceforge.net/u/spabla/)** wrote on [Monday, November 26, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/2ba4664cbf/#dcfa):

I am using FreeRTOS v 10.1.0 , in addition I have downloaded FreeRTOS+FAT from the labs area (160919 release)

I am using an Altera Cyclone V evaluation board and have succesfully ran FreeRTOS projects on the board using the Demo project and the available port for my board as the basis for my own applications.

I have also succesfully mounted a partion on my SD Card and read files from the SD Card and also written files to the SD Card.

My problems begin when I try to read a file bigger than 2K. I am using the following ff\_fread command to read from a file I have previous opened and I know to be 5777 bytes long:

ff\_fread( &byteBuffer[0],1,5777, pxSourceFile );

What I find is the byte buffer is repetedly populated with the same 2048 bytes, up to the maximum of 5777 bytes. So byteBuffer[0] to byteBuffer[2047] are what I expect but then this data is repeated.

I have also tried to read the data in 512 byte chunks and also in 2048 byte chunks in case the issue was related to a sector boundary (512 byte sector) or a cluster boundary (4 sectors per cluster).

My suspicion is that the issue is in FreeRTOS + Fat as opposed to the Altera code for interfacing with the SD Card. This is becasue when I put a break point in the following function I see that the FreeRTOS+Fat api does actually seem to jump back to the first sector after it has successfully read 4 sectors of data. So it would seem that the Altera Api is returning the data requested by FreeRTOS + FAT.

static int32\_t prvReadSd( uint8\_t \*pucDestination,  
uint32\_t ulSectorNumber,  
uint32\_t ulSectorCount,  
FF\_Disk\_t \*pxDisk )  
{  
int32\_t errorCode = alt\_sdmmc\_read(pucDestination,  
ulSectorNumber \* 512,  
ulSectorCount \* 512);  
return errorCode  
}

Any insights anyone can offer into the issues I am having will be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 28, 2018, 4:44pm UTC](https://forums.freertos.org/t/cant-read-files-bigger-than-2kb-using-freertos-fat/7546/2 "2018-11-28T16:44:03Z")

</div>

**[spabla](https://sourceforge.net/u/spabla/)** wrote on [Wednesday, November 28, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/2ba4664cbf/#29d5):

Ok, I have resolved my issue. My apologies for blaming FreeRTOS+FAT, I will explain the issue below just in case others have the same issue.

I had created a 1MB partition on my SD Card which I believed to be Fat16. After trying various things I decided to reformat my sd care using the following command in Linux.

sudo mkdosfs -F 16 /dev/sdc4

linux gave the following warning

WARNING: Not enough clusters for a 16 bit FAT! The filesystem will be  
misinterpreted as having a 12 bit FAT without mount option “fat=16”.

This prompted me to enable Fat12 support in the FreeRTOS+Fat config file and this fixed my issue.

---

<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:** [November 28, 2018, 4:47pm UTC](https://forums.freertos.org/t/cant-read-files-bigger-than-2kb-using-freertos-fat/7546/3 "2018-11-28T16:47:12Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, November 28, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/2ba4664cbf/#29d5/bf5c):

Thanks for taking the timer to report back.
