STM32L051C8T6 HAL DMA IDLE串口不定长接收遇到的问题
DMA中断,串口不定长接收,无法连续发送第二个printf
写2个printf只能发送第一个,第二个需要延时5S左右才能发送。
无法把串口状态置为READY
初始化的时候 Main.c
要使能串口中断 DMA
``
HAL_NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
HAL_UART_Receive_DMA(&huart1, UsartType1.usartDMA_rxBuf, USART1_MAX_RECV_LEN);
__HAL_UART_ENABLE_IT(&huart1, UART_IT_IDLE);
``
HAL 串口库.c
添加串口发送完毕状态
/**
- @brief DMA UART transmit process complete callback.
- @param hdma DMA handle.
- @retval None
*/
static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma)
{
UART_HandleTypeDef *huart = (UART_HandleTypeDef *)(hdma->Parent);
/* DMA Normal mode */
if (HAL_IS_BIT_CLR(hdma->Instance->CCR, DMA_CCR_CIRC))
{
huart->TxXferCount = 0U;
/* Disable the DMA transfer for transmit request by resetting the DMAT bit
in the UART CR3 register */
CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
/* Enable the UART Transmit Complete Interrupt */
SET_BIT(huart->Instance->CR1, USART_CR1_TCIE);
/* Check if a transmit process is ongoing or not */
if(huart->gState == HAL_UART_STATE_BUSY_TX_RX)
{
huart->gState = HAL_UART_STATE_BUSY_RX;
}
else
{
huart->gState = HAL_UART_STATE_READY;
}
}
/* DMA Circular mode */
else
{
if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
/*Call registered Tx complete callback*/
huart->TxCpltCallback(huart);
else
/*Call legacy weak Tx complete callback*/
HAL_UART_TxCpltCallback(huart);
endif /* USE_HAL_UART_REGISTER_CALLBACKS */
}
}