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 ]    [ Sitemap ]    [ ]

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

Latest News

Meet us at Embedded World. Hall 3A-525.

Hear from Richard Barry at Embedded World. Feb 28, 16:00, Hall 4-428.

Video: Watch James Gosling & Richard Barry at re:Invent, Las Vegas 2017.

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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