Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non-aligned pointer to read/write buffer #10

Open
SomeMaker opened this issue Nov 27, 2022 · 1 comment
Open

non-aligned pointer to read/write buffer #10

SomeMaker opened this issue Nov 27, 2022 · 1 comment

Comments

@SomeMaker
Copy link

The read/write driver sometimes passes an unaligned reference, which causes DMA to write data at an offset.
In FS_FAT_FileRd function if reading from other than the beginning of sector is required:

if (sec_cur_pos != 0u) {
        FSVol_RdLockedEx
...
p_dest_08 += size_rd; //the pointer may not be aligned!
...
 while (size_rem > 0u) //and if a whole sector should be read next
...
FSVol_RdLockedEx( p_file->VolPtr, /* Rd full sec's.         */
                             (void *)p_dest_08 //then we transmit non-aligned address for reading

If we read/write sectors using DMA then data will be read at an offset.

I worked around it this way: in SD card driver I check if the address is aligned, if it is - pass it to DMA as is, otherwise - use a temporary buffer of one section size. then I just copy data from it to my non-aligned buffer

The same thing happens when you write

This may not be a file system problem but a driver problem.
And maybe you have a better solution

@forg0ne
Copy link
Member

forg0ne commented Jan 3, 2023

Your workaround is how we resolve this as well.
Your BSP should have a properly aligned buffer for use when the FS driver passes a misaligned pointer.
The buffer size should be the sector size multiplied by an integer, BLK_CNT_MAX, which you define.
You should also return BLK_CNT_MAX from the FSDev_SD_Card_BSP_GetBlkCntMax() function in your BSP, so that the FS limits the number of blocks it will read at any one time to what your aligned buffer can hold.
If the pointer from the FS driver is alread aligned you can simply have the DMA read directly into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants