pxStack, pxEndOfStack

osmonnb wrote on Thursday, September 26, 2019:

StackType_t		*pxStack;		/*Points to the start of the stack*/
StackType_t		*pxEndOfStack;	/*Points to the highest valid address for the stack*/

As I understand, stack grows from high address to low address, e.g starts from 0x0000FFFF as base, then to 0x0000FF00

So, is 0x0000FFFF pxStack, or pxEndOfStack?
Because it says pxEndOfStack points to the highest valid address…

richard_damon wrote on Thursday, September 26, 2019:

FreeRTOS is designed to work on MANY different processors. Some grow the stack from High to Low, and some grow the stack from Low to High.

You will notice that the definition of pxEndOfStack is conditional on ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) ) so only if those are defined. portSTACK_GROWTH is set to a positive number if the stack grows from low values to hight values and a negative number if the stack grows from high values to low values. onfigRECORD_STACK_HIGH_ADDRESS can be set if the application for some reason wants to know the top end of the stack for some reason even if the stack is growing downwards.

pxStack will point to the lowest address of the stack, that is the address that was obtained from memory allocation (and the address given to free the stack).

pxEndOfStack stores the highest address in the stack to allow checking for stack overflow in upwards growing stacks, or it could be used on machines with downward growing stacks to compute how much stack is actually being used (vs how much is left).

In your example, pxEndOfStack would have the value like 0x0000FFFF, the highest valid address in the stack (or perhaps rounded down to match the alignment restrictions of StackType_t)