2024-03-11 03:58 AM - edited 2024-03-11 04:20 AM
Hi Community,
I am working in a freeRTOS environment where one of the threads parses the serial data from the UART. A protocol is defined to decode the hex stream received from another device. HAL_UART_RxCpltCallback is configured to receive one byte at a time and is filled in an array that houses a sufficient amount of data (no overflow). But sometimes a byte is getting missed out which is a mid byte.
To troubleshoot this issue set the RX FIFO threshold to generate an interrupt if the FIFO is full. However, whenever a byte is missed it does not trigger a HAL_UARTEx_RxFifoFullCallback (still figuring out how to get this work no interrupt is being generated even if I set the threshold to UART_RXFIFO_THRESHOLD_1_8).
Core: STM32G491
Clock: 170MHz (HSE + PLL)
Here is the program flow:
uint8_t rx_data;
for (;;)
{
/* This is added for the synchronization to disable ISR being called */
HAL_UART_AbortReceive(&huart1);
/* 1. Check for the stream ending \r\n
* 2. Decode and process the byte stream
* 3. Reset index (index = 0)
*/
/* This is added for the synchronization */
HAL_UART_Receive_IT(&huart1, &rx_data, sizeof(rx_data));
osDelay(1);
}
ISR
void HAL_UART_RxCpltCallback (UART_HandleTypeDef * huart)
{
rx_buffer[index++] = rx_data;
HAL_UART_Receive_IT(&huart1, &rx_data, sizeof(rx_data));
}
2024-03-11 05:59 AM
> HAL_UART_AbortReceive
This shouldn't be called from the main loop. If you abort something already in progress, it makes sense that bytes are being lost.
Also, calling HAL_UART_Receive_IT repeatedly is not proper.
What you should be doing is the following:
2024-03-11 08:01 AM
Hi @TDK, thanks for pointing out misconception.