如题:IAR+Jlink,SWD方式调试,芯片型号为STM32F101CBT6,仿真运行,执行到函数TIM2_Configuration中的TIM_Cmd(TIM2, ENABLE);就进入到HardFault_Handler,如果复位后重新运行则执行到NVIC_Configuration中的NVIC_Init(&NVIC_InitStructure);就进入到HardFault_Handler,找了好久没有找到原因,请香主帮忙分析,谢谢!
代码:
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); // Configure the NVIC Preemption Priority Bits
//NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
//NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
//NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//NVIC_Init(&NVIC_InitStructure);
//Enable the TIM2 global Interrupt
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//使能EXTI 12通道
//NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
//NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
//NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//NVIC_Init(&NVIC_InitStructure);
}
void TIM2_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 5625;
TIM_TimeBaseStructure.TIM_Prescaler = 64;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_ARRPreloadConfig(TIM2, ENABLE);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM2, ENABLE);
}
另外进入到HardFault_Handler后观察到LR=0xFFFFFFF1 |