# stack location in RAM

**URL:** <https://forums.freertos.org/t/stack-location-in-ram/935>\
**Category:** Kernel\
**Created:** [December 7, 2015, 8:45pm UTC](https://forums.freertos.org/t/stack-location-in-ram/935 "2015-12-07T20:45:50Z")\
**Posts on this page:** 5\
**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:** [December 7, 2015, 8:45pm UTC](https://forums.freertos.org/t/stack-location-in-ram/935/1 "2015-12-07T20:45:50Z")

</div>

**[antoxaxa](https://sourceforge.net/u/antoxaxa/)** wrote on [Monday, December 07, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/27ab8afe/#c2af):

Hello!  
I have a simple question,  
how can I find where my task stack begins in RAM?  
I use heap\_1.c implementation on dsPIC.

Thanks in advance,

---

<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:** [December 7, 2015, 9:01pm UTC](https://forums.freertos.org/t/stack-location-in-ram/935/2 "2015-12-07T21:01:06Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, December 07, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/27ab8afe/#0cb7):

There is currently a feature request, to be implemented for the next release, to provide a function that provides this and other information on the stack of a task. Currently you would have to inspect the task’s control block manually.

Regards.

---

<div class="post-metadata">

**Author:** ![tlafleur](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tlafleur](https://forums.freertos.org/u/tlafleur)\
**Post date:** [December 7, 2015, 9:41pm UTC](https://forums.freertos.org/t/stack-location-in-ram/935/3 "2015-12-07T21:41:57Z")

</div>

**[tlafleur](https://sourceforge.net/u/tlafleur/)** wrote on [Monday, December 07, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/27ab8afe/#c2af/e222):

look in the linker map…

On Mon, Dec 7, 2015 at 1:45 PM, Anton [antoxaxa@users.sf.net](mailto:antoxaxa@users.sf.net) wrote:

> Hello!  
> I have a simple question,  
> how can I find where my task stack begins in RAM?  
> I use heap\_1.c implementation.
> 
> ## Thanks in advance,
> 
> ## stack location in RAM [https://sourceforge.net/p/freertos/discussion/382005/thread/27ab8afe/?limit=25#c2af](https://sourceforge.net/p/freertos/discussion/382005/thread/27ab8afe/?limit=25#c2af)
> 
> Sent from [sourceforge.net](http://sourceforge.net) because you indicated interest in  
> [SourceForge.net: Log In to SourceForge.net](https://sourceforge.net/p/freertos/discussion/382005/)
> 
> To unsubscribe from further messages, please visit  
> [SourceForge.net: Log In to SourceForge.net](https://sourceforge.net/auth/subscriptions/)

–

~~\_/) `_/)` \_/) ``` \_/)~~

Tom Lafleur

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [December 8, 2015, 4:27am UTC](https://forums.freertos.org/t/stack-location-in-ram/935/4 "2015-12-08T04:27:39Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Tuesday, December 08, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/27ab8afe/#d33e):

Richard wrote:

> Currently you would have to inspect the task’s control block manually.

In case this is not immediately clear to you:

If you put a break somewhere in tasks.c you can see ‘pxCurrentTCB’, which points to the Task’s Control Block of the task which is currently active.

Two fields in the PCB may be of interest:

```auto
StackType_t pxTopOfStack; /* Location of the last item placed on the tasks stack. */
StackType_t pxStack; /* Start of the stack. */

```

And beside these two members, it might be interesting to check the actual Stack Pointer `SP`, which can be found in a window showing the CPU registers.

Lafleur wrote:

> look in the linker map…

You will find the location of the stack that will be used at boot time.

For instance, these are 512 bytes of boot stack.

```auto
    00000200 a __stack_size__
    ...
    0000fe00 B _stack
    00010000 B _estack

```

This stack space becomes vacant as soon as the scheduler is started by calling `vTaskStartScheduler()`.  
The function `xTaskCreate()` will have allocated stack space for each of the tasks ( using `pvPortMalloc()` ).

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 8, 2015, 12:24pm UTC](https://forums.freertos.org/t/stack-location-in-ram/935/5 "2015-12-08T12:24:21Z")

</div>

**[antoxaxa](https://sourceforge.net/u/antoxaxa/)** wrote on [Tuesday, December 08, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/27ab8afe/#b451):

I could not find anything in the map file.  
but the structure pxNewTCB-\>pxStack was a good hint!

Thanks to all
