Quality RTOS & Embedded Software

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


Multiple xTaskCreate calls consume all memory

Posted by hytromo on June 30, 2016

Our processor runs a server in the background which listens for commands. We can command it to send a low value to a pin, wait a bit, and then reset the pin to the default high value.

Because of the running server, It is important that the above process is executed as a separate task.

As stated here http://www.freertos.org/a00126.html, we create the task (via xTaskCreate(mixer, "Mixer", UINT32_C(2048), NULL, UINT32_C(2), &mixerTask)) which calls the following function:

~~~ void mixer(void * pvParameters) { (void) pvParameters;

    // set PIN LOW code here


     // set PIN HIGH code here

   vTaskDelete(mixerTask); // delete the task itself (memory is scheduled for being freed)

} ~~~

The task runs each time our server receives a specific command, which is ~10-20 seconds.

Apart from the server, we have a timer (created via vTimerCreate) running every 600ms performing a simple task.

The problem is that we run out of memory after 3 calls to the vTaskCreate function. Searching the web reveals that the IDLE task is responsible for freeing the memory after the call to vTimerDelete.

Should we create this IDLE task ourselves or how else can we solve this problem?

Multiple xTaskCreate calls consume all memory

Posted by rtel on June 30, 2016

The idle task is created automatically - you do not need to create it yourself. However, if you are deleting tasks (or in FreeRTOS V9 just if a task deletes itself) you do need to ensure the idle task gets some processing time. The idle task runs at the idle priority (stating the obvious ;o) which is priority 0. If you have tasks above priority zero that never enter the Blocked state (don't call vTaskDelay(), vTaskDelayUntil(), or otherwise enter the Blocked state to wait for a queue/semaphore/direct to task event) then the Idle task will never run - and I suspect that is your problem.

As an aside, why do you create and delete a task each time anyway? When the command is given you can set the pin low and reset a software timer. Once the software timer expires its callback function can set the pin high again.

[ 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