# checking stack usage 

**URL:** <https://forums.freertos.org/t/checking-stack-usage/7703>\
**Category:** Kernel\
**Created:** [March 1, 2019, 10:56am UTC](https://forums.freertos.org/t/checking-stack-usage/7703 "2019-03-01T10:56:05Z")\
**Posts on this page:** 4\
**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:** [March 1, 2019, 10:56am UTC](https://forums.freertos.org/t/checking-stack-usage/7703/1 "2019-03-01T10:56:05Z")

</div>

**[mr-m-from-k](https://sourceforge.net/u/mr-m-from-k/)** wrote on [Friday, March 01, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/1e40721c25/#d18f):

Hello,

I struggle with stack checks because increasing the size in TaskCreateStatic did not give a corresponding result when using usStackHighWaterMark. I work on a Cortex-M7, StackType\_t is set to uint32\_t.  
Now, when I increase the stack size passed into TaskCreateStatic by one the result I get in uxTaskGetSystemState[n].usStackHighWaterMark increases by 2. Increasing in TaskCreateStatic by 2 also increases usStackHighWaterMark by 2, 3-\> 4, 4-\>4 and so on. I always check at the same system state, so the real stack usage at that point is the same (I suppose).  
FreeRTOS Tutorial says usStackHighWaterMark gives the remaining stack in bytes. I also looked at prvTaskCheckFreeStackSpace. Somehow I can’t make sense of it.

Any help is welcome - thanks

Martin

---

<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:** [March 1, 2019, 11:39am UTC](https://forums.freertos.org/t/checking-stack-usage/7703/2 "2019-03-01T11:39:34Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, March 01, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/1e40721c25/#d18f/c353):

Stack sizes are specified in words, whereas stack high water mark is reported in bytes. Does that help?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 1, 2019, 12:27pm UTC](https://forums.freertos.org/t/checking-stack-usage/7703/3 "2019-03-01T12:27:35Z")

</div>

**[mr-m-from-k](https://sourceforge.net/u/mr-m-from-k/)** wrote on [Friday, March 01, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/1e40721c25/#93e1):

Hello Richard,

yes, that’s also what I have learned from the docu.  
But then I would expect when increasing the stack size value passed into TaskCreate(Static) by 1 that I get 4 more out with usStackHighWaterMark and 2 -\> 8 and so on. But that is not what I found.

…

I checked again prvTaskCheckFreeStackSpace that is called to fill usStackHighWaterMark and it has this line:  
ulCount /= ( uint32\_t ) sizeof( StackType\_t );  
which makes me think the output is in units of StackType\_t.  
Please kindly check that again and confirm, as I just did a quick text search. My FreeRTOS version is V10.1.1.

kind regards

Martin

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 2, 2019, 2:39am UTC](https://forums.freertos.org/t/checking-stack-usage/7703/4 "2019-03-02T02:39:47Z")

</div>

**[richarddamon](https://sourceforge.net/u/richarddamon/)** wrote on [Saturday, March 02, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/1e40721c25/#f8ca):

One other thing to note is that on some processors (like the Arm Cortex series) the stack needs to be aligned more strictly than a stack ‘word’ by the ABI, so there is a ‘round up’ aspect in the stack size. Thus the size of the stack will be rounded up to the next multiple of that stack alignment.
