cancel
Showing results for 
Search instead for 
Did you mean: 

Bug in HAL libraries when using multiple DMA request to different channels of same timer

JMano.2042
Associate

I am having a problem getting two DMA requests started for the same timer. One capture is an IC (input capture) and the other an OC (output compare). See the following code snippet

HAL_StatusTypeDef status;
status = HAL_TIM_OC_Start_DMA(&htim3,TIM_CHANNEL_1,(uint32_t *)TX_buf,TX_buf_len);
printf("Status TX: %u\r\n",status);
status = HAL_TIM_IC_Start_DMA(&htim3,TIM_CHANNEL_2,(uint32_t *)RX_buf,RX_buf_len);
printf("Status RX: %u\r\n",status);

Both the OC and IC are working individually, but when I try to use both, whichever one is started second does not work. The first one always returns status 0 (HAL_OK). The second one always returns status 2 (HAL_BUSY). Both of these HAL API functions contain a check of htim->State. If I comment out the following in the function implementations, both calls work successfully

  if (htim->State == HAL_TIM_STATE_BUSY)
  {
    return HAL_BUSY;
  }
  else if (htim->State == HAL_TIM_STATE_READY)
  {
    if ((pData == NULL) && (Length > 0U))
    {
      return HAL_ERROR;
    }
    else
    {
      htim->State = HAL_TIM_STATE_BUSY;
    }
  }
  else
  {
    /* nothing to do */
  }

I believe the HAL library is incorrectly returning HAL_BUSY when starting the second DMA. My work around of commenting out code in the HAL library seems to work well. I would like a solution that doesn't require modifying the libraries.

I have verified the bug and the work around in "STM32Cube FW_G0 V1.3.0" and "STM32Cube FW_L0 V1.11.2"

1 REPLY 1
Imen.D
ST Employee

Hello @JMano.2042​ ,

Thank you for reporting this issue.

This is raised internally for fix in all impacted series.

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen