Skip to main content
aurelien23
Associate III
December 9, 2020
Solved

How to measure the stack remaining available size

  • December 9, 2020
  • 1 reply
  • 1498 views

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??

    This topic has been closed for replies.
    Best answer by Giuseppe DI-GIORE

    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.

    1 reply

    Giuseppe DI-GIORE
    ST Employee
    January 12, 2021

    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.