Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


xQueueReceive stops receiving?

Posted by Thomas Johansen on March 6, 2013
Hi All

I have a TXTask, that uses a queue for receiving data to send. The queue is 5 deep.
2 other task can then send message to this task for transmission.
(And a lot of other tasks doing other stuff)

I had it running the night for testing. But at some point, the xQueueSend returned that the queue was full...

In the TXTask, I have a timeout on the xQueueReceive function, to maintain a watchdog. The task was still running, but the xQueueReceive never returned pdTRUE.

It is a bit difficult to debug, because stepping through the receiving function, a schedule will happen and I will debug some other code/callstack

Any idea what can be wrong with the receive function never get triggered?
How to debug the code without getting re-scheduled?
Could it be a stack overflow somewhere? (I have configCHECK_FOR_STACK_OVERFLOW defined to 1)


RE: xQueueReceive stops receiving?

Posted by Dave on March 6, 2013
You could use FreeRTOS+Trace to see what is happening. Start a trace recording using a circular buffer, then stop the trace when xQueueSend() returns pdFALSE so you can see what happens immediately before that.

You could also post the code for your receive function here. Without seeing the code there are too many possibilities to go through. For example, it could simply be that a task that has a higher priority is stopping the receive task from ever running so the queue becomes full.

RE: xQueueReceive stops receiving?

Posted by Thomas Johansen on March 6, 2013

I will try using the FreeRTOs+Trace next time it happens...

I don't think another task is stopping it from running.
The timeout on the xQueueReceive works fine, refreshing my watchdog. Also could debug the task, but pdTRUE never returned. Also configGENERATE_RUN_TIME_STATS say that no task a taking to much CPU time.

Receive code that stops receving

void ProtocolTXTask(void *pvParameters)
BYTE byRetries = 0;
BYTE byTXTaskID = 0;

// Create a queue for RX events...
g_xProtocolTXEvent = xQueueCreate( 5, sizeof(PROTOCOL_TX) );

if( g_xProtocolTXEvent == 0 )

byTXTaskID = RegisterTaskToWatchdog(xProtocolTXHandle, 10);

if(pdTRUE == xQueueReceive (g_xProtocolTXEvent, &sTXData, 5000))

// Media connected?
if( bActiveConnection[sTXData.byMedia] )
// Send the data
if(pdTRUE == (*pTXdata[sTXData.byMedia])(sTXData.ulTXBuffer, sTXData.nSize, sTXData.xTimeout,
sTXData.bRAW)) // Normal
sTXData.byState = 1;
sTXData.byState = 0;
} // While(1)

Code that post to the g_xProtocolTXEvent queue (Called by different tasks)

BOOL ProtocolSendData(unsigned long ulTXData, int nTXSize, BYTE byMedia, portTickType xTimeOut, BOOL bRAW)

sTXData.nSize = nTXSize;
sTXData.ulTXBuffer = (unsigned long)ulTXData; // Address of the TX data
sTXData.xTimeout= xTimeOut;
sTXData.bRAW = bRAW;
sTXData.byMedia = byMedia;

if(xQueueSend(g_xProtocolTXEvent, (void*)&sTXData, ( portTickType ) 10))
return TRUE;

return FALSE;

RE: xQueueReceive stops receiving?

Posted by Dave on March 6, 2013
if( g_xProtocolTXEvent == 0 )

You must not exit a task like that. Use vTaskDelete(NULL) instead of return;

Does PROTOCOL_TX just contain the members shown being accessed in your ProtocolSendData() send function? If so then stack overflow is unlikely. You could set configCHECK_FOR_STACK_OVERFLOW to 2 to be a bit more secure, but I don't think that is your problem.

Is ProtocolSendData() ever called from an interrupt? If so then you will need to use xQueueSendFromISR() version.

Which compiler are you using? The state viewer plug in available for Eclipse and IAR will show you how many items are in the queue. If there are items in the queue then you can step through the xQueueReceive() function to see why it thinks its empty.

Have you checked all the http://www.freertos.org/FAQHelp.html items?

RE: xQueueReceive stops receiving?

Posted by Thomas Johansen on March 6, 2013
Yes, PROTOCOL_TX only contains the data shown...
I have configCHECK_FOR_STACK_OVERFLOW to 1 without anything. I know the configCHECK_FOR_STACK_OVERFLOW works. been there :-)

ProtocolSendData() is never send called from a ISR. It can be called from 3 different tasks.

I' usin KEIL MDK and I can see the the queue values. There are items in the queue.
I then step into the xQueueReceive(..) function, still with queue item at 5. The call stack also are correct.
Then after "taskENTER_CRITICAL" there was a task switch i guess. The call stack changed to a different part of my application (the call stack contained other functions that also uses xQueueReceive(..)) and the queue item was different as well.

I thin there was a contents switch during the debug steps. Maybe I can make the debugger disable all interrupts while stepping through code?


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner