Skip to main content
Associate III
Solved

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

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

    This topic has been closed for replies.
    Sarra.SBest answer
    ST Employee

    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.

    2 replies

    Sarra.SBest answer
    ST Employee

    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

    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!