4 Replies Latest reply on Sep 13, 2017 12:16 PM by tikonen

    Unable to get TIM2 interrupt to work

    tikonen

      Hi,

       

      I'm trying to get STM32 TIM2 interrupt to work but some reason they are not enabled and ISR functions do not get called (TIM2_IRQHandler). Is this a known issue in the QEMU? The emulator does give error "PRIGROUP unimplemented" but don't know if it's related?

       

      Running the QEMU with a following command line.

      C:\work\stm32workspace\STM32Test\Debug>"C:\Program Files\GNU ARM Eclipse\QEMU\2.8.0-201612271623-dev\bin\qemu-system-gnuarmeclipse.exe" -verbose -verbose -board STM32F4-Discovery -nographic -d unimp,guest_errors -semihosting --image STM32Test.elf

       

      My code follows, problem is probably here but I'm not able to see it.

       

      
      #include <stdio.h>
      
      
      #include "stm32f4xx.h"
      #include "stm32f4_discovery.h"
      
      
      extern void initialise_monitor_handles(void);
      
      
      
      
      static TIM_HandleTypeDef sTimerInstance = {
          .Instance = TIM2
      };
      
      
      #define timerINTERRUPT_FREQUENCY ( ( unsigned short ) 500 )
      
      
      void InitTimer()
      {
      __HAL_RCC_TIM2_CLK_ENABLE();
      
      
          sTimerInstance.Init.Prescaler = 1;
      sTimerInstance.Init.CounterMode = TIM_COUNTERMODE_UP;
      sTimerInstance.Init.Period = 16000000/ timerINTERRUPT_FREQUENCY;
      sTimerInstance.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
      sTimerInstance.Init.RepetitionCounter = 0;
      HAL_TIM_Base_Init(&sTimerInstance);
      
      
      __HAL_TIM_CLEAR_FLAG(&sTimerInstance, TIM_SR_UIF);
      
      
      HAL_TIM_Base_Start(&sTimerInstance);
      HAL_TIM_Base_Start_IT(&sTimerInstance);
      }
      
      
      // never gets called
      void TIM2_IRQHandler()
      {
      HAL_TIM_IRQHandler(&sTimerInstance);
      }
      
      
      void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
      {
      // TODO
      }
      
      
      int main(void)
      {
      initialise_monitor_handles(); // semihosting, required for prints to work
      
      
      puts("main() - enter");
      
      
      HAL_Init();
      InitTimer();
      HAL_NVIC_SetPriority(TIM2_IRQn, 1, 1);
      HAL_NVIC_EnableIRQ(TIM2_IRQn);
      
      
      // dummy main loop
      for(;;) {
      }
      
      
      return 0;
      }
      

      Thank you!

      • Reply