Quality RTOS & Embedded Software

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


Loading

2 tasks work, but 3 and more no

Posted by miklpolikov on November 18, 2013

Good day everybody !

I am starting to use FreeRTOS. My configuration : CPU STM32L151, compiler KEIL, using heap_2 I have meat the problem : 1 or 2 tasks are work well, but three and more are not. After execute vTaskStartScheduler(); program get in while(1){} in the wery end of main{}. What am I do wrong ?

And the other question, where to find file errors.h with error codes that xTaskCreate( ) return ? I have find some file error.h in folder freertos, but there is no erroe with code 1 or -1 that I see.

I'm sorry, but I do not know why some lines are in so large font.

Thanks in advance!

define configUSE_PREEMPTION 1
define configUSEIDLEHOOK 0
define configUSETICKHOOK 0
define configCPUCLOCKHZ ( ( unsigned long ) 16000000 )
define configTICKRATEHZ ( ( portTickType ) 1000 )
define configMAXPRIORITIES ( ( unsigned portBASETYPE ) 2 )
define configMINIMALSTACKSIZE ( ( unsigned short ) 128 )
define configTOTALHEAPSIZE ( ( size_t ) ( 17*128) )
define configMAXTASKNAME_LEN ( 16 )
define configUSETRACEFACILITY 0
define configUSE16BIT_TICKS 0
define configIDLESHOULDYIELD 1

void Task1 (void *pvParameters) { char x; while(1) { x++; } }

void Task2 (void *pvParameters) { char x; while(1) { x++; } }

void Task3 (void *pvParameters) { char x; while(1) { x++; } }

void Task4 (void *pvParameters) { char x; while(1) { x++; } }

void main() { xTaskCreate(Task1,(signed char)"Task1",configMINIMALSTACKSIZE,NULL,tskIDLE_PRIORITY + 1,NULL); xTaskCreate(Task2,(signed char)"Task2",configMINIMALSTACKSIZE,NULL,tskIDLEPRIORITY + 1,NULL); xTaskCreate(Task3,(signed char*)"Task3",configMINIMALSTACKSIZE,NULL,tskIDLEPRIORITY + 1,NULL); xTaskCreate(Task4,(signed char*)"Task4", onfigMINIMALSTACKSIZE,NULL,tskIDLE_PRIORITY + 1,NULL);

vTaskStartScheduler();

while(1){} }


2 tasks work, but 3 and more no

Posted by davedoors on November 18, 2013

Step through the function in the debugger, you will soon see why it returns. I expect you have run out of heap space and that is preventing the idle task (or the timer task) being created. http://www.freertos.org/a00111.html


2 tasks work, but 3 and more no

Posted by richard_damon on November 18, 2013

The normal cause of this is running out of heap. Which heap routine are you linking with your code?

Note that Calling vTaskStartScheduler() (which I don't see in your above sample) needs to create 1 or 2 more processes, the Idle task, and maybe the Timer task. Task stack sizes are specified in "words" but heap size in in bytes. I think your processor uses 32 bit stack words, so your 17*128 byte heap has room for only 4 task stacks + 128 bytes, which may not be enough for 4 TCBs (or just barely and you are creating the timer task)


2 tasks work, but 3 and more no

Posted by miklpolikov on November 18, 2013

Did I understand correctly ? : configMINIMALSTACKSIZE ( ( unsigned short ) 128 )
means that one task nead 128 4-byte words stack becouse my CPU is 32-bit, and configTOTALHEAPSIZE ( ( size_t ) ( 17 * 128) ) means that total heap is 17 * 128=2176 bytes ?


2 tasks work, but 3 and more no

Posted by richardbarry on November 18, 2013

configMINIMALSTACKSIZE

The only place this constant is used by the kernel itself is when the idle task is created. It is representative of the smallest stack a task can realistically have. Naturally if you task calls library functions, or has a deep function call nesting depth, it will need to be larger. The demo applications use the constant to, for convenience, as they run on lots of different architectures.

As described in the API documentation the stack size is specified in the number of variables the stack can hold. On you device each stack variable is 4 bytes wide, so specifying that the stack should hold 100 values will result in a stack of 400 bytes being allocated.

configTOTALHEAPSIZE ( ( size_t ) ( 17128) ) means that total heap is 17128=2176 bytes ?

I don't understand this part of your comment. heap_2 effectively uses a statically allocated char array as the heap. Each char is one bytes, so a heap of 17128 will be 17128 bytes.

Regards.


2 tasks work, but 3 and more no

Posted by miklpolikov on November 18, 2013

The sign * was lost, I write that as I understand configTOTALHEAPSIZE ( ( size_t ) ( 17 * 128) ) means that total heap is 17 * 128=2176 bytes .


2 tasks work, but 3 and more no

Posted by miklpolikov on November 18, 2013

Thank You for explanations ! Thay help me !


2 tasks work, but 3 and more no

Posted by miklpolikov on November 18, 2013

One more question. Why when I try to create one more task in body of runing task, program fails ?

define configMINIMALSTACKSIZE ( ( unsigned short ) 128)
define configTOTALHEAPSIZE ( ( size_t ) ( 10 * 128 * 4) )

void Task2 (void *pvParameters);

void Task1 (void pvParameters) { char x; xTaskCreate(Task2,(signed char)"Task2",configMINIMALSTACKSIZE,NULL,tskIDLE_PRIORITY+ 1, NULL); vTaskStartScheduler(); while(1) { x++; } }

void Task2 (void *pvParameters) { char x1; while(1) { x1++; } }

void main() { xTaskCreate(Task1,(signed char*)"Task1", configMINIMALSTACKSIZE,NULL,tskIDLE_PRIORITY + 1, NULL); vTaskStartScheduler();

}


2 tasks work, but 3 and more no

Posted by richardbarry on November 18, 2013

The formatting is not easy to follow - but it looks like you are calling vTaskStartScheduler() from a task. vTaskStartScheduler() should only ever be called once. Once the scheduler is running it cannot be re-started.

Regards.


2 tasks work, but 3 and more no

Posted by miklpolikov on November 18, 2013

Thank You, before I think that vTaskStartScheduler() should be implement after every xTaskCreate( )


2 tasks work, but 3 and more no

Posted by miklpolikov on November 18, 2013

And the other one question :

Why my task work correctly only with static variables ? As I understand, all contest of task, i.e. CPU core registers and task variables are saved in stack, so directive static should influence nothing ?


2 tasks work, but 3 and more no

Posted by richardbarry on November 18, 2013

Each task maintains its own context, and has its own stack, so declaring variables on the stack should not be a problem. If it works when you make them static then it probably means you have overflowed your stack. How big was the variable? Have you turned stack overflow protection on? Do you have configASSERT() defined?

Regards.


2 tasks work, but 3 and more no

Posted by miklpolikov on November 18, 2013

The question: If I use in task, for exumple, 13 variables(char, int, long int ) and I shure that I not use there any libraries and so on, it means that when this task create by xTaskCreate( ) I can specify the value of parameter usStackDepth =13 , and it will be tha best way to economize memory space ? This is right ?

And If I use In this task xTaskCreate( ), vTaskDelete( ) how many stack size will need them ?

I use heap_2.c


2 tasks work, but 3 and more no

Posted by dumarjo on November 18, 2013

hi,

Le 2013-11-18 12:24, Mikhail_P a écrit : > > The question: > If I use in task, for exumple, 13 variables(char, int, long int ) and > I shure that I not use there any libraries and so on, it means that > when this task create by xTaskCreate( ) I can specify the value of > parameter usStackDepth =13 , and it will be tha best way to economize > memory space ? This is right ? > no. You should have enough stackdepth to handle also the calling for function. Normay you should put a bigger number on your stackdepth and when you can get your stats working, you will be able to see you free stack from there.

Regards Jonathan


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


Careers

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

Renesas

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