Quality RTOS & Embedded Software

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


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


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

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists