Strange stack behaviour question.

Hi,

It's about the STM32F103. Due to my previous post my application first fills all (at that moment) free stack memory locations with a value of 0x55555555. This all works fine so does the application. I can monitor the stack behaviour in the Memory1 debug window.

But what I see is that at a certain moment data is placed in the stack at some location leaving some gaps of 2 to 10 times (32-bits) dwords containing 0x55555555.

The stack grows downwards in memory addresses.
For example I see: (highest memory on top)

Address Data
0xnnnnnnnn-0 data start of stack
0xnnnnnnnn-1 data
0xnnnnnnnn-2 data
0xnnnnnnnn-3 0x55555555
0xnnnnnnnn-4 0x55555555
0xnnnnnnnn-5 data
0xnnnnnnnn-6 data
0xnnnnnnnn-7 0x55555555
0xnnnnnnnn-8 data
0xnnnnnnnn-9 data
0xnnnnnnnn-10 0x55555555
0xnnnnnnnn-12 0x55555555
until
0xnnnnnnnn-nn 0x55555555 end of stack

I do use many interrupt handlers.
Is there an explanation for this or is my application buggy?

Thanks

Henk

Parents
  • Hi,

    I investigated it a little more and found out that you are right.

    The specific (first) function allocates memory for a structure with that structure containing a non initialized buffer of 255 bytes. Then a second function is called with the address of this structure as an argument...

    I declared this structure as static and now the stack memory does not show this 'gaps'. Also declaring the buffer as static will speed up the program execution I think because the microcontroller does not have to copy and uncopy this buffer to and from the stack when entering or leaving the second function.

    regards,

    Henk

Reply
  • Hi,

    I investigated it a little more and found out that you are right.

    The specific (first) function allocates memory for a structure with that structure containing a non initialized buffer of 255 bytes. Then a second function is called with the address of this structure as an argument...

    I declared this structure as static and now the stack memory does not show this 'gaps'. Also declaring the buffer as static will speed up the program execution I think because the microcontroller does not have to copy and uncopy this buffer to and from the stack when entering or leaving the second function.

    regards,

    Henk

Children
More questions in this forum