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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
2,234 次查看
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!

标签 (1)
0 项奖励
回复
1 解答
1,669 次查看
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 项奖励
回复
1 回复
1,670 次查看
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 项奖励
回复