1、 使用CUBEMX 配置自动生成代码:
- /DMA 接收地址设置/
`HAL_UART_Receive_DMA(&huart1,Uart1RxBuf,BUFFER_SIZE);
/*开启串口1IDLE中断*/
__HAL_UART_ENABLE_IT(&huart1,UART_IT_IDLE);
/**
* @brief This function handles USART1 global interrupt.
*/
void USART1_IRQHandler(void)
{
/* USER CODE BEGIN USART1_IRQn 0 */
uint32_t temp;
if(__HAL_UART_GET_FLAG(&huart1, UART_FLAG_IDLE) != RESET)
{
__HAL_UART_CLEAR_IDLEFLAG(&huart1);
HAL_UART_DMAStop(&huart1);
temp = hdma_usart1_rx.Instance->CNDTR;
rx_len = BUFFER_SIZE - temp;
recv_end_flag = 1;
}
/* USER CODE END USART1_IRQn 0 */
HAL_UART_IRQHandler(&huart1);
/* USER CODE BEGIN USART1_IRQn 1 */
/* USER CODE END USART1_IRQn 1 */
}