0
\$\begingroup\$

I setup TIM3 on my STM32F411 using the following code:

void Enable_Timer_3()
{
    __TIM3_CLK_ENABLE();
    TIM3->PSC = 8399;               // Prescaler value, 8400 - 1, 84 MhZ / 8400 = 10000 Hz
    TIM3->EGR = TIM_EGR_UG;         // Update prescaler
    TIM3->ARR = 9999;               // Period, 10000-1, 1 second period
    TIM3->DIER = TIM_DIER_UIE;      // Enable interrupts for this timer
    TIM3->CR1 = TIM_CR1_CEN;        // Enable this timer
}

The timer counts just fine - inspecting the TIM3->CNT register shows it correctly counting from 0 to 9999 in the span of a second. But my interrupt handler is not called.

My handler:

void TIM3_IRQHandler(void)
{
    TIM3->SR = 0;
    HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
}

It is set as the TIM3 interrupt in the interrupt vector:

  .word     TIM3_IRQHandler  /* TIM3 */   

Did I do something wrong?

\$\endgroup\$
  • 1
    \$\begingroup\$ I do not know much about coding.. but I cannot see the place where you are enabling the interrupts \$\endgroup\$ – User323693 Jan 29 at 4:04
  • \$\begingroup\$ @User323693 thank you, that was it. I forgot to enable the TIM3-Interrupt. If you want, you can post your comment as an answer and I'll accept it. \$\endgroup\$ – Katharina Jan 29 at 4:09
3
\$\begingroup\$

I do not know much about coding.. but I cannot see the place where you are enabling the interrupts..

The interrupt for timer TIM3 can be enabled by adding the following line to the timer setup function:

NVIC_EnableIRQ(TIM3_IRQn);
|improve this answer|||||
\$\endgroup\$
  • 1
    \$\begingroup\$ @Katharina Ah yes, the ARM core specific stuff that is never in the ST's manual. Interrupt priority is set similarly and won't be in ST's manual. \$\endgroup\$ – DKNguyen Jan 29 at 14:26
  • \$\begingroup\$ @DKNguyen Yea, it's quite annoying. I worked through the I2C section of the ST manual prior to this and it didn't mention this at all. \$\endgroup\$ – Katharina Jan 30 at 23:31
  • \$\begingroup\$ @Katharina If you think it has to do with the core and not the peripherals, don't expect to find it in the ST manual. Look at the materials from ARM. For example, the SysTick timer. \$\endgroup\$ – DKNguyen Jan 30 at 23:32
  • \$\begingroup\$ @DKNguyen Yea, this is all new to me still. I come from an AVR background. \$\endgroup\$ – Katharina Jan 30 at 23:35
  • \$\begingroup\$ @Katharina Not sure if AVR has this issue, but in ARM, if you are in C++ and the libraries in your compiler are in C, the interrupt handler in your code names will not be associated with the pre-designated interrupt handler names unless you use "extern C" to preserve the function name, due to C++ name function name mangling. It will just appear as if none of your interrupts are running with no errors (because they aren't, because they can't be found so the dummy interrupt handler runs while your interrupt handlers just sit there as functions that aren't called). \$\endgroup\$ – DKNguyen Jan 30 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.