UART_Start_Receive_IT error when using hardware flow control
Hello,
I ran into an issue when testing a UART application on a STM32C562RE in loopback mode with RTS and CTS enabled. The app does the following:
1. Start receiving 1 character at a time by using HAL_UART_Receive_IT.
2. Send a string
3. After the received character is printed out I issue another call HAL_UART_Receive_IT.
Everything works fine; the app prints out the string I sent.
I wanted to make sure the hardware flow control was running correctly so I placed a HAL_Delay(1) after I print out the character received and before I issue a new call to HAL_UART_Receive_IT. This should stop the transmitter due to the CTS -> 1 (no more room in the Rx buffer) and it should restart it after I issue the HAL_UART_Receive_IT CTS -> 0 due to available room in the Rx buffer; and, it does. All the characters are received as expected however HAL_UART_Receive_IT returns HAL_ERROR. Everything seems normal except the error returned by HAL_UART_Receive_IT.
I debugged the code and it fails in UART_Start_Receive_IT:
if (huart->rx_state != HAL_UART_RX_STATE_ACTIVE)
{
huart->p_rx_isr = NULL;
return HAL_ERROR;
}The rx_state is HAL_UART_RX_STATE_IDLE and therefore the check above fails.
I also enabled 'Get last error' for UART in MX2 and the last_reception_error_codes is 0.
I cannot figure out why HAL_UART_Receive_IT returns an error.
I appreciate the help,
Gil