Quality RTOS & Embedded Software

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




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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists