Skip to main content
Associate III
May 6, 2024
Solved

How to enable global interrupt for TIM3 (in PWM mode)

  • May 6, 2024
  • 1 reply
  • 2163 views

Hi,

 

I want to enable the global interrupt for TIM3 so that I can recognize when it becimes active (it raises the pin).

I've added:

if(htim_base->Instance==TIM3)
{
/* Peripheral clock enable */
__HAL_RCC_TIM3_CLK_ENABLE();
/* TIM2 interrupt Init */
HAL_NVIC_SetPriority(TIM3_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(TIM3_IRQn);
}

this to my void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) and can confirm that it gets executed and finally added

void TIM3_IRQHandler(void)
{
HAL_TIM_IRQHandler(&htim3);
}

into stm32f4xx_it.c but I still don't get a TIM3 callback in void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim). What am I missing?
I can see the PWM waveform on my scope but TIM3_IRQHandler() never gets invoked

    Best answer by Sarra.S

    Hello @debug
    Try to enable the update interrupt (UIE) for TIM3, you can enable it by setting the DIER register or by HAL using __HAL_TIM_ENABLE_IT(&htim3, TIM_IT_UPDATE);

    Also, are you starting the timer with HAL_TIM_Base_Start_IT(&htim3) or HAL_TIM_Base_Start(&htim3)? 

    1 reply

    Sarra.SBest answer
    ST Employee
    May 7, 2024

    Hello @debug
    Try to enable the update interrupt (UIE) for TIM3, you can enable it by setting the DIER register or by HAL using __HAL_TIM_ENABLE_IT(&htim3, TIM_IT_UPDATE);

    Also, are you starting the timer with HAL_TIM_Base_Start_IT(&htim3) or HAL_TIM_Base_Start(&htim3)? 

    To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
    debugAuthor
    Associate III
    May 7, 2024

    Yes, calling __HAL_TIM_ENABLE_IT(&htim3, TIM_IT_UPDATE);  did the trick! Thanks!

    I actually have built a custom start function "HAL_TIM_PWM_Start_custom()" to be able to setup timers completely and then just need to call __HAL_TIM_ENABLE(&htim3); to start them (because I want to start two back-to-back with minimal latency).

    Thanks!