STMicroelectronics / STM32CubeF3

STM32Cube MCU Full Package for the STM32F3 series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits))
Other
142 stars 54 forks source link

missing callback call in I2SEx_TxRxDMACplt() if DMA is in circular mode #13

Closed lukasnee closed 3 years ago

lukasnee commented 3 years ago

Problem in: https://github.com/STMicroelectronics/STM32CubeF3/blob/master/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_i2s_ex.c

in function static void I2SEx_TxRxDMACplt(DMA_HandleTypeDef *hdma)

I think this callback logic (theres two copies of it inside the function):

 /* Call user TxRx complete callback */
#if (USE_HAL_I2S_REGISTER_CALLBACKS == 1U)
        hi2s->TxRxCpltCallback(hi2s);
#else
        HAL_I2SEx_TxRxCpltCallback(hi2s);
#endif /* USE_HAL_I2S_REGISTER_CALLBACKS */

is missing outside the scope of:

/* if DMA is configured in DMA_NORMAL mode */
  if (hdma->Init.Mode == DMA_NORMAL) {

 /* ... */

}

I discovered this problem when trying to set up I2S full duplex DMA in circular mode on NUCLEO-F303RE. I found that this callback: void HAL_I2SEx_TxRxHalfCpltCallback(I2S_HandleTypeDef *hi2s) was being called periodically (as expected), but this one: void HAL_I2SEx_TxRxCpltCallback(I2S_HandleTypeDef *hi2s) was not.

This is how i fixed it:

static void I2SEx_TxRxDMACplt(DMA_HandleTypeDef *hdma)
{

   /* ... */

  if (hdma->Init.Mode == DMA_NORMAL)
  {

    /* ... */

  }
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++ START OF FIX
  else if (hdma->Init.Mode == DMA_CIRCULAR)
  {
    /* Call user TxRx complete callback */
#if (USE_HAL_I2S_REGISTER_CALLBACKS == 1U)
    hi2s->TxRxCpltCallback(hi2s);
#else
    HAL_I2SEx_TxRxCpltCallback(hi2s);
#endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
  }
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++ END OF FIX
}

My problem was actually fixed.

ASELSTM commented 3 years ago

Hi @lukasnee,

Thank you for this report. If the issue is systematically reproducible on your side, would you please give us more details on how to reproduce it and if possible share the project so that we can reproduce the same behavior and give you an answer.

With regards,

ASELSTM commented 3 years ago

Hi @lukasnee,

Any update regarding this issue to move this discussion forward?

With regards,

lukasnee commented 3 years ago

I don't understand what is unclear. If you try to use full duplex ("TxRx") I2S in DMA Circular mode, you won't get a dma complete callback as you would expect. On the other hand, half complete callback fires which makes this bug really sneaky. Look at the code, this must have been an overlook. I also found a video where someone else discovered the same issue and there's also a thread in forum

https://youtu.be/lNBrGOk0XzE?t=1383

ASELSTM commented 3 years ago

Hi @lukasnee,

Thank you for this detailed report. Please allow me to close this thread as answer has been posted within the pull request #15.

With regards,