Padding the task stack with 0xA5

Hi, At task stack Init, The stack is padding with 0xA5. The function prvTaskCheckFreeStackSpace() seerch for 0xA5 to know the stack memory usage at any point of time. When there is a “Pop” data from stack (data goes out from task stack), Is the data is padd back to 0xA5 ? And if yes, Where this padding process is happened ?

Padding the task stack with 0xA5

No. The idea of filling with a known (and unlikely) value, is it lets you look at the stack and be able to see the ‘high water mark’, the maximum usage of the stack. If you want to know the current usage, you would just use the value of the stack pointer, no need to look at the contents of the stack.

Padding the task stack with 0xA5

Richard Thank you very much ! So if I understand good – at system run time – it is wrong to call the function prvTaskCheckFreeStackSpace() in order to determine the current stack memory usage. And the best way to determine the task stack current memory usage at any time is to use stack pointers like this: Number bytes in use in stack == ( Total stack mem usage in byes – (pxTopOfStack – pxStack))

Padding the task stack with 0xA5

prvTaskCheckFreeStackSpace() purpose is to tell you how much excess stack space (based on current execution profile) the task has over the full run, not the amount of free space at the moment. This is the value that you generally want to monitor to adjust stack sizes for creation of the tasks. If you want to know how much stack space you have at the moment, perhaps to decide if you can do some stack intensive operation, you would want to take the differenece of the stack pointer (either the stack pointer register to determine for the current stack, or the stack pointer in the TCB for another stack) and the maximal stack extent allowed (depends on stack growth direction),

Padding the task stack with 0xA5

Ok Richard. Thank you !

Padding the task stack with 0xA5

Michael – I recommend you invest some time in reading the free-to-download book. It doesn’t yet cover the latest features, but it will give you a good grounding on using the RTOS: https://www.freertos.org/Documentation/RTOS_book.html

Padding the task stack with 0xA5

Thank you Richard