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.

I have only two tasks.

This is my code

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

** CDL Task Configurations

#define configCDL_TASK_PRIORITY                 ( tskIDLE_PRIORITY + 2 )
#define configCDL_TASK_STK_SIZE                 ( 950 )

** 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));

    xTaskCreate(GUITask, (TASKCREATE_NAME_TYPE)"GUITask",

    xTaskCreate(CDLTask, (TASKCREATE_NAME_TYPE)"CDLTask",



I need suggestions to figure out the issue.

  • 1
    \$\begingroup\$ So what if you only init one of the queues? What do you mean by "task depth" - are you referring to the task stack? \$\endgroup\$ – brhans Jul 22 '19 at 13:37
  • \$\begingroup\$ 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. \$\endgroup\$ – ihsanogluu Jul 22 '19 at 13:41
  • \$\begingroup\$ And does it crash immediately when initializing one of these queues, or does it only crash some time later? \$\endgroup\$ – brhans Jul 22 '19 at 13:46
  • \$\begingroup\$ @brhans immediately, this is probably a heap size issue. I just couldnt figure it out \$\endgroup\$ – ihsanogluu Jul 22 '19 at 13:56
  • \$\begingroup\$ 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. \$\endgroup\$ – 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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.