Quality RTOS & Embedded Software

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




Loading

Question about Task Stack items

Posted by Dimitry on January 3, 2012
Hi,

MCU: EFM32 (EnergyMicro Cortex M3)
FreeRTOS 7.0.1

I check stack allocation in function xTaskGenericCreate() and pxPortInitialiseStack(), for example:

TOP of stack = 0x200008CC, aligned TOP of stack = 0x200008C8

Aligned TOP of Stack value – 4 bytes(0x200008C4) portINITIAL_XPSR
Aligned TOP of Stack value – 8 bytes(0x200008C0) pointer to task function
Aligned TOP of Stack value – 12 bytesLR
Aligned TOP of Stack value – 16 bytesR12(reserved for use in future)
Aligned TOP of Stack value – 20 bytesR3(reserved for use in future)
Aligned TOP of Stack value – 24 bytesR2(reserved for use in future)
Aligned TOP of Stack value – 28 bytesR1(reserved for use in future)
Aligned TOP of Stack value – 32 bytespointer to parameters, passed to the Task Function
Aligned TOP of Stack value – 36 bytesR11(reserved for use in future)
Aligned TOP of Stack value – 40 bytesR10(reserved for use in future)
Aligned TOP of Stack value – 44 bytesR9(reserved for use in future)
Aligned TOP of Stack value – 48 bytesR8(reserved for use in future)
Aligned TOP of Stack value – 52 bytesR7(reserved for use in future)
Aligned TOP of Stack value – 56 bytesR6(reserved for use in future)
Aligned TOP of Stack value – 60 bytesR5(reserved for use in future)
Aligned TOP of Stack value – 64 bytes (0x20000888)R4(reserved for use in future)

When the Task Function is called by system, firstly a values of R4 and LR is pushed to stack:

void TaskFunction(void *pvParameters)
{
TaskFunction:
0x14c22: 0xb510 PUSH {R4, LR}
.....

Them pushed at address 0x200008C4 (LR) and 0x200008C0 (R4) and completely overwrite the portINITIAL_XPSR and pointer to the task function values.

Does it correct behavior?
Can I analyze the stack area (R1 .. R12 values stored in the stack as reserved in pxPortInitialiseStack() function) after context switch or this area is "not for use"?

Best Regards and thanks for support.




RE: Question about Task Stack items

Posted by Richard on January 3, 2012
The items are pushed onto the stack before the stack is started to allow the stack to be started. That is, the items are popped from the stack during the processor starting the task. Once they have been popped from the stack, and the task is running, the stack frame as initially configured is no longer required and a new stack frame is created by the task function entry code (the compiler generated prologue). The tasks stack frame will overwrite the original stack frame, so this behaviour is correct.

Regards.


[ 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