This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

FreeRTOS Queues seem broken.

Hi,

The xQueueReceive function in FreeRTOS seems to be broken, when a non-zero timeout is specified.

Example, I'm trying to create and ordered output mechanism for the UART using a task and a FIFO queue:

static void uart_output_task(void * arg)
{
    for (;;)
    {
        struct SerialPortOutput spo;

        printf("uart_output_task: Waiting for data to send, come on.\n");
        
        // Block waiting on data in the queue.
        if (xQueueReceive(m_uart_output_queue, &spo, 100))
        {
            printf("Sending data to UART.\n");
            
            // Send data to UART.
            nrf_drv_uart_tx(spo.output, spo.length);
        }
        else
        {
            printf("uart_output_task: xQueueReceive had nothing to send.\n");
        }
        
        // char test[8] = "test\r\n";
        // nrf_drv_uart_tx(test, 6);
    }
}

If I specify a timeout to the xQueueReceive method (in this case 100 ticks), the task prints the first printf() and stops forever while waiting. I should be seeing that printf() every 100 ticks. If I set the queue receive timeout to 0, it loops appropriately, but this is of course not the behavior I want. This also happens if I set it to portDELAY_MAX.

Thanks, Max

Parents
  • The first thing is - what is the system doing when its apparently stuck in xQueueReceive(). Are other tasks running. If you pause the debugger, what is executing? Are you sure its not in a fault handler?

    Are you sure the tick interrupt is executing? If you put a break point in xTaskIncrementTick() in FreeRTOS/Source/tasks.c, does it ever get hit? If the tick count is not increment the timeout will never occur.

    How is your printf() implemented. That can often cause in small microcontroller systems, especially when it is used in more than one task, or uses semihosting (which will conflict with the kernel interrupts).

    Have you checked for stack overflow? Do you have configASSERT() defined? Etc.

Reply
  • The first thing is - what is the system doing when its apparently stuck in xQueueReceive(). Are other tasks running. If you pause the debugger, what is executing? Are you sure its not in a fault handler?

    Are you sure the tick interrupt is executing? If you put a break point in xTaskIncrementTick() in FreeRTOS/Source/tasks.c, does it ever get hit? If the tick count is not increment the timeout will never occur.

    How is your printf() implemented. That can often cause in small microcontroller systems, especially when it is used in more than one task, or uses semihosting (which will conflict with the kernel interrupts).

    Have you checked for stack overflow? Do you have configASSERT() defined? Etc.

Children
No Data
Related