Avoiding "Ring buffer overrun!" or "Hardware buffer overrun!"while using FreeRTOS uart example

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Avoiding "Ring buffer overrun!" or "Hardware buffer overrun!"while using FreeRTOS uart example

Jump to solution
2,312 Views
nkp
Contributor II

Hi!

I am trying to use the freertos_uart.c on my frdm-k22 board to read data from my GPS module (GPS module has tx and rx lines that keeps sending out information every second). 

Everytime I run the uart example I get four bytes (specified by recv_buffer[4]) of information after which I get "Ring buffer overrun!" Increasing the size of the recv_buffer doesn't seem to help. 

My question:

-How do I read the information from the ring buffer every time recv_buffer gets full? 

-Will reading the ring buffer solve the "ring buffer overrun" problem?

Thanks!

Labels (1)
0 Kudos
Reply
1 Solution
1,747 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Niyanth

The example uses single instance of UART IP and writes string into, then reads back chars. After every 4B receives, these are sent back on UART.    

This example also showing that if the reading from ring buffer is slower than writing to it, buffer will overflow. To show this situation, data reading is slowed down by 1s delay.

In uart_task

    /* Send data */
    do
    {
        error = UART_RTOS_Receive(&handle, recv_buffer, sizeof(recv_buffer), &n);
        if (error == kStatus_UART_RxHardwareOverrun)
        {
            /* Notify about hardware buffer overrun */
            if (kStatus_Success !=
                UART_RTOS_Send(&handle, (uint8_t *)send_hardware_overrun, strlen(send_hardware_overrun)))
            {
                vTaskSuspend(NULL);
            }
        }
        if (error == kStatus_UART_RxRingBufferOverrun)
        {
            /* Notify about ring buffer overrun */
            if (kStatus_Success != UART_RTOS_Send(&handle, (uint8_t *)send_ring_overrun, strlen(send_ring_overrun)))
            {
                vTaskSuspend(NULL);
            }
        }
        if (n > 0)
        {
            /* send back the received data */
            UART_RTOS_Send(&handle, (uint8_t *)recv_buffer, n);
        }
        vTaskDelay(1000);

    } while (kStatus_Success == error);

 remark this line will solve this issue

//     vTaskDelay(1000);

Regards

Daniel

View solution in original post

0 Kudos
Reply
1 Reply
1,748 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Niyanth

The example uses single instance of UART IP and writes string into, then reads back chars. After every 4B receives, these are sent back on UART.    

This example also showing that if the reading from ring buffer is slower than writing to it, buffer will overflow. To show this situation, data reading is slowed down by 1s delay.

In uart_task

    /* Send data */
    do
    {
        error = UART_RTOS_Receive(&handle, recv_buffer, sizeof(recv_buffer), &n);
        if (error == kStatus_UART_RxHardwareOverrun)
        {
            /* Notify about hardware buffer overrun */
            if (kStatus_Success !=
                UART_RTOS_Send(&handle, (uint8_t *)send_hardware_overrun, strlen(send_hardware_overrun)))
            {
                vTaskSuspend(NULL);
            }
        }
        if (error == kStatus_UART_RxRingBufferOverrun)
        {
            /* Notify about ring buffer overrun */
            if (kStatus_Success != UART_RTOS_Send(&handle, (uint8_t *)send_ring_overrun, strlen(send_ring_overrun)))
            {
                vTaskSuspend(NULL);
            }
        }
        if (n > 0)
        {
            /* send back the received data */
            UART_RTOS_Send(&handle, (uint8_t *)recv_buffer, n);
        }
        vTaskDelay(1000);

    } while (kStatus_Success == error);

 remark this line will solve this issue

//     vTaskDelay(1000);

Regards

Daniel

0 Kudos
Reply