cancel
Showing results for 
Search instead for 
Did you mean: 

How to measure the stack remaining available size

aurelien23
Senior

I had to enhance the stack size using __process_stack_size__ value to make my software running and I would like to know how to measure the stack remaining size. I tried commenting out the ram init in boot.s and fill the stack ram area with a 0x55AA pattern using the debugger, but the area is still initialized. Is there an easy way to know the stack occupied size??

1 ACCEPTED SOLUTION

Accepted Solutions
Giuseppe DI-GIORE
ST Employee

Hello,

indeed stack occupied size depends on the application.

A simple way to know, at runtime if a stack allocated variable is still inside the defined stack memory is:

  1. get the address of the variable
  2. compare it with the top of the stack (note that the stack grows downward)

In sPC5Studio top of the stack is defined in the linker script file (__core0_process_stack_base__)

Also: PowerPC ABI defines R1 register as stack pointer. It can be used to know the occupied stack size by doing:

  • (content of R1) minus (__process_stack_end__)

__process_stack_end__ is defined in linker script.

In SPC5Studio crt0.s file, R1 is initialized with address of __process_stack_end__

Regards,

Giuseppe

PS: unfortunately [PowerPC] FreeGCC compiler does not support -stack-protector option.

View solution in original post

1 REPLY 1
Giuseppe DI-GIORE
ST Employee

Hello,

indeed stack occupied size depends on the application.

A simple way to know, at runtime if a stack allocated variable is still inside the defined stack memory is:

  1. get the address of the variable
  2. compare it with the top of the stack (note that the stack grows downward)

In sPC5Studio top of the stack is defined in the linker script file (__core0_process_stack_base__)

Also: PowerPC ABI defines R1 register as stack pointer. It can be used to know the occupied stack size by doing:

  • (content of R1) minus (__process_stack_end__)

__process_stack_end__ is defined in linker script.

In SPC5Studio crt0.s file, R1 is initialized with address of __process_stack_end__

Regards,

Giuseppe

PS: unfortunately [PowerPC] FreeGCC compiler does not support -stack-protector option.