Alexander Wolf

CubeMX generated Project with DMA & FATFS & SD Card SDMMC1/SDIO

Discussion created by Alexander Wolf on Mar 19, 2018
Latest reply on May 4, 2018 by Alexander Vasiliev

Since SD Card & DMA with CubeMX generated Code doesn’t work out of the box, i want to offer the community my solution.

I coded and tested this for STM32L496 on Disco board. For other uController this workflow should be also succesfull. Attached is a fully working example. After every CubeMX Code Generating changes need to be applied again.

 

  1. Generate Project in Cube MX

  1.1. Select SDMMC & DMA2 request on one single Channel 4. Not two channels for RX TX

           See attached CubeMX example

 

  1. In generated Code:

  2.1 In main.c delete: DMA_HandleTypeDef hdma_sdmmc1;

  2.2 In stm32l4xx_hal_msp.c  go to void HAL_SD_MspInit(SD_HandleTypeDef* hsd) and

             delete  the "SDMMC1 Init" section in this function

             built project should work

  3.

  3.1   in stm32l4xx_it.c

             apply changes in

             void DMA2_Channel4_IRQHandler(void)

             as in this example

             built project should work

  4.

  4.1   in bsp_driver_sd.c

              add static HAL_StatusTypeDef SD_DMAConfigTx(SD_HandleTypeDef *hsd)

              add static HAL_StatusTypeDef SD_DMAConfigRx(SD_HandleTypeDef *hsd)

             apply changes in

             uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks)

              uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks)

              as in this example

              built project should work

Outcomes