有大神调试STM32H7串口DMA接收时出现过“串口DMA接收短时间内频繁收到大量数据后,串口就“挂死”,软重启没用只能断电重启串口才正常”这个问题没?
我测试时发现一旦短时间内给串口灌入大量数据,这个串口收发就没反应了,即能接收数据也不会进中断了,感觉就是串口这个外设挂掉了,一时之间排查不出到底是软件问题还是硬件问题?
以下是UART接收DMA回调函数:
uint16_t uart1_count,uart2_count,uart3_count;
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart->Instance==USART1)//如果是串口1
{
uart1_count= UART_RxBufSize - __HAL_DMA_GET_COUNTER(&UART1DMA_Rx);
if(uart1_count != 0){
UART1DMA_Rx.Lock = HAL_UNLOCKED;
if(huart->pRxBuffPtr < UART_RecvBuf[1])
{
CFifoUint8_InBlock(&UART1_RXcircularBuf.cfifo,UART_RecvBuf[0],uart1_count);
HAL_UART_Receive_DMA(&UART1_Handler,UART_RecvBuf[1],UART_RxBufSize);
}else{
CFifoUint8_InBlock(&UART1_RXcircularBuf.cfifo,UART_RecvBuf[1],uart1_count);
HAL_UART_Receive_DMA(&UART1_Handler,UART_RecvBuf[0],UART_RxBufSize);
}
UART1DMA_Rx.Lock = HAL_LOCKED;
}
}else if(huart->Instance==USART2)//如果是串口2 - wifi
{
uart2_count= Wifi_UART_RxBufSize - __HAL_DMA_GET_COUNTER(&UART2DMA_Rx);
if(uart2_count != 0){
UART2DMA_Rx.Lock = HAL_UNLOCKED;
if(huart->pRxBuffPtr < UART2Wifi_RecvBuf[1])
{
CFifoUint8_InBlock(&UART2WIFI_RXcircularBuf.cfifo,UART2Wifi_RecvBuf[0],uart2_count);
HAL_UART_Receive_DMA(&UART2_Handler,UART2Wifi_RecvBuf[1],Wifi_UART_RxBufSize);
}else{
CFifoUint8_InBlock(&UART2WIFI_RXcircularBuf.cfifo,UART2Wifi_RecvBuf[1],uart2_count);
HAL_UART_Receive_DMA(&UART2_Handler,UART2Wifi_RecvBuf[0],Wifi_UART_RxBufSize);
}
UART2DMA_Rx.Lock = HAL_LOCKED;
}
}else if(huart->Instance==USART3)//如果是串口3 - RS485
{
uart3_count= UART485_RxBufSize - __HAL_DMA_GET_COUNTER(&UART3DMA_Rx);
if(uart3_count != 0){
UART3DMA_Rx.Lock = HAL_UNLOCKED;
if(huart->pRxBuffPtr < UARTRS485_RecvBuf[1])
{
CFifoUint8_InBlock(&UART3RS485_RXcircularBuf.cfifo,UARTRS485_RecvBuf[0],uart3_count);
HAL_UART_Receive_DMA(&UART3_Handler,UARTRS485_RecvBuf[1],UART485_RxBufSize);
}else{
CFifoUint8_InBlock(&UART3RS485_RXcircularBuf.cfifo,UARTRS485_RecvBuf[1],uart3_count);
HAL_UART_Receive_DMA(&UART3_Handler,UARTRS485_RecvBuf[0],UART485_RxBufSize);
}
UART3DMA_Rx.Lock = HAL_LOCKED;
}
}
}
|