修改后内容如下:
stm32fl0xx_it.c
#define RECV_BUFFER_SIZE 20
uint8_t uart_dma_recv_buff[RECV_BUFFER_SIZE] = {0};
uint8_t uart_dma_recv_buff_bak[RECV_BUFFER_SIZE] = {0}
void USART1_IRQHandler(void)
{
/* USER CODE BEGIN USART1_IRQn 0 */
/* USER CODE END USART1_IRQn 0 */
HAL_UART_IRQHandler(&huart1);
/* USER CODE BEGIN USART1_IRQn 1 */
if(RESET != __HAL_UART_GET_FLAG(&huart1,UART_FLAG_IDLE))//Check whether the specified UART flag is set or not.
{
__HAL_UART_CLEAR_IDLEFLAG(&huart1);//Clear the UART IDLE pending flag.(Otherwise it will continue to interrupt)
// HAL_UART_DMAStop(&huart1);
/*关闭接收的DMA*/
ret_Value = HAL_IS_BIT_SET(huart1.Instance->CR3, USART_CR3_DMAR);
if ((huart1.RxState == HAL_UART_STATE_BUSY_RX) && ret_Value)
{
CLEAR_BIT(huart1.Instance->CR3, USART_CR3_DMAR);
/* Abort the UART DMA Rx stream */
if (huart1.hdmarx != NULL)
{
HAL_DMA_Abort(huart1.hdmarx);
}
CLEAR_BIT(huart1.Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
CLEAR_BIT(huart1.Instance->CR3, USART_CR3_EIE);
/* At end of Rx process, restore huart->RxState to Ready */
huart1.RxState = HAL_UART_STATE_READY;
}
/*******************/
Uart_recv_len = RECV_BUFFER_SIZE - (__HAL_DMA_GET_COUNTER(&hdma_usart1_rx));//获取接收数据的长度
Uart_recv_flag = 1;
memset(uart_dma_recv_buff_bak,0,RECV_BUFFER_SIZE);
memcpy(uart_dma_recv_buff_bak,uart_dma_recv_buff,RECV_BUFFER_SIZE);
memset(uart_dma_recv_buff,0,RECV_BUFFER_SIZE);
__HAL_UART_DISABLE_IT(&huart1, UART_IT_IDLE);//关闭空闲中断
}
|