Debugger gets stuck at configASSERT(( pxQueue )); in queue.c

Hi, I have a strange problem with a MKV58F24C. I am running he latest version of FreeRTOS and trying to create a very simple task. The debugger gets stuck at configASSERT(( pxQueue )); in queue.c. I am not even using any queues… My code is shown below.

Any insights from anyone please?

 
void vMenuTask(void* pvParameters) {
/* The parameter value is expected to be 1 as 1 is passed in the
   pvParameters value in the call to xTaskCreate() below. */
//configASSERT(((uintptr_t)pvParameters) == 1);
 
for (;;) {
        printf("Test\n\n");
        vTaskDelay(pdMS_TO_TICKS(100));
 
}
 
}void vInitMenuTask(void) {
 
// Create the task dynamically
BaseType_t xTaskCreated = xTaskCreate(vMenuTask,              // Task function
"Menu Task",           // Task name
MENU_TASK_STACK_SIZE, // Stack size
(void*)1,              // Task parameter
MENU_TASK_PRIORITY, // Priority
&xMenuTaskHandle  // Task handle
);
 
if (xTaskCreated == pdPASS) {
printf("Menu task created successfully.\n");
}
else {
printf(stderr, "Failed to create menu task. Not enough heap RAM.\n");
}
}
vInitMenuTask();

printf("FreeRTOS initialization complete.\n");

vTaskStartScheduler();
/* vTaskStartScheduler should not return, but if it does, enter an infinite loop: */
for (;;) {

}

}

I would first look at the stack trace to see how it got to that call in queue.c

Is your code using timers? as the timer task uses a Queue.

You might be having a memory overwrite issue, which can be tough to trace down.

1 Like

In addition to Richard’s hints how is MENU_TASK_STACK_SIZE defined ?
Did you also enable stack checking during development ?

Could you also provide which line or method this assertion is in? There are number of instances of this assertion in queue.c (see search).

This should help drive us closer to the problems source.

Hi Richard,

Thanks for your reply. I do have PIT tasks and software timer tasks in my code but they are lying dormant for the moment (no init).

I will do a stack trace when I am back on the hardware on Monday.

Kind regards,
Robert

Hi Kody,

I will only be back on the hardware on Monday, then I can see which line of queue.c it was. I can’t remember of the top off my head.

Kind regards,
Robert

Hi Hartmut,

Yes, stack checking is defined:
#define configCHECK_FOR_STACK_OVERFLOW 1

I also implemented
vApplicationStackOverflowHook()

The definition of MENU_TASK_STACK_SIZE is as follows:
#define MENU_TASK_STACK_SIZE (8 * configMINIMAL_STACK_SIZE)
// 256 words = 2048 bytes

Kind regards,
Robert

Hi Kody,

I found the line, I marked it in other editor. It is 1666:

BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
                                TickType_t xTicksToWait )
{
    BaseType_t xEntryTimeSet = pdFALSE;
    TimeOut_t xTimeOut;
    Queue_t * const pxQueue = xQueue;

    #if ( configUSE_MUTEXES == 1 )
        BaseType_t xInheritanceOccurred = pdFALSE;
    #endif

    traceENTER_xQueueSemaphoreTake( xQueue, xTicksToWait );

    /* Check the queue pointer is not NULL. */
    configASSERT( ( pxQueue ) );     //    <==== line 1666

    /* Check this really is a semaphore, in which case the item size will be
     * 0. */
    configASSERT( pxQueue->uxItemSize == 0 );

Kind regards,
Robert

Stack size seems large enough. Great that you found the problematic assert !
I’m sure you’ll also find the root cause problem why the semaphore to take is probably not (yet) created when xQueueSemaphoreTake is called. Looking at the backtrace resp. callstack in the debugger might help.
Under the hood semaphores are implemented using the queue mechanism in FreeRTOS.

So it isn’t a “Queue” but a Semaphore (which are based on Queue with no data). Again, you need to look at the stack trace back to see who is using a Semaphore (or a Mutex) before that Semaphore was created, so it has a Null handle.

1 Like

Are you using a mutex or either a counting or binary semaphore in your application? And if so, have you called the corresponding creation APIs? Your example code does not show any semaphore/mutex usage.

Our doc pages have more info info on the xSemaphoreCreateBinary(), xSemaphoreCreateMutex(), and xSemaphoreCreateCounting() APIs.

Hi Kody,

They are there, but I don’t want to clutter the message box. But it is probably better to share the whole picture. This morning at work, the debugger got stuck at

configASSERT( ucMaxSysCallPriority ); ; line 367 of port.c.

I use static memory allocation; my task creation is as follows in my_file.c:

/* STATIC */

/* Declare the semaphore(s) */
	StaticSemaphore_t xUARTMenuTaskSemaphoreBuffer1, xUARTMenuTaskSemaphoreBuffer2;
	SemaphoreHandle_t xUARTMenuTaskSemaphore1, xUARTMenuTaskSemaphore2;

	/* Declare the mutexes */
	StaticSemaphore_t xUARTMenuTaskMutexBuffer1, xUARTMenuTaskMutexBuffer2;
	SemaphoreHandle_t xUARTMenuTaskMutex1, xUARTMenuTaskMutex2;

	/* Declare the queue(s) */
	StaticQueue_t xUARTMenuTaskQueueBuffer1, xUARTMenuTaskQueueBuffer2;
	QueueHandle_t xUARTMenuTaskQueue1, xUARTMenuTaskQueue2;

	/* Allocate memory for the queues' storage */
	uint8_t ucUARTMenuTaskQueueStorage1[UART_MENU_TASK_QUEUE_LENGTH * UART_MENU_TASK_QUEUE_ITEM_SIZE];
	uint8_t ucUARTMenuTaskQueueStorage2[UART_MENU_TASK_QUEUE_LENGTH * UART_MENU_TASK_QUEUE_ITEM_SIZE];

	/* Task handle and buffer for static task */
	StaticTask_t xUARTMenuTaskBuffer;
	StackType_t xUARTMenuTaskStack[UART_MENU_TASK_STACK_SIZE];

	/* Task function */
	void vUARTMenuTask(void* pvParameters) {
		/* The parameter value is expected to be 1 as 1 is passed in the
		   pvParameters value in the call to xTaskCreateStatic() below. */
		configASSERT(((uintptr_t)pvParameters) == 1);

		for (;;) {
			// Task loop
            if (splashScreenDisplayed == pdFALSE) {
                displaySplashScreen();
                vTaskDelay(pdMS_TO_TICKS(splashScreenDisplayTime * 1000));
                displaySplashScreen2();
                vTaskDelay(pdMS_TO_TICKS(splashScreenDisplayTime * 1000));

                //splashScreenDisplayed = pdTRUE; //Don't set to pdTRUE: infinite loop for testing
            }

            //printMainMenu();
            //printf("Test\n\n");
            //vTaskDelay(pdMS_TO_TICKS(10));

		}
	}

	/* Initialization function */
	void vInitUARTMenuTask(void) {

		console_init();

		/* Create the semaphores statically */
		xUARTMenuTaskSemaphore1 = xSemaphoreCreateBinaryStatic(&xUARTMenuTaskSemaphoreBuffer1);
		xUARTMenuTaskSemaphore2 = xSemaphoreCreateBinaryStatic(&xUARTMenuTaskSemaphoreBuffer2);

		if (xUARTMenuTaskSemaphore1 == NULL || xUARTMenuTaskSemaphore2 == NULL) {
			//safeFprintf(stderr, "Failed to create the UART menu task semaphores.\n");
			return;
		}

		/* Create the mutexes statically */
		xUARTMenuTaskMutex1 = xSemaphoreCreateMutexStatic(&xUARTMenuTaskMutexBuffer1);
		xUARTMenuTaskMutex2 = xSemaphoreCreateMutexStatic(&xUARTMenuTaskMutexBuffer2);

		if (xUARTMenuTaskMutex1 == NULL || xUARTMenuTaskMutex2 == NULL) {
			//safeFprintf(stderr, "Failed to create the UART menu task mutexes.\n");
			return;
		}

		/* Create the queues statically */
		xUARTMenuTaskQueue1 = xQueueCreateStatic(UART_MENU_TASK_QUEUE_LENGTH,
			UART_MENU_TASK_QUEUE_ITEM_SIZE,
			ucUARTMenuTaskQueueStorage1,
			&xUARTMenuTaskQueueBuffer1);

		xUARTMenuTaskQueue2 = xQueueCreateStatic(UART_MENU_TASK_QUEUE_LENGTH,
			UART_MENU_TASK_QUEUE_ITEM_SIZE,
			ucUARTMenuTaskQueueStorage2,
			&xUARTMenuTaskQueueBuffer2);

		if (xUARTMenuTaskQueue1 == NULL || xUARTMenuTaskQueue2 == NULL) {
			//safeFprintf(stderr, "Failed to create the UART menu task queues.\n");
			return;
		}

		// Create the task statically
		TaskHandle_t xUARTMenuTaskHandle = xTaskCreateStatic(
			vUARTMenuTask,                 // Task function
			"TCP Menu Task",               // Task name
			UART_MENU_TASK_STACK_SIZE,       // Stack size
			(void*)1,                      // Task parameter
			UART_MENU_TASK_PRIORITY,        // Priority
			xUARTMenuTaskStack,            // Stack buffer
			&xUARTMenuTaskBuffer           // Task buffer
		);

		if (xUARTMenuTaskHandle == NULL) {
			//safeFprintf(stderr, "Failed to create the UART menu task.\n");
		}
		else {
			//safePrintf("The UART menu task was created successfully.\n");
		}
	}

Since it has a problem with ucMaxSysCallPriority, I also share the relevant sections of FreeRTOSConfig.h:

/* Interrupt priorities */

#ifdef __NVIC_PRIO_BITS
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used.
 * In core_cm7.h:  __NVIC_PRIO_BITS = 3U => 8 priority levels */
#define configPRIO_BITS                         __NVIC_PRIO_BITS
#else
#define configPRIO_BITS 3U /* 8 priority levels */
#endif

/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY ((1U << (configPRIO_BITS)) - 1)
/* (1 << 3) - 1 = 7 */

/*
         * ISRs that CAN call FreeRTOS APIs:
     * Priority levels must be greater than or equal to configMAX_SYSCALL_INTERRUPT_PRIORITY, which is 2.
     * Valid numerical values: 2, 3, 4, 5, 6, 7.
     * ISRs that CANNOT call FreeRTOS APIs:
     * Numerical values: 0, 1 */

/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
    See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */

#define configMAX_SYSCALL_INTERRUPT_PRIORITY 2

#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 2

/* Interrupt priorities used by the kernel port layer itself.  These are generic
* to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY 7

Sorry for dumping so much code on you, but it is better to share the full picture.

This is wrong and likely the cause of your problem. Please shift the value according to the number of bits implemented:

#define configMAX_SYSCALL_INTERRUPT_PRIORITY        ( 2 << (8 - configPRIO_BITS) )

Here is an example - FreeRTOS/FreeRTOS/Demo/CORTEX_MPU_STM32L4_Discovery_GCC_IAR_Keil/Config/FreeRTOSConfig.h at main · FreeRTOS/FreeRTOS · GitHub.

Thanks Gaurav,

I changed the value to that expression; it works out to 64.

The problem shifted to tasks.c: Line 6116; it looks like it has to do with task delete. As you can see from my code, it is very simple and there are no calls to vTaskDelete;

Kind regards,
Robert

This line -FreeRTOS-Kernel/tasks.c at main · FreeRTOS/FreeRTOS-Kernel · GitHub? What is the problem there? Can you post the callstack?