Skip to main content
Associate II
July 5, 2026
Question

How to use SDIO + DMA transfer-complete callbacks?

  • July 5, 2026
  • 2 replies
  • 81 views

I’m using SDIO + DMA on an STM32F407 and I need a “transfer complete” callback for SD writes/reads. 

What is the correct way to attach a user callback for SDIO + DMA completion when using the CubeMX‑generated SD/FATFS drivers?

Thank you!

2 replies

ST Technical Moderator
July 6, 2026

Hello ​@omaroski 

The SD driver declares the transfer-complete callbacks as weak functions, so they can be overridden by the user application.
To attach your own handling for SDIO + DMA read/write completion, simply implement these same callback functions in your application code:

void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd)

{

}



void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)

{

}

 

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
MOBEJ
ST Employee
July 6, 2026

Hi @omaroski,

In CubeMX, configure SDIO in 1-bit mode, pull up all SDIO GPIO pins except CLK, add two DMA channels (Rx + Tx), and enable the SDIO global interrupt in the NVIC tab .

Then, redefine these weak HAL callbacks anywhere in your application:

void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd) { }
void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd) { }
void HAL_SD_ErrorCallback (SD_HandleTypeDef *hsd) {  }

In the Tx callback, wait for HAL_SD_GetCardState() == HAL_SD_CARD_TRANSFER before reusing the buffer, as the card may still be internally programming after the DMA transfer completes.

For a complete working reference, check the FatFs_uSD_DMA_RTOS example from the official STM32CubeH7 repository it covers exactly this pattern.

Br

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.