cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L496RGT SDMMC DMA FATFS

lorant124
Associate III

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

0 REPLIES 0