Can not jump to Timer interrupt function in STM32F4 discoverty

interruptsstm32f4timer

I made a code to call Timer2 interrupt function like this :

timerx->TIMx_PSC    =42000;   // prescaler
timerx->TIMx_ARR    =2000;    // counting number
timerx->TIMx_CR1    |=0x90;   // auto reload, count down
timerx->TIMx_DIER   |=0x01;   // enable update interrupt
interruptsx->ISER[0]|= 1<<(TIMER2_INTERRUPT);   // enable timer_interrupt 
TIMER2_INTERRUPT=28   
timerx->TIMx_CR1    |=0x01;   // enable counter  
timerx->TIMx_EGR    =0x01;    // update generation

and

void TIM2_IRQHandler(){
if(timer2->TIMx_SR & 0x1){
gpio_toggle_off(gpio_A,GPIO_Pin_1);
number_display(gpio_D,number0);
}
timer2->TIMx_SR=0x0;
}

The problem is : it doesn't jump to TIM2_IRQHandler(). How can I solve this problem?

Best Answer

The following works (i.e. triggers interrupts) on my STM32F4Discovery board under the Coocox environment using GCC:

#include    "stm32f4xx.h"

int main (void) {
SystemInit();
NVIC->ISER[0] |= 0x10000000;
RCC->APB1ENR |= 1;
TIM2->CR1 = 0x0010;
TIM2->ARR = 0x8000;
TIM2->CR2 = 0;
TIM2->SMCR = 0;
TIM2->DIER = 0x0001;
TIM2->CR1 |= 0x0001;
while (1);
}

void TIM2_IRQHandler (void) {
TIM2->SR &= 0xfffe;
}

I'm pretty sure that the reason is that I don't actually start the timer (set bit 0 of TIM2->CR1) until after everything else is configured.