Skip to main content
JRS
Associate III
November 9, 2021
Solved

ST32H7 SPI DMA Callback not called in non-circular Mode

  • November 9, 2021
  • 2 replies
  • 2575 views

Hi,

I have seen this some time ago in another thread:

https://community.st.com/s/question/0D53W000005771OSAQ/stm32h7xx-spi-tx-with-dma-halspitxcpltcallback-is-called-only-if-dma-is-configured-in-circular-mode

I am kind of repeating the questions in that last thread, because I did not see any final answer.

Still in FW H7 v1.9.0 the problem persists. In stm32h7xx_hal_spi.c using the DMA the TxCpltCallback is never called if not in circular mode.

static void SPI_DMATransmitCplt(DMA_HandleTypeDef *hdma)
{
 SPI_HandleTypeDef *hspi = (SPI_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
 
 if (hspi->State != HAL_SPI_STATE_ABORT)
 {
 if (hspi->hdmatx->Init.Mode == DMA_CIRCULAR)
 {
#if (USE_HAL_SPI_REGISTER_CALLBACKS == 1UL)
 hspi->TxCpltCallback(hspi);
#else
 HAL_SPI_TxCpltCallback(hspi);
#endif /* USE_HAL_SPI_REGISTER_CALLBACKS */
 }
 else
 {
 /* Enable EOT interrupt */
 __HAL_SPI_ENABLE_IT(hspi, SPI_IT_EOT);
 }
 }
}

What is the reason for hiding that TxCpltCallback?

This topic has been closed for replies.
Best answer by TDK

It should be triggered at the end of transfer in HAL_SPI_IRQHandler, here:

https://github.com/STMicroelectronics/STM32CubeH7/blob/ccb11556044540590ca6e45056e6b65cdca2deb2/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c#L2982

It is called when the EOT bit is set:

https://github.com/STMicroelectronics/STM32CubeH7/blob/ccb11556044540590ca6e45056e6b65cdca2deb2/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c#L2893

If that's not happening, you could look into why EOT isn't being set or isn't being handled properly.

2 replies

TDK
TDKBest answer
November 9, 2021

It should be triggered at the end of transfer in HAL_SPI_IRQHandler, here:

https://github.com/STMicroelectronics/STM32CubeH7/blob/ccb11556044540590ca6e45056e6b65cdca2deb2/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c#L2982

It is called when the EOT bit is set:

https://github.com/STMicroelectronics/STM32CubeH7/blob/ccb11556044540590ca6e45056e6b65cdca2deb2/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c#L2893

If that's not happening, you could look into why EOT isn't being set or isn't being handled properly.

"If you feel a post has answered your question, please click ""Accept as Solution""."
JRS
JRSAuthor
Associate III
November 10, 2021

Hi TDK,

you are right about the EOT IRQ calling the callback. I concede, that if I enable the global SPI Interrupt (in addition to the DMA Interrupt) the callback is called and works well.

But why is it not called directly from the DMA Interrupt? It seems like a waste of cycles to call another interrupt from there, although there is some flag handling and the closing of the transfer that would otherwise be needed in the dma irq.

Anyway to summarize: For callback to work in DMA the DMA Stream interrupt and also the SPI global Interrupt is needed.