STM32L452 + SD + DMA + FATFS + STM32CubeMX v5.0.0: 32-bit alignment check is needed
The functions SD_read() and SD_write() in sd_diskio.c do 32-bit DMA accessed to the SDMMC FIFO. As a result, any buffer passed to these functions must be 32-bit aligned, as otherwise data can be lost or corrupted.
However, it is not enough to pass an aligned buffer to f_write() and f_read(), as there are various scenarios where the buffers passed to SD_write() and SD_read() are still not aligned.
So the latter functions need to check for an unaligned buffer, and take some action to correct this. We found that the simplest fix is to have a local aligned buffer, one sector in size, which can be used for DMA operations, with data transferred between it and the buffer passed to the function.
We've never seen a case where more than one sector is read/written and an unaligned buffer is passed in; it's possible that this scenario is impossible.
Incidentally, this post mentions a scratchpad, which sounds similar to our solution. If this isn't already included in the version of this file for STM32L4, could this be added in the near future?
----
This is the sixth bug report I've filed recently, relating solely to the SD code produced by STM32CubeMX. Only one has had a response from ST, and that was a holding message, with no further update in the 2 months since.
Please could ST provide some reassurance that these bugs are being looked into.
@Imen DAHMEN @Amel NASRI @Maurizio NESSI
