2025-02-27 7:02 AM - edited 2025-02-27 7:07 AM
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 */
2025-02-27 7:11 AM
@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...
2025-02-27 7:14 AM - edited 2025-02-27 7:15 AM
@Andrew Neil wrote:You mean STM32CubeG4 ?
Yes, I meant STM32CubeG4 package.
2025-02-27 7:17 AM
2025-02-27 7:26 AM