Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

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

Posted by awillson on January 15, 2016

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?

Posted by rtel on January 15, 2016

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?

Posted by awillson on January 15, 2016

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?

Posted by rtel on January 16, 2016

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?

Posted by awillson on January 18, 2016

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.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS