Need Help with Queue Send Error in FreeRTOS

Hi everyone,

I’m currently working on a project using FreeRTOS, and I’ve run into an issue that I can’t seem to figure out. I’m hoping someone here might be able to help me out.

I’m trying to send data to a queue using xQueueSend, but I keep getting a “Queue Send Error”. Here’s a bit more detail about what I’m doing:

  • I’ve created a queue with a length of 5 and a size of sizeof(int).
  • I have a task that generates data and tries to send it to the queue.
  • I’m using xQueueSend with a block time of pdMS_TO_TICKS(100).

However, it seems like the queue is always full, and xQueueSend fails. Here’s the relevant code snippet:

QueueHandle_t myQueue;
int data = 42;

void vProducerTask(void *pvParameters)
{
    myQueue = xQueueCreate(5, sizeof(int));
    if (myQueue == NULL)
    {
        // Error handling
    }

    for (;;)
    {
        if (xQueueSend(myQueue, &data, pdMS_TO_TICKS(100)) != pdPASS)
        {
            // Queue send error handling
            printf("xQueueSend failed to send message to myQueue.\n");
        }
        vTaskDelay(pdMS_TO_TICKS(200)); // Delay to simulate work
    }
}

When I was searching about this I came across to these resources Message Queue Errors - FreeRTOS GCP Interview Questions, and as per them I tried the following.

  • I tried by Increasing the queue length.
  • I tried by Increasing the block time in xQueueSend.
  • I have cross checked if the task sending data is running too fast compared to the task consuming data.

But none of these seem to work. The consumer task is reading from the queue, but it seems like it’s not able to keep up, even though I’ve tried to slow down the producer task.

Has anyone faced a similar issue or have any suggestions on what I might be doing wrong? Any tips on how to debug this would be greatly appreciated!

Thanks in advance!

Hi @amaracollins ,

Can you please let us know what is the priority of both producer & consumer task? Can you try making the priority of consumer equal to producer or more than that?
Also is there any difference in delay for both producer & consumer task?

It would be great if you can share the consumer code as well to check it further. Thank you

1 Like

can we see the code for the consumer task? Is there a possible race condition where the consumer attempts to read from the queue before it is generated and thus terminates?

Edit: It is also considered good pactice to create shared objects such as Muteces and queues before starting the scheduler.

1 Like