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.

    This topic has been closed for replies.
    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?

    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

    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