2014-08-11 05:18 AM
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, (Asi
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 #stm32f1032014-08-11 05:56 AM
So perhaps a failure in your diskio.c implementation, or memory allocations (structures/stacks)
Thoroughly test your abstraction layer outside of FatFs2014-08-12 08:32 AM
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 fileIn 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'
2014-08-12 09:04 AM
To me it
look
likeissue
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 creatingfile 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=falseFatTestTask.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0XS&d=%2Fa%2F0X0000000bbC%2FH79JApaCALsyn0E66qrnJNtB.8niF0Nzz8asaSE9ZiA&asPdf=falseffconf.h : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0bx&d=%2Fa%2F0X0000000bbE%2FAfU3d.ughrOQYLA1zbTJAxbiyowXBV5BA_4AEho8Gnw&asPdf=false2014-08-12 09:19 AM
There are 8 sectors in your erase block, not 4.
2014-08-12 10:02 AM
Yes, they are 8 not 4.
But it has no effect either.2014-08-12 10:31 AM
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.2014-08-13 02:14 AM
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 creatingfile system
.2014-08-13 02:40 AM
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.2014-08-13 08:43 PM
By setting the Sector Size and Allocation unit both to 4096 bytes, successfully read/write any amount of data.
Thanks everyone.....