2 tasks work, but 3 and more no

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″,configMINIMAL_STACK_SIZE,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″, onfigMINIMAL_STACK_SIZE,NULL,tskIDLE_PRIORITY + 1,NULL); vTaskStartScheduler(); while(1){} }

2 tasks work, but 3 and more no

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

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

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

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

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

Thank You for explanations ! Thay help me !

2 tasks work, but 3 and more no

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″, configMINIMAL_STACK_SIZE,NULL,tskIDLE_PRIORITY + 1, NULL); vTaskStartScheduler(); }

2 tasks work, but 3 and more no

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

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

2 tasks work, but 3 and more no

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

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

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

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