代码是社区里面找的类似拷贝过来的,看着没毛病的样子,
接收几次之后,就出现HARDFAULT
void USART2_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void USART2_IRQHandler(void)
{
uint16_t Count = 0;
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //中断产生
{
USART_ClearITPendingBit(USART2,USART_IT_RXNE);
}
if(USART_GetITStatus(USART2, USART_IT_IDLE) != RESET)
{
USART2->STATR;
USART2->DATAR;
rx_int_flag2 = 1;
/* 获取剩余 DMA缓存大小 */
Count = DMA_GetCurrDataCounter(DMA1_Channel6);
//本帧数据长度 = DMA缓存的大小 - 剩余 DMA缓存大小
rx_recvLen2 = 1024 - Count;
/* DMA接收复位 */
DMA_Cmd(DMA1_Channel6,DISABLE);
DMA_SetCurrDataCounter(DMA1_Channel6,1024);
DMA_Cmd(DMA1_Channel6,ENABLE);
}
}
/* 线程2入口 */
static void thread2_entry(void *param)
{
uint16_t len = 0;
rt_kprintf("%s22\r\n",__func__);
for(;;)
{
if(rx_int_flag2)
{
rx_int_flag2 = 0;
rt_kprintf("receiveLen = %d\r\n",len);
}
rt_thread_mdelay(2);
}
}