#include "stm32f10x_lib.h"
EXTI_InitTypeDef EXTI_InitStructure;
ErrorStatus HSEStartUpStatus;
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
int main(void)
{
RCC_Configuration();
NVIC_Configuration();//到处就进入中断服务程序,然后死机!!!
GPIO_Configuration();
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource15);
EXTI_InitStructure.EXTI_Line = EXTI_Line15;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
while (1)
{
}
}
void RCC_Configuration(void)
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
FLASH_SetLatency(FLASH_Latency_2);
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
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_1);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);//单步运行到此,会进入中断服务程序,然后就不出来了
}
现象总结:
1:软件中不能开 EXTI15_10_IRQChannel中断,否则死机(如上面程序中铁贴出的一样),
2:如果想用 EXTI15_10_IRQChannel中断,必须使先用串口擦除FLASH,不然不管是用MDK还是IAR都会出现死机,
3:死机现象 程序在配置中断时(如程序中所示)就会进入中断。
4:如果我不开 EXTI15_10_IRQChannel中断,整个芯片运行正常,在IAR和MDK下都很正常,
5: 正常的意思是不需要用事先串口擦除FLASH,直接在IAR或者MDK下载可正常工作
我选择ram运行,过程及现象如下:
1:断电配置boot
2:配置程序
3:上电下载 正常
4:第一次运行 正常
5:软件复位
6:第二次运行(或者单步运行) 死机
7: 断电
8:重复3~7
和flash运行不一样的地方,
flash运行:程序执行配置中断后,立刻进入中断服务程序,然后就出来了,
ram运行:程序执行配置中断后,程序跑飞
在21ic上问了好几天,也没人知道
用户193211 2009-7-21 17:06
ilove314_323192455 2008-6-22 11:06