AnsweredAssumed Answered

TIM2_IRQHandler(void) not working on STM32F407Vg

Question asked by anton.bogdan on Jun 3, 2014
Latest reply on Jun 4, 2014 by Clive One
Hi guys, i encounter some problems using timer interrupts.

I tryied several code examples from the web, but the problem stil occurs...
I am using IAR 6.3 as ide, i cant figure out what is wrong in the interrupt routine, why does not blinks that led3.
The setup is on a discovery f4 board

If i try to declare the void TIM2_IRQHandler as extern "c" void TIM2_IRQHandler(void) the complier returns me some error mesages

Error[Pe040]: expected an identifier
Error[Pe260]: explicit type is missing ("int" assumed)



#include <stm32f4xx.h>
#include <stm32f4xx_i2c.h>
#include <stm32f4xx_i2c.c>
#include "stm32f4xx_gpio.c"
#include "stm32f4xx_rcc.c"
#include "system_stm32f4xx.c"
#include "my_i2c.c"
#include "stm32_ub_lcd_2x16.c"
#define I2Cx I2C1
#include "delay.c"
#include "delay.h"
#include "misc.c"
#include "i2c_com.c" // MPU comunication functions
//#include "MPU6050.c" // MPU functions library
#include "stm32f4xx_tim.h"
#include "stm32f4xx_tim.c"
#include "stm32f4_discovery.h"
#include "stm32f4_discovery.c"
#include "stm32f4xx_it.h"
 
void TIM2_IRQHandler(void)
{
  if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
  {
    TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
  
    /* LED3 toggling */
    STM_EVAL_LEDToggle(LED3);
  }
}
  
int main(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;
    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  
  /* TIM2 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
  
  /* Enable the TIM2 gloabal Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
 // NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
   
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
  /* Initialize LED3 mounted on STM32F0-Discovery */
  STM_EVAL_LEDInit(LED3);
  
  /* Turn on LED3 */
  STM_EVAL_LEDOn(LED3);
  
  /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Prescaler = 42000 - 1; // To KHz
  TIM_TimeBaseStructure.TIM_Period = 1000 - 1; // To Hz
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
  
  /* TIM Interrupts enable */
  TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
  
  /* TIM2 enable counter */
  TIM_Cmd(TIM2, ENABLE);
  
  /* Infinite loop */
  while (1);
}

Outcomes