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.
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.
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.