uxTaskGetStackHighWaterMark problem?

grahamfclark wrote on Sunday, October 19, 2008:

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!

        while( *pucStackByte == tskSTACK_FILL_BYTE )
            pucStackByte -= portSTACK_GROWTH;

        usCount /= sizeof( portSTACK_TYPE );

        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?


rtel wrote on Sunday, October 19, 2008:

Oops, my bad.  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.