heinbali01 wrote on Tuesday, July 31, 2018:
In my previous post I made a typo. Where I wrote:
ff_fwrite() and ff_fread()
I actually meant the implementation in the driver, often called:
prvFFRead() and prvFFWrite()
I’m sorry if that confused any one.
Ah okay if I understand you correctly I can pass aligned buffer placed in non cacheable region to:
pxParameters->pucCacheMemory = ‘AlignedNonCacheableBuffer of size xIOManagerCacheSize’
and everything should be fine cause +FAT executed read/write operations through this cache buffer?
If the memory that you supply is non-cacheable, it must have an alignment that DMA can work with.
If the memory is cacheable, its alignment must fit both with DMA and the D-CACHE.
And also: when the first block is well-aligned, the subsequent blocks will also have a proper alignment because the block-size is 512 bytes.
Will it be possible to use cached_malloc/free then ? I see that +FAT allocated
some memory for different structures but they are not used with read/write operation directly.
With the exception of
pxFile->pucBuffer ( which you do not use for now ).
Unfortunately I don’t understand first case that you’ve mentioned.
What you mean by “entire aligned sectors” ? You mean writing 4KB of aligned data ?
I mean for instance this kind of access:
__attribute__ ((aligned (32))) uint8_t pucBuffer[ 16 * 512 ];
FF_Read( pxFile, 1, n * 512, pucBuffer );
FF_Write( pxFile, 1, n * 512, pucBuffer );
In these cases, the +FAT caching buffers will be by-passed, and
pucBuffer will be passed directly to the driver functions
ffconfigOPTIMISE_UNALIGNED_ACCESS is set 0 so no problem in this case but I will test in future.
As you can guess, the fastest file i/o is done when you read or write in multiple blocks of 512 bytes. This is also favourable for memory cards: contiguous reads and writes are a lot faster.
ffconfigOPTIMISE_UNALIGNED_ACCESS option is only useful if you plan to read or write in small quantities.
I think that your solution with testing for cached/non-cached buffer operation will do the trick,
I just need confirmation if it safe to use cached_malloc/free in this scenario
In case you have doubts, there is some good testing software in the original +FAT release
It is in the old