控制臺串口改成了USART3,初始化USART1之后,進USART1接收中斷,就會跳到HardFault_Handler中斷里面出不來了,是什么問題。工程是用MounRiver Studio創(chuàng)建的RT-Thread工程
void USART1_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
//UART1中斷函數(shù)
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);? ?//接收數(shù)據(jù)字節(jié)
? ? ? ? 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外設(shè)時鐘
? ? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);? //GPIOA外設(shè)時鐘
? ? /* 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);