Search code examples
arminterruptiarisrstm32f1

IAR Embedded Workbench for ARM - How to define Interrupt Service Routine?


I tried to create an Interrupt Service Routine for the Timer2 Overflow Interrupt like this:

#include "stm32f10x.h"

/* IRQ definitions in CMSIS startup_stm32f10x */


void TIM2_IRQHandler (void) {
  TIM2->SR &=~TIM_SR_UIF;
  GPIOC->ODR |= GPIO_ODR_ODR13;
}

void timer2_setup() {
  RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;

  TIM2->PSC = 0;
  TIM2->ARR = 900;
  TIM2->DIER |= TIM_DIER_UIE;

  NVIC_EnableIRQ(TIM2_IRQn);

  TIM2->CR1 = TIM_CR1_CEN;
}

int main()
{
  /* Set System-Clock as high as possible */
  RCC->CFGR = RCC_CFGR_SW_1 | RCC_CFGR_PLLMULL_3 | RCC_CFGR_PLLMULL_2 | RCC_CFGR_PLLMULL_0;
  RCC->CR = RCC_CR_HSION | RCC_CR_PLLON;

  /* Set GPIO C13 as High-Speed PushPull output */
  RCC->APB2ENR = RCC_APB2ENR_IOPCEN;
  GPIOC->CRH |= GPIO_CRH_MODE13_1 | GPIO_CRH_MODE13_0;

  __enable_irq();  
  timer2_setup();
  GPIOC->ODR &=~GPIO_ODR_ODR13;
  while(1){
    asm volatile ("nop");
  }
}

I am using IAR Embedded Workbench for ARM v8.22.2 (so latest version). But TIM2_IRQHandler is never called - it even gets optimized from the C-compiler (so in dissasembly there is no TIM2_IRQHandler anymore).

So how do I define an ISR properly inside IAR Workbench?


Solution

  • Please check startup_stm32f10XXX.s file. This file must contain all interrupt vector definitions for MCU.