如题,维护一个程序,发现中断优先级设置存在明显的错误,而且这几个中断都在正常使用中
void BOARD_NVIC_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); //设置中断矢量表,加载FLASH的位置
/* 2 bit for pre-emption priority, 2 bits for subpriority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置优先级分组
/*定时器中断*/
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; //通道设置为串口1中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //中断占先等级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //中断响应优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //打开中断
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; //通道设置为串口2中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //中断占先等级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //中断响应优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //打开中断
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;//通道设置为串口3中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 10; //中断占先等级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //中断响应优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //打开中断
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;//通道设置为串口4中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 10; //中断占先等级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //中断响应优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //打开中断
NVIC_Init(&NVIC_InitStructure);
//DMA发送中断设置 (串口3 发送中断)
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/*外部IO中断*/
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 4;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/*外部IO中断*/
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 4;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
抢占优先级占两位的话,取值应该是0-3,程序中出现了超出预期的取值,我的理解是如果中断号设置错误,存在异常向量表中的数据也应该是错误的,那么程序会不知道从哪里进入中断。但是,很奇葩的是,这个程序运行了一年多,非常稳定(代码中这几个中断都在使用),怀疑是按默认的中断标号来进入的,应该怎么排查
|