cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to read file greater than 2K in FatFS ,stm32F103

ch23
Associate II
Posted on August 11, 2014 at 14:18

Hi,

I am reading a file from the SPI Flash with FATFS file system, on STM32F103 platform running FreeRTOS. I can successfully read File of size less the 2048, but if read a file file of size greater than 2048, (As

i

am reading in chunks of 128 bytes) it only reads up to 2048 bytes and f_read returns 'FR_INT_ERR' error when File pointer move to location above 2048 bytes.

Thanking in an anticipation,

CAK

#spi-flash #fatfs #stm32f103
9 REPLIES 9
Posted on August 11, 2014 at 14:56

So perhaps a failure in your diskio.c implementation, or memory allocations (structures/stacks)

Thoroughly test your abstraction layer outside of FatFs

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
ch23
Associate II
Posted on August 12, 2014 at 17:32

Spi-Flash is of 4MB size. I have done raw read/writes. I can success Fully read/write all SPI flash addresses.

Using FatFS, I have created file of more the 100K and when i check file size with f_size for that particular file it gives exact size. But when i start reading i cant read the complete file

In diskio.c file found a issue with get_block_size. It was set 1 which should be 4 in my case as Block Erase Size for spi-flash in 4k and sector size is set 512.  After changing I can now read 4096 bytes reading more then that gives same error 

 'FR_INT_ERR' 

ch23
Associate II
Posted on August 12, 2014 at 18:04

To me it

look

like

issue

is with f_mkfs

(

)

xRes = f_mkfs(0, SFD_FORMAT, 4096 );

Now I can read up to the value given in the f__mkfs allocation unit. I have tried value 32K instead of 4K. I can read up to 32K bytes. But the problem is my file is bigger than 32 K about 130K to 150 K. I have gone FATFS docs I have read the possible value is

betwee

512 to 32K

Can you suggest what should be the allocation unit size when creating

file system

.

I have attached my diskio2flash

.

c file,

ffconfig

.

h file and file for read write test code that may help in understanding my problem.

________________

Attachments :

diskio2flash.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0c2&d=%2Fa%2F0X0000000bbD%2FytWMNM5Jn9aFTLUVfUjRjzOFieG6Bv3Ha6KURSN9u0Y&asPdf=false

FatTestTask.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0XS&d=%2Fa%2F0X0000000bbC%2FH79JApaCALsyn0E66qrnJNtB.8niF0Nzz8asaSE9ZiA&asPdf=false

ffconf.h : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0bx&d=%2Fa%2F0X0000000bbE%2FAfU3d.ughrOQYLA1zbTJAxbiyowXBV5BA_4AEho8Gnw&asPdf=false
stm322399
Senior
Posted on August 12, 2014 at 18:19

There are 8 sectors in your erase block, not 4.

ch23
Associate II
Posted on August 12, 2014 at 19:02

Yes, they are 8 not 4.

But it has no effect either.

stm322399
Senior
Posted on August 12, 2014 at 19:31

4096 should be OK as allocation unit. Pass 0 for automatic AU selection.

There is another way: set sector size to 4096 and AU to 1. I had success with this configuration and SST25 flash.

ch23
Associate II
Posted on August 13, 2014 at 11:14

Yes, 4096 should be enough as

allocation unit

.

I tested by setting AU (allocation unit

)

to '0', in this case I can only read 2048 bytes from file.

I am unable to understand why this AU value is affecting the reading from file. Although my file size is showing that I can write any amount of data, but I am unable to read from file above this allocation unit size, .

 

Is there any other option in FATFS that is associated to this AU which must be set properly when creating

file system

.

stm322399
Senior
Posted on August 13, 2014 at 11:40

Just a guess: there is something wrong in your write function.

If I were you, I'll try to make it bullet proof: for any sector write, read the entire erase block in RAM, update the sector, erase the block and rewrite the updated block.

ch23
Associate II
Posted on August 14, 2014 at 05:43

By setting the Sector Size and Allocation unit both to 4096 bytes, successfully read/write any amount of data.

Thanks everyone.....