cancel
Showing results for 
Search instead for 
Did you mean: 

ST32H7 SPI DMA Callback not called in non-circular Mode

JRS
Associate III

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?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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".

View solution in original post

2 REPLIES 2
TDK
Guru

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
Associate III

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.