初级会员

- 积分
- 70
- 金钱
- 70
- 注册时间
- 2018-9-25
- 在线时间
- 13 小时
|
1金钱
之前抄袭了原子哥例子中的串口1例子,后来发现中断后没有进入void USART1_IRQHandler(void)方法,而是进入了void __attribute__ ((section(".after_vectors"))) Default_Handler(void)方法。
我单步跟踪后发现在vectors_stm32f10x.c中有定义void __attribute__((weak))Default_Handler(void);方法和void __attribute__ ((weak, alias ("Default_Handler")))USART1_IRQHandler(void);方法。
其中的注释为:
// Forward declaration of the specific IRQ handlers. These are aliased
// to the Default_Handler, which is a 'forever' loop. When the application
// defines a handler (with the same name), this will automatically take
// precedence over these weak definitions
可是我自己定义的void USART1_IRQHandler(void)并没有覆盖掉之前使用weak声明的原方法。而是继续调用了声明为别名的Default_Handler(void)方法。
我尝试将void __attribute__ ((weak, alias ("Default_Handler")))USART1_IRQHandler(void);中的定义去掉了它的别名定义void __attribute__ ((weak))USART1_IRQHandler(void);后,
发现进入的方法变为了
void __attribute__ ((section(".after_vectors"),weak,used))
HardFault_Handler_C (ExceptionStackFrame* frame __attribute__((unused)),
uint32_t lr __attribute__((unused)))
那么,我应该怎么改才能让中断后的执行方法转到实际上我需要使用的void USART1_IRQHandler(void)呢?
|
最佳答案
查看完整内容[请看2#楼]
通过反复确认,发现因为vectors_stm32f10x.c是个C定义,而我自己是在一个CPP中定义的void USART1_IRQHandler(void)方法,因此无法覆盖掉weak定义的方法,在我的CPP中用extern "C"对方法进行声明,中断的响应成功进入我需要的中断方法,问题解决
|