控制台串口改成了USART3,初始化USART1之后,进USART1接收中断,就会跳到HardFault_Handler中断里面出不来了,是什么问题。工程是用MounRiver Studio创建的RT-Thread工程
void USART1_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
//UART1中断函数
void USART1_IRQHandler(void)
{
GET_INT_SP();
rt_interrupt_enter();
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
uart0_rev->rev_buf[uart0_rev->rev_len] = USART_ReceiveData(USART1); //接收数据字节
if(++uart0_rev->rev_len>=UART0_MAX_LEN)
{
uart0_rev->rev_len = 0;
}
}
rt_interrupt_leave();
FREE_INT_SP();
}
static int App_Uart0_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //USART1外设时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE); //GPIOA外设时钟
/* USART1 TX-->A.9 RX-->A.10 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_Init(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_Cmd(USART1, ENABLE);
rt_memset(uart0_rev,0,sizeof(struct Uart0_Rev));
return 0;
}
void aliiot_send(u8 *buf, int len )
{
rt_enter_critical();
while (len--)
{
USART_SendData(USART1, *buf);
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET) /* waiting for sending finish */
{
}
buf++;
}
rt_exit_critical();
}
INIT_DEVICE_EXPORT(App_Uart0_Init);