STMicroelectronics / stm32-mw-fatfs

Provides the FatFS library part of the STM32Cube MCU Component "middleware" for all STM32xx series.
BSD 3-Clause "New" or "Revised" License
16 stars 8 forks source link

Alignment of buffers in ff.h #5

Open khevessy opened 1 year ago

khevessy commented 1 year ago

I am using FatFS library on STM32H723 MCU with FreeRTOS and DMA. I have encountered the issue mentioned here on the forum. When buffers are not aligned, file access functions like f_read return FR_INT_ERR as cache coherency operations probably don't work as expected. Turning the ENABLE_SCRATCH_BUFFER and ENABLE_SD_DMA_CACHE_MAINTENANCE defines on in sd_diskio.c template also does not help. I do not know if ST is able to fix those issues in the library, but the fix is simple, change

https://github.com/STMicroelectronics/stm32_mw_fatfs/blob/5042a94556d1c4477642fc6b09450725d18ab5e8/src/ff.h#L125

to

BYTE win[_MAX_SS] __attribute__((aligned(32)));

and

https://github.com/STMicroelectronics/stm32_mw_fatfs/blob/5042a94556d1c4477642fc6b09450725d18ab5e8/src/ff.h#L170

to

BYTE buf[_MAX_SS] __attribute__((aligned(32)));.

Then the issue goes away completely.

TOUNSTM commented 9 months ago

Hello @khevessy,

Thank you for your contribution. You are absolutely right about this point. Actually, the point you raised has already been dealt and fixed internally. The fix will be made available in the frame of a future release.

Thank you again for your contribution. We are looking forward to reading from you again.

With regards,

TOUNSTM commented 9 months ago

ST Internal Reference: 133958