cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_HRTIM_WaveformCounterStop_IT delay due to "delai"

KTyte.1
Associate II

Hi. Im using HRTIM and HAL in my project.
To stop Master timer with subsequent interrupt call I use HAL_HRTIM_WaveformCounterStop_IT (it is defined in stm32_hal_legacy.h) and it calls HAL_HRTIM_WaveformCountStop_IT from stm32g4xx_hal_hrtim.c.
Pic.1 shows how long it takes to process this function call, and it is enormous 27.94us.
Yes, I know HAL is kinda slow and for maximum efficiency one should use direct registers call.
I suggest the culprit is delay inserted in this function (variable called "delai").

 

HAL_StatusTypeDef HAL_HRTIM_WaveformCountStop_IT(HRTIM_HandleTypeDef *hhrtim,
                                                 uint32_t Timers)
{
  /* ++ WA */
  __IO uint32_t delai = (uint32_t)(0x17FU);
  /* -- WA */

  uint8_t timer_idx;

  /* Check the parameters */
  assert_param(IS_HRTIM_TIMERID(Timers));

  /* Process Locked */
  __HAL_LOCK(hhrtim);

  hhrtim->State = HAL_HRTIM_STATE_BUSY;

  /* Disable HRTIM interrupts (if required) */
  __HAL_HRTIM_DISABLE_IT(hhrtim, hhrtim->Init.HRTIMInterruptRequests);

  /* Disable master timer related interrupts (if required) */
  if ((Timers & HRTIM_TIMERID_MASTER) != 0U)
  {
    /* Interrupts enable flag must be cleared one by one */
    __HAL_HRTIM_MASTER_DISABLE_IT(hhrtim, hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].InterruptRequests);
  }

  /* Disable timing unit related interrupts (if required) */
  for (timer_idx = HRTIM_TIMERINDEX_TIMER_A ;
       timer_idx < HRTIM_TIMERINDEX_MASTER ;
       timer_idx++)
  {
    if ((Timers & TimerIdxToTimerId[timer_idx]) != 0U)
    {
      __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, timer_idx, hhrtim->TimerParam[timer_idx].InterruptRequests);
    }
  }

  /* ++ WA */
  do { delai--; } while (delai != 0U);
  /* -- WA */

  /* Disable timer(s) counter */
  hhrtim->Instance->sMasterRegs.MCR &= ~(Timers);

  hhrtim->State = HAL_HRTIM_STATE_READY;

  /* Process Unlocked */
  __HAL_UNLOCK(hhrtim);

  return HAL_OK;
}

 

 When I commented line 40 

 

 /* ++ WA */
// do { delai--; } while (delai != 0U);
 /* -- WA */

 

execution time drastically decreased to 3.18us (Pic. 2).
So the question is:
What is the purpose of this delay?
Can I just comment it?
What is "WA" mean in the comments near delai? (workaround?).
I did not find any mentions about it in errata, and I checked that this delay was there since version 1.0.0 of STM32Cube MCU package.Pic.1 HAL_HRTIM_WaveformCountStop_IT call execution time.Pic.1 HAL_HRTIM_WaveformCountStop_IT call execution time.Pic.2 HAL_HRTIM_WaveformCountStop_IT call execution time with commented delai cycle..Pic.2 HAL_HRTIM_WaveformCountStop_IT call execution time with commented delai cycle..
 
4 REPLIES 4

@KTyte.1 wrote:
 
What is "WA" means in comments near delai? (workaround?). 

It looks like a marker to identify all modifications associated with a Patch - could also be the author's initials.

 


@KTyte.1 wrote:
I checked that this delay was there since version 1.0.0 of STM32Cube MCU package.

You mean STM32CubeG4 ?

Probably means it was inherited from whatever that package was based on...


@Andrew Neil wrote:


You mean STM32CubeG4 ?


Yes, I meant STM32CubeG4 package.