How to see upper/lower bound of a task’s stack?

Hello, I am working on a RAM test routine that needs to skip the current RTOS task’s stack. How can I retrieve the current task’s upper/lower stack boundary? Thanks!

How to see upper/lower bound of a task’s stack?

This is not easy at the moment, although we are already working on a function that will extend the uxTaskGetSystemState() function to return stack boundaries too (and to allow it to be called on a task by task basis) – plus the current head revision allows task stacks to be allocated statically so you always know where they are. In the mean time, assuming you are using an architecture for which the stack grows down, you can obtain the limit of the stack by adding the following function to the tasks.c. You pass in a task handle, or NULL if you are querying the stack limit of the calling task. The stack size will be known as it was a parameter passed into the function that created the stack (in words, not bytes!). ~~~~ StackTypet *pxTaskGetStackStart( TaskHandlet xTask ) { TCB_t *pxTCB;
/* If null is passed in here then it is the stack of the calling task that
is being queried. */
pxTCB = prvGetTCBFromHandle( xTask );
return ( pxTCB->pxStack );
} ~~~~

How to see upper/lower bound of a task’s stack?

Hello RTE. I’m getting a hardfault on the return() statement. Are you sure this pointer is dereferenced correctly? Also, the handle which I pass to this GetStackStart() function, is the handle which is returned to me by xTaskCreate() – correct?
vBISTSRAM1_Task_handle = xTaskCreate(vBISTSRAM1_Task, 
    (const char *) "vTaskBISTSRAM1",
    configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 1UL),
    (xTaskHandle *) NULL);

...
        SRAM_BIST_Test(pxTaskGetStackStart(vBISTSRAM1_Task_handle), configMINIMAL_STACK_SIZE);
Thanks for your assistance.

How to see upper/lower bound of a task’s stack?

I didn’t actually try running the code, just typed it into the post, but it looks ok. I suspect your problem is to to the following comments –
Also, the handle which I pass to this GetStackStart() function, is the handle which is returned to me by xTaskCreate() – correct?
No! Please read the documentation for the xTaskCreate() API function – the handle is passed out using the last parameter. The return value is simply a pass/fail indication, not a pointer. http://www.freertos.org/a00125.html

How to see upper/lower bound of a task’s stack?

Thanks for your help. I mis-read the xTaskCreate() definition, sorry about that. The code you provided is working fine, and all is well now.