Quality RTOS & Embedded Software

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


Task within a task - causing crash

Posted by rog57 on March 7, 2013

I have a fairly straightforward bit of code as such. The task time for this function in the main loop is set for 50ms.

static void prvReadCOMBufferTaskFunction( void *pvParameters )
portTickType xLastCheckTime;
xLastCheckTime = xTaskGetTickCount();

vTaskDelayUntil( &xLastCheckTime, check_COM_SIGNAL_RATE );

//check to see if start sequence received (startCycle). If started,
//initiate a task that will validate time taken. should never be
//more than 10-12 seconds from start.
if(startCycle )
//launch task to check in 10 seconds to see if completeFlag is set
pdPass = xTaskCreate( prvCommCheckTaskFunction, ( signed char * ) "CommCheck", configMINIMAL_STACK_SIZE, NULL, 2,(xTaskHandle)&CommCheckTask );
sprintf(msgBuf, "pdPass = %i", pdPass); _DBG_(msgBuf);

. if(completeFlag)
//found end of sequence; Ok to delete the comm check task.
if(CommCheckTask) vTaskDelete( (xTaskHandle) CommCheckTask );
//then process data

Here's the function callback for the created function: it's timer is set to 10 seconds

static void prvCommCheckTaskFunction( void *pvParameters )
portTickType xLastCheckTime;

// Initialize xLast***Times prior to the first call to vTaskDelayUntil()
xLastCheckTime = xTaskGetTickCount();

vTaskDelayUntil( &xLastCheckTime, checkComFlag_RATE );
_DBG_("If you can read this, an incomplet rx buffer was landed.");
if( CommCheckTask ) vTaskDelete( (xTaskHandle) CommCheckTask );


Here's the problem.
I can run it once and see that it deletes the task.
If I try it a second time - it crashes the program, causing WDT to kick.

Anything obviously wrong that I can change?


RE: Task within a task - causing crash

Posted by Friedrich Lobenstock on March 7, 2013
Sound like you should be using a software timer instead.

Please see:

RE: Task within a task - causing crash

Posted by Richard Damon on March 8, 2013
One question, why are you casting CommCheckTask to a xTaskHandle, it should be one already (and casting &CommCheckTask to one is incorrect).

Also, you need to take some care in deleting a task, as doing so stops it right were it is with NO cleanup, so any resources it creates are not released. In your case if it is in the vTaskDelayUntil call you should be ok, but if that ends and you are starting the _DBG call, that might cause problems.

RE: Task within a task - causing crash

Posted by rog57 on March 8, 2013
Hi, thanks for the help.
Not sure how that cast got in there? I thought most of my code was from FreeRTOS examples, but none of the other tasks have that cast. Thanks for pointing that out.

When you refer to cleanup, are you referring to FreeRTOS, or my code? If my code, yes, I have other stuff, just a few variables to set, which I would do before the delete. At this point I was just getting it to work repetitiously.

The function "prvReadCOMBufferTaskFunction" has been working with no issues at all before the above.

Any other suggestions - or is it just the task handle you think is causing this?

RE: Task within a task - causing crash

Posted by Richard Damon on March 8, 2013
The casts can only cause trouble if CommCheckTask wasn't defined as a xTaskHandle.

For cleanup, I was referring to things like allocating memory in the task, or acquiring semaphores.

One other thought is the code you posted doesn't check that the xTaskCreate call succeeds. It is possible that you run out of memory. A few quick questions, which heap version are you using? Also, is the idle task able to get time to run? In you application it MUST be given time to run, as vTaskDelete does not put the memory from the task back into the heap, but postpones that operation to the idle task. If you have a task, above priority 0, that doesn't block, you will not get your memory freed.

RE: Task within a task - causing crash

Posted by rog57 on March 8, 2013
Sorry, in the loop below it is actually this:

if(completeFlag && !pdPass) (have pdPass declared as well)

I'll add in the idle task and see if that changes anything. Thanks again for pointing that out.


RE: Task within a task - causing crash

Posted by rog57 on March 8, 2013
friedl - maybe I could use one. I'll read up on that and check it out. Thanks!

[ 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.

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