UART TimeOut Issue

tazdevil72
Posts: 1
Joined: Tue Mar 18, 2025 7:00 am

UART TimeOut Issue

Postby tazdevil72 » Tue Mar 18, 2025 9:00 am

Hi,

I'm developing some UART code for latest ESP32C5 using dev/v5.5.0.
I'm working with uarts at 115k2, 8, no parity, 1 stop bit, hw flowcontrol disable, and default clock.
Since we can receive different size frames (from 6 to 2048 bytes) and we have also different header bytes we have applied an strategy to use uart_set_rx_timeout for catching the frames, put this frames in a buffer and analyze them out of the uart event callback
Timeout has been set to 3 ms.
excerpt of even callback implementation:
for (;;)
{
//Waiting for UART event.
if (xQueueReceive(uartlp_queue, (void *)&event_lp, (TickType_t)portMAX_DELAY))
{
bzero(ucTempData_lp, UART_LP_RD_BUFF_SIZE);

switch (event_lp.type)
{
case UART_DATA: //Event of UART receving data
{
static uint8_t ucFrameBuffer[UART_LP_RD_BUFF_SIZE];
static uint16_t ucFrameLength = 0;
int16_t siNumBytesRead = uart_read_bytes(LP_UART_NUM_0, ucTempData_lp, event_lp.size, portMAX_DELAY);

// Accumulate data in the frame buffer
if (siNumBytesRead > 0)
{
if (ucFrameLength + siNumBytesRead <= UART_LP_RD_BUFF_SIZE)
{
memcpy(ucFrameBuffer + ucFrameLength, ucTempData_lp, siNumBytesRead);
ucFrameLength += siNumBytesRead;
}
else
{
// Frame buffer overflow, discarding data
ucFrameLength = 0; // Reset frame length on overflow
}
}

// Check if the event was caused by a timeout, then frame is completed
if (event_lp.timeout_flag)
{
// Send the complete frame of data
BLEDriver_TransmitBuffer(ucFrameBuffer,ucFrameLength);
ucFrameLength = 0; // Reset frame length after processing
}
break;
}
case UART_FIFO_OVF:


As I said, code is running fine for ALMOST all frame sizes (6 to 2048 bytes) but we have detected that if size of received frame is UART_FULL_THRESH_DEFAULT (120) or
LP_UART_FULL_THRESH_DEFAULT (10) the UART_DATA data event is just called once and not when timeout is reached, so that frames are not properly handled.


Could you please take a look at this specific scenario ? Note that I have replicate this in ESP32C6 and ESP32S3 not just only in ESP32c5


Thanks

Who is online

Users browsing this forum: PetalBot and 1 guest