Quality RTOS & Embedded Software

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




Loading

Hard fault after xTaskCreate

Posted by Christian Berger on September 26, 2012
I have a hard fault after xTaskCreate which vanishes when putting a vTaskDelay(1) right after it.

The paramter of the TaskCreate is a malloced struct containing pointers to other malloced structs. The task created just parses the messages given to it, then distributes it to other queues.

//This is where the parameters come from.
CMD_CMD* cmd_newcommand(char cmd[], uint32_t tag, CMD_CMD* next)
{
CMD_CMD* ncmd=pvPortMalloc(sizeof(CMD_CMD));
if (ncmd!=NULL){
(*ncmd).cmd=cmd;
(*ncmd).tag=tag;
(*ncmd).next=next;
if (tag==0) (*ncmd).cmdqueue=xQueueCreate(20,sizeof(CMD_LINE));
else {
(*ncmd).cmdqueue=0; //Damit irgendwas drin steht
if (next!=NULL) (*ncmd).cmdqueue=(*next).cmdqueue;
}
return ncmd;
} else return next;
}

//This is where the sheduler crashes
void cmd_newinterpreter(CMD_CMD* caller, CMD_CMD* commands)
{
CMD_PARAM* parm=pvPortMalloc(sizeof(CMD_PARAM));
(*parm).cmdqueue=(*caller).cmdqueue;
(*parm).cmdlist=commands;
xTaskCreate(cmd_commandtask,NULL,75,parm,2,NULL); //setting the stack size to 7500 won't help
vTaskDelay(1); //Removing this will make it crash
}

/* This is how it's typically used
* CMD_CMD* demo_dings = cmd_newcommand("dings",0,NULL);
* CMD_CMD* demo_bumms = cmd_newcommand("bumms",0,demo_dings);
* CMD_CMD* demo_mehr = cmd_newcommand("mehr",0,demo_bumms);
* CMD_CMD* demo_mehr_nochwas = cmd_newcommand("nochwas",0,NULL);
* cmd_newinterpreter(demo_mehr,demo_mehr_nochwas);
* CMD_CMD* demo_irgendwas =cmd_newcommand("irgendwas",demo_mehr);
* cmd_newinterpreter(demo,demo_irgendwas);
*/


This is running on an STM32F4 on the gcc. As far as I can tell, all Interrupt priorities are set to 0xf via the libraries.

RE: Hard fault after xTaskCreate

Posted by Richard on September 26, 2012
Is cmd_newinterpreter() called when when the kernel is already running? I presume so if you are calling vTaskDelay(1).

The effect calling vTaskDelay( 1 ) has will depend on the priority of the task you are calling cmd_newinterpreter() from. The task you are creating is priority 2, so if you are calling cmd_newinterpreter() from a task of priority 3 or higher, then the vTaskDelay() will allow cmd_commandtask() to run before cmd_newinterpreter() returns. If you are calling cmd_newinterpreter() from a task of priority 2 or lower, then cmd_commandtask() will run before cmd_newinterpreter() returned with or without the vTaskDelay( 1 ).

Does it crash inside xTaskCreate(), or inside cmd_commandtask()? What is it doing (or trying to do) to make it crash?

Do you create a new queue for every command? Do you check the queue was created before trying to use it (that is not shown in the code you have posted).

Plus the usual help links: http://www.freertos.org/FAQHelp.html

Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




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

Latest News

FreeRTOS kernel V10 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