用JLINK进行RAM调试时,程序中NVIC初始化后程序就会卡死,注释掉“NVIC_Init(&NVIC_InitStructure);”就可以正常运行,求大神帮看
这里附上main.c的程序/*Include---------------------------*/
#include"stm32f10x_lib.h" //包含所有的头文件
#include<stdio.h>
//----------------函数声明--------------------
void Delay_MS(u16 dly);
void RCC_Configuration(void);
void GPIO_Configuration(void);
//void EXTI_Configuration(void);
void NVIC_Configuration(void);
//void USART3_Configuration(void);
/*******************************************************************************
* Function Name : main
* Description : Main program.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
debug();
#endif
//------------初始化------------
RCC_Configuration();
GPIO_Configuration();
// EXTI_Configuration();
NVIC_Configuration();
// USART3_Configuration();
while(1)
{
GPIO_SetBits(GPIOA, GPIO_Pin_1); //置位LED
Delay_MS(2000);
GPIO_ResetBits(GPIOA, GPIO_Pin_1); //复位LED
Delay_MS(2000);
GPIO_SetBits(GPIOA, GPIO_Pin_4);
Delay_MS(2000);
GPIO_ResetBits(GPIOA, GPIO_Pin_4);
Delay_MS(2000);
}
}
/*******************************************************************************
* Function Name : Delay_Ms
* Description : delay 1 ms.
* Input : dly (ms)
* Output : None
* Return : None
*******************************************************************************/
void Delay_MS(u16 dly)
{
u16 i,j;
for(i=0;i<dly;i++)
for(j=1000;j>0;j--);
}
/*******************************************************************************
* Function Name : RCC_Configuration
* Description : Configures the different system clocks.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void RCC_Configuration(void)
{
//----------使用外部RC晶振-----------
RCC_DeInit(); //初始化为缺省值
RCC_HSEConfig(RCC_HSE_ON); //使能外部的高速时钟
while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET); //等待外部高速时钟使能就绪
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); //Enable Prefetch Buffer
FLASH_SetLatency(FLASH_Latency_2); //Flash 2 wait state
RCC_HCLKConfig(RCC_SYSCLK_Div1); //HCLK = SYSCLK
RCC_PCLK2Config(RCC_HCLK_Div1); //PCLK2 = HCLK
RCC_PCLK1Config(RCC_HCLK_Div2); //PCLK1 = HCLK/2
RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9); //PLLCLK = 8MHZ * 9 =72MHZ
RCC_PLLCmd(ENABLE); //Enable PLLCLK
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); //Wait till PLLCLK is ready
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //Select PLL as system clock
while(RCC_GetSYSCLKSource()!=0x08); //Wait till PLL is used as system clock source
//---------打开相应外设时钟--------------------
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); //使能APB2外设的GPIOA的时钟
//RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); //使能APB2外设的GPIOA的时钟
}
/*******************************************************************************
* Function Name : GPIO_Configuration
* Description : 初始化GPIO外设
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //声明一个结构体变量
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_1; //选择PC.10(TXD) 和 PC.11
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //管脚频率为50MHZ
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //输出模式为复用推挽输出
GPIO_Init(GPIOA,&GPIO_InitStructure); //初始化GPIOC寄存器
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //选择PC.10(TXD) 和 PC.11
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //管脚频率为50MHZ
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //输出模式为复用推挽输出
GPIO_Init(GPIOC,&GPIO_InitStructure); //初始化GPIOC寄存器
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; //选择PC.10(TXD) 和 PC.11(RXD)
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //管脚频率为50MHZ
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //输出模式为浮空输入
GPIO_Init(GPIOC,&GPIO_InitStructure); //初始化GPIOA寄存器
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource13);
//EXTI_DeInit(); //将EXIT寄存器重设置为缺省值
EXTI_InitStructure.EXTI_Line = EXTI_Line13;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
//将USART3的TXD和RXD重映射到PC10和pc11
//GPIO_PinRemapConfig(GPIO_PartialRemap_USART3,ENABLE);
}
//void EXTI_Configuration(void)
//{
// EXTI_InitTypeDef EXTI_InitStructure;
// EXTI_DeInit(); //将EXIT寄存器重设置为缺省值
// EXTI_InitStructure.EXTI_Line = EXTI_Line13;
// EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
// EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
// EXTI_InitStructure.EXTI_LineCmd = ENABLE;
// EXTI_Init(&EXTI_InitStructure);
//
// EXTI_ClearITPendingBit(EXTI_Line13);
//}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
NVIC_SetVectorTable(NVIC_VectTab_RAM,0X0);//向量表位于RAM区
#else
NVIC_SetVectorTable(NVIC_VectTab_FLASH,0X0);//向量表位于FLASH区
#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);
}
//void USART3_Configuration(void)
//{
// USART_InitTypeDef U3;
// U3.USART_BaudRate =9600;
// U3.USART_WordLength = USART_WordLength_8b;
// U3.USART_StopBits = USART_StopBits_1;
// U3.USART_Parity = USART_Parity_No;
// U3.USART_Mode = USART_Mode_Rx|USART_Mode_Tx;
// U3.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
//
// USART_Init(USART3, &U3);
//
// USART_Cmd(USART3,ENABLE);
//}
|