看实现
[C] 纯文本查看 复制代码 /**
\brief Set Interrupt Vector
\details Sets an interrupt vector in SRAM based interrupt vector table.
The interrupt number can be positive to specify a device specific interrupt,
or negative to specify a processor exception.
VTOR must been relocated to SRAM before.
\param [in] IRQn Interrupt number
\param [in] vector Address of interrupt handler function
*/
__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector)
{
uint32_t vectors = (uint32_t )SCB->VTOR;
(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)) = vector;
__DSB();
}
是将修改中断向量表中的值,但默认中断向量表中的值是放在flash中的,不能修改,而且注释也说了修改在SRAM中的中断向量表
1. 根据硬汉老师的,将中断向量表复制一份到RAM中,修改 SCB->VTOR 让它指向这个新的中断向量表
2. 调用 NVIC_SetVector 将新的中断函数的地址取代默认的中断函数
话说,直接直接调用NVIC_SetVector尝试去修改flash的内容没有触发异常吗
|