I'm using a STM32L461VGTx and am trying to implement the SDMMC peripheral to read and write to a SD card using DMA. I've adapted CubeMX FatFs_uSD_DMA_Standalone example to my project which uses a simpler, custom file system. The problem I'm seeing is this: I can get DMA2 Channel 5 to work but not DMA2 Channel 4. I've set up both DMA channels using CubeMX with the following settings:
- Priority: Low
- DMA Request Settings: Mode: Normal
- DMA Request Settings: Increment Address: Memory checked
- Data Width: Peripheral: Word
- Data Width: Memory: Word
I've tried swapping the DMA channels assigned to SDMMC Rx and Tx, and that doesn't help: it's always DMA2 Channel 4 that does not work regardless of whether it is handling Rx or Tx.
Specifically, I am calling HAL_SD_ReadBlocks_DMA or HAL_SD_WriteBlocks_DMA and waiting in a while loop for the operation to complete. The conditions I'm waiting for are:
- HAL_SD_GetState != HAL_SD_STATE_BUSY
- HAL_SD_GetCardState == HAL_SD_CARD_TRANSFER
- The DMA complete flag is set
- If 1-3 do not happen, then I timeout after 30000 ms.
Using the debugger, I see that the DMA2 Channel 4 while loop always times out and 1-3 HAL_SD_STATE_BUSY, HAL_SD_CARD_RECEIVING, and the flag is not set, respectively. DMA2 Channel 2 works correctly in that 1-3 are HAL_SD_STATE_READY, HAL_SD_CARD_TRANSFER, and the flag is set.
I also used an oscilloscope to probe the SDCLK and SDDA0 lines. When DMA2 Channel 5 is used, I see SDCLK toggling and SDDA0 transmitting or receiving. When DMA2 Channel 4 is used, SDCLK is held high and SDDA0 remains low.
What is happening here? Why does DMA2 Channel 4 not work while DMA2 Channel 5 works for the same setup? I would like to use DMA for both the SDMMC Rx and Tx.