# FreeRTOS crashing when adding new queues

I am new to FreeRTOS

At the beginning I created 3 queues and everything worked fine. Until I needed a new 4th and 5th queue.

When ever I initialize the queues with xQueueCreate() The system crashes.

I tried to increase the task depth. Also tried to increase the total Heap size with no success.

This is my code

/**
* Define the FreeRTOS task priorities and sizes
*/
#define configGUI_TASK_PRIORITY                 ( tskIDLE_PRIORITY + 3 )

/*
*/

#define configCDL_TASK_PRIORITY                 ( tskIDLE_PRIORITY + 2 )

/*
** FreeRTOS Queues
*/

xQueueHandle msgGuiRqst;
xQueueHandle msgCdlStatus;
xQueueHandle msgCdlRspnsBool;
xQueueHandle msgPlatformsStatusData;
xQueueHandle msgPlatformsWeightData;

int main(void)
{
msgGuiRqst      = xQueueCreate(1, sizeof(char));
msgCdlStatus    = xQueueCreate(1, sizeof(char));
msgCdlRspnsBool = xQueueCreate(1, sizeof(bool));

// Problem started after adding these two queues
msgPlatformsStatusData = xQueueCreate(2, sizeof(bool));
msgPlatformsWeightData = xQueueCreate(2, sizeof(int));

NULL,
NULL);

NULL,
NULL);

while(1)
{
;
}
}


I need suggestions to figure out the issue.

• So what if you only init one of the queues? What do you mean by "task depth" - are you referring to the task stack? – brhans Jul 22 '19 at 13:37
• yes , I mean the task stack. Initializing the first 3 queues makes no issue. everything works fine. Only initializing the 4th or 5th (last two) queues results with system crash. – ihsanogluu Jul 22 '19 at 13:41
• And does it crash immediately when initializing one of these queues, or does it only crash some time later? – brhans Jul 22 '19 at 13:46
• @brhans immediately, this is probably a heap size issue. I just couldnt figure it out – ihsanogluu Jul 22 '19 at 13:56
• When you say immediately you mean it is crashing specifically on the xQueueCreate calls? If not, you should check to see if the xQueueCreate call is returning null before proceeding. – nvuono Jul 22 '19 at 15:15

I'm not sure I follow this. If the call to xQueueCreate() causes the system to crash, and xQueueCreate() is being called from main() before the scheduler has started, then it can't be the task stack size as the task is not running (and therefore its stack is not being used yet).
If it is crashing in the call to xQueueCreate() then simply step into the function in the debugger to see where it is crashing. It might be that the C run-time is not set up correctly before main() is called.
Which version of FreeRTOS are you using? It looks to be VERY old if you are using xQueueHandle instead of QueueHandle_t as the variable type. If it is a moderately recent version and you think you may be running out of heap (seems extremely doubtful, if you create tasks after the queues and creating the tasks doesn't fail) then you can use a malloc failed hook (https://www.freertos.org/a00016.html ) which is a callback that will get executed if a memory allocation fails.