# uxTaskGetStackHighWaterMark problem?

**URL:** <https://forums.freertos.org/t/uxtaskgetstackhighwatermark-problem/63>\
**Category:** Kernel\
**Created:** [October 19, 2008, 10:16am UTC](https://forums.freertos.org/t/uxtaskgetstackhighwatermark-problem/63 "2008-10-19T10:16:06Z")\
**Posts on this page:** 2\
**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:** [October 19, 2008, 10:16am UTC](https://forums.freertos.org/t/uxtaskgetstackhighwatermark-problem/63/1 "2008-10-19T10:16:06Z")

</div>

**[grahamfclark](https://sourceforge.net/u/grahamfclark/)** wrote on [Sunday, October 19, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/05c78107/#c09c):

Hi, I’m using FreeRTOS 5.0.3 on a PIC32 and just I’ve started to use uxTaskGetStackHighWaterMark() to determine my stack usage. However I’m getting some strange values returned from it. As far as I can see it should return the number of words available on the stack. On the PIC32 a word is 4 bytes. Looking at the code it seems to return the number of 16byte words remaining!

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while( \*pucStackByte == tskSTACK\_FILL\_BYTE )  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pucStackByte -= portSTACK\_GROWTH;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; usCount++;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; usCount /= sizeof( portSTACK\_TYPE );

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return usCount;

posSTACK\_GROWTH is set to -4 by FreeRTOS, so the pointer moves from low to high memory couting 4 bytes at a time until a byte indicating stack has been used.

This is OK but then it adjusts the counter by dividing by 4 and returning this. This appears to be the number of 16 byte words remaining in the stack. Any comments?

Graham

---

<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:** [October 19, 2008, 11:09am UTC](https://forums.freertos.org/t/uxtaskgetstackhighwatermark-problem/63/2 "2008-10-19T11:09:10Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Sunday, October 19, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/05c78107/#c09c/af70):

Oops, my bad.&nbsp; portSTACK\_GROWTH should be set to -1, not -4.

I have corrected this in the SVN head revision and it will get included in the next release.

Thanks for pointing this out.

Regards.
