cancel
Showing results for 
Search instead for 
Did you mean: 

DMA stay in busy state when using HAL_I2C_Slave_Receive_DMA

ANauz.1
Senior II

Hello,

I'm working on 2 NUCLEO-F767ZI Demo Board.

I'm using STM32CubeMX with last firmware package to generate the code and STM32CubeIDE to modify it and debug it.

One of the board is used as an I2C Master, the other as I2C Slave. Every thing work fine when using IT, but I have a problem using DMA on the slave.

In the main, I call HAL_I2C_Slave_Receive_DMA, trying to receive one byte

It work fine. The HAL_I2C_SlaveRxCpltCallback is called. The correct data is received. Then in the call back, I call again HAL_I2C_Slave_Receive_DMA, but this time, the call back is never triggered.

With the debugger, I have seen that, in the HAL_I2C_Slave_Receive_DMA

  • When trying to start the DMA, HAL_DMA_Start_IT, the function always return error code 0x02, ie DMA_BUSY
  • The function return it because the hdma->State is not in Ready State. It is in HAL_DMA_STATE_BUSY

What causes the DMA to be in an busy state? How to avoid it? Is there something special to know to be able to make several Receive_DMA ones after other?

Thank you for your help

Antoine

2 REPLIES 2
ANauz.1
Senior II

Ok, so I have found the cause and a solution, but I am not sure it is the correct way to do it.

The cause:

  • When receiving is done, the I2C IRQ is triggered, I2C_EV_IRQHandler in my case. This function call the HAL_I2C_SlaveRxCpltCallback
  • After that, and only AFTER, the DMA IRQ and therefore "Transfert Complete Interrupt management"

So between the I2C interrupt, and the DMA interrupt, the DMA is still in a BUSY state.

Calling the HAL_I2C_Slave_Receive_DMA at the end of the DMA IRQ make it work as at this moment, the DMA is in an READY mode.

So it make it work, but for me, the I2C_Receive_DMA should only trigger after the DMA complete it transfert and trigger it own IRQ. Otherwise, if the DMA transfert is not complete, data read in I2C IRQ could be corrupted.

Any thing I am missing?

Antoine

ANauz.1
Senior II

Anybody to explain me why when HAL_I2C_SlaveRxCpltCallback is called, the DMA is still in a busy state?

When the RX is complete,the DMA should have finish it work, and should be in a ready state, don't it?

Any ST member to help? Thank you

Antoine