我试图为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?
答案 0 :(得分:1)
请检查startup_stm32f10 XXX .s文件。该文件必须包含MCU的所有中断向量定义。