Alternate blocking and interrupt UART reception
Hello, everyone.
I'm working on a project based on an STM32L4 MCU. My project needs to receive some commands asynchronously, to start and stop processing and tune internal parameters. I also need to be able to stream large chunks of data in and out.
I'm using UART5 for this purpose. To handle the asynchronous commands I enabled the interrupt in CubeMX and I user HAL_UART_Receive_IT(). I then use HAL_UART_RxCpltCallback() to execute the commands (this involves interacting with GPIO and SPI) and then call HAL_UART_Receive_IT() again.
This part works pretty well.
In order to receive the large chunks of data, I'm trying to use HAL_UART_Receive() in a blocking mode. Using this approach, however, I am only able to receive the first byte, and the rest is lost. This happens also if I do not ever call HAL_UART_Receive_IT() before.
Do I need to change some configuration before using the blocking mode?
Here my UART configuration.
static void MX_UART5_Init(void)
{
/* USER CODE BEGIN UART5_Init 0 */
/* USER CODE END UART5_Init 0 */
/* USER CODE BEGIN UART5_Init 1 */
/* USER CODE END UART5_Init 1 */
huart5.Instance = UART5;
huart5.Init.BaudRate = 2000000;
huart5.Init.WordLength = UART_WORDLENGTH_8B;
huart5.Init.StopBits = UART_STOPBITS_1;
huart5.Init.Parity = UART_PARITY_NONE;
huart5.Init.Mode = UART_MODE_TX_RX;
huart5.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart5.Init.OverSampling = UART_OVERSAMPLING_16;
huart5.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart5.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart5) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN UART5_Init 2 */
/* USER CODE END UART5_Init 2 */
}