Data reception is locked if data arrives before the STM32 UART reception function is called.
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.