Data reception is locked if data arrives before the STM32 uart reception function is called.
I simulated this in the code example given below. I send a data packet and receive an immediate response from the other device. I am not interested in this response, so I do not call the receive function. But later when I need to receive data, I call the function. But when I send a data from the serial monitor, it does not receive the data. It behaves as if no data is coming.
HAL_UART_Transmit(&huart1, send_packet, 8, 340);
//This is where data is sent to the other device and a response is received.
//In less than 1 second, this answer comes.
HAL_Delay(1000);
HAL_UARTEx_ReceiveToIdle_IT(&huart1, buffer, BUFFER_SIZE);
This has happened on different occasions. For example; I am configuring a BLE module with AT commands. If the setting is successful, it responds back. But since I do not call the uart receive function, the uart locks up.
When I need to read data from the uart in the rest of the software, there is no data reception. It does not give any error.
To avoid this error, I deinit the UART and then init it again. Or I use the uart receive function continuously if there is data to be received.
If you don't call the receive function for data that is received then an overrun will occur.
If you don't want the data then you need to clear the overrun flag yourself before receiving again.
De-init and re-init is clearing the flag for you, but perhaps you can search in the library header for a function that only clears the flag without having to set up all the other registers again.