Skip to main content
Graduate
January 10, 2021
Question

STM32L496RGT SDMMC DMA FATFS

  • January 10, 2021
  • 1 reply
  • 634 views

Hi,

in CubeMX 6.1.1 with FW package 1.16.0. If I choice in SDMMC with DMA template enable and shared DMA channel CubeMX doesn't generate proper code. In BSP_SD_ReadBlocks_DMA and in BSP_SD_WriteBlocks_DMA miss setting for change DMA direction. Solution:

__weak uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks)
{
 uint8_t sd_state = MSD_OK;
 
 __HAL_DMA_DISABLE(hsd1.hdmatx);
 hsd1.hdmatx->Init.Direction = DMA_MEMORY_TO_PERIPH;
 hsd1.hdmatx->Instance->CCR |= (uint32_t)DMA_CCR_DIR;
 
 /* Write block(s) in DMA transfer mode */
 if (HAL_SD_WriteBlocks_DMA(&hsd1, (uint8_t *)pData, WriteAddr, NumOfBlocks) != HAL_OK)
 {
 sd_state = MSD_ERROR;
 }
 
 return sd_state;
}
__weak uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks)
{
 uint8_t sd_state = MSD_OK;
 
 __HAL_DMA_DISABLE(hsd1.hdmatx);
 hsd1.hdmatx->Init.Direction = DMA_MEMORY_TO_PERIPH;
 hsd1.hdmatx->Instance->CCR |= (uint32_t)DMA_CCR_DIR;
 
 /* Write block(s) in DMA transfer mode */
 if (HAL_SD_WriteBlocks_DMA(&hsd1, (uint8_t *)pData, WriteAddr, NumOfBlocks) != HAL_OK)
 {
 sd_state = MSD_ERROR;
 }
 
 return sd_state;
}

please repair it.

Solution first posted superspud9 on reddit.

Thanks

    This topic has been closed for replies.

    1 reply

    Explorer II
    February 14, 2025

    This was (almost) the solution to my problem.Looks like the write code was pasted twice, when you do need a version of the read code to set the direction bit back.

    But it's not hard at all to convert one to the other.