Skip to main content
Explorer
April 29, 2025
Solved

HAL_DMA_RegisterCallback with SPI

  • April 29, 2025
  • 3 replies
  • 746 views

Hi,

I'm just struggling with the same problem. I use SPI with DMA non-circular mode and want a callback for receive complete.

I can set the callback function with HAL_DMA_RegisterCallback but in HAL_SPI_TransmitReceive_DMA it will be overwritten:

 /* Set the SPI Tx/Rx DMA Half transfer complete callback */
 hspi->hdmarx->XferHalfCpltCallback = SPI_DMAHalfTransmitReceiveCplt;
 hspi->hdmarx->XferCpltCallback = SPI_DMATransmitReceiveCplt;

Edit: Post moved from original thread How to know the when the DMA transfer done?, to give a chance to be answered. Please precise if you are using U5 as original one.

Best answer by KnarfB

The DMA callbacks are used internall by SPI HAL and should not be changed.

You can override HAL_SPI_TxCpltCallback function and friends, or register your own callback function with HAL_SPI_RegisterCallback.

hth

KnarfB

 

 

3 replies

Technical Moderator
May 2, 2025

Hello @STmine 

Could you provide more details about the issue please. 

What is the MCU you are using? 

 

I can set the callback function with HAL_DMA_RegisterCallback but in HAL_SPI_TransmitReceive_DMA it will be overwritten:

 /* Set the SPI Tx/Rx DMA Half transfer complete callback */
 hspi->hdmarx->XferHalfCpltCallback = SPI_DMAHalfTransmitReceiveCplt;
 hspi->hdmarx->XferCpltCallback = SPI_DMATransmitReceiveCplt;

 


What you want to say by overwritten? How it is overriten?

"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.Saket_Om"
Billy OWEN
ST Employee
May 2, 2025

Hi @STmine 

 

This post has been escalated to the ST Online Support Team for additional assistance.  We'll contact you directly.

 

Regards,

Billy

KnarfB
KnarfBAnswer
Super User
May 2, 2025

The DMA callbacks are used internall by SPI HAL and should not be changed.

You can override HAL_SPI_TxCpltCallback function and friends, or register your own callback function with HAL_SPI_RegisterCallback.

hth

KnarfB