# xStackCreate

**URL:** <https://forums.freertos.org/t/xstackcreate/6940>\
**Category:** Kernel\
**Created:** [January 15, 2018, 8:02am UTC](https://forums.freertos.org/t/xstackcreate/6940 "2018-01-15T08:02:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 15, 2018, 8:02am UTC](https://forums.freertos.org/t/xstackcreate/6940/1 "2018-01-15T08:02:52Z")

</div>

**[michaeln32](https://sourceforge.net/u/michaeln32/)** wrote on [Monday, January 15, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/bfe196aa/#6dbd):

Can you please tell me what are the values that initial the stack of a task whae it  
create (xTaskCreate) ?

Are those values the general purpose registers ?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [January 15, 2018, 3:05pm UTC](https://forums.freertos.org/t/xstackcreate/6940/2 "2018-01-15T15:05:52Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, January 15, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/bfe196aa/#6dbd/4c2d):

To my knowledge there is no function xStackCreate().

Each task has its own stack and its own set of MCU registers. When a  
task is swapped out (stops executing to allow a different task to run)  
the task’s registers are saved onto its stack. When it starts running  
again its registers are popped off its stack so it can continue  
executing with exactly the same MCU context as when it stopped.

The stack used by a task is created when the task is created, and then  
initialized to make it look like the task had been swapped out - so the  
values placed onto the stack when the task is created are the values  
that the task will pop off the stack into the MCU registers when it  
first executes.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 15, 2018, 3:59pm UTC](https://forums.freertos.org/t/xstackcreate/6940/3 "2018-01-15T15:59:53Z")

</div>

**[michaeln32](https://sourceforge.net/u/michaeln32/)** wrote on [Monday, January 15, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/bfe196aa/#8978):

Richard, Thank you very much.

1. Are local variables of a task are saves on the task stack too ? If they do, Are the local variables that saved in the stack are saved after the MCU registers or before the MCU registers ?

2. Where can I find what is the order of the MCU registers are saved in the stack of a task, and what are the registers that are saved ?

Thank you !

Michael

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [January 15, 2018, 4:06pm UTC](https://forums.freertos.org/t/xstackcreate/6940/4 "2018-01-15T16:06:06Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, January 15, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/bfe196aa/#8978/806d):

> ```
> Are local variables of a task are saves on the task stack too ? 
> 
> ```

Where local variables are saved is completely under the control of the  
compiler you are using. FreeRTOS is just C code, compiled along with  
the rest of your application - it cannot change how the processor or the  
compiler work.

> ```
> Where can I find what is the order of the MCU registers are saved in
> the stack of a task, and what are the registers that are saved ?
> 
> ```

Have a look at the port layer source code. The initial stack is created  
by vPortInitialiseStack() in each port.c file - but that might not tell  
you much (depending on the port). Otherwise look at the code that saves  
and restores the context, which will be in the same port.c file or in an  
assembly file in the same directory as the port.c file.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 15, 2018, 4:16pm UTC](https://forums.freertos.org/t/xstackcreate/6940/5 "2018-01-15T16:16:55Z")

</div>

**[michaeln32](https://sourceforge.net/u/michaeln32/)** wrote on [Monday, January 15, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/bfe196aa/#9641):

I have this task:

void Task(void \*arg)  
{  
char stackBufferLcl[100];

```
while(1)
{
	vTaskDelay(5000);
}

```

}

When I call the API vTaskList() I see that the stack memory usege has grown in 100 bytes.  
So i asume that local varialbes of task do saves in task stack

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [January 15, 2018, 4:25pm UTC](https://forums.freertos.org/t/xstackcreate/6940/6 "2018-01-15T16:25:48Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, January 15, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/bfe196aa/#9641/f864):

If you want to know where local variables are stored you should consult  
your compiler’s manual. 100 bytes its almost certain to go on the  
stack. If it were 4 bytes then it would probably be stored in a register.
