我试图为 Timer2 溢出中断创建一个中断服务程序,如下所示:
#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");
}
}
我正在使用 IAR Embedded Workbench for ARM v8.22.2(最新版本)。但是 TIM2_IRQHandler 永远不会被调用——它甚至可以从 C 编译器中得到优化(所以在 dissasembly 中不再有 TIM2_IRQHandler 了)。
那么如何在 IAR Workbench 中正确定义 ISR?