record the maximal usage size of the stack space

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

record the maximal usage size of the stack space

Jump to solution
835 Views
cyli
Contributor I

Hi, All

I encounter a question recently.

My code will enter abnormal state and execute the wrong operation. I think it may be caused by the overflow of the stack.

I want to record the maximal usage size of the stack space during a long time. May be sereral day.

Is there any methord to do this? And how to do it?

Thanks a lot!

Li

Labels (1)
0 Kudos
1 Solution
570 Views
NavidadRedivivu
Contributor III

One thing you can try is to fill the stack space with a pattern, then run the program and at the end check up to which point the pattern has been overwritten. Of course, there is the risk that the program will write exactly the 'pattern' on the stack, but I guess it will give you a fair estimation anyway. I don't know if this is available on HC12 (last I know, it was realeased on HC08), but Freescale tools provide support for a statical analisys of the maximum stack consumption for a given application. This computation is done at link time and does _not_ take into account situations like calls via function pointers or recurrent calls since the above mentioned scenarios are very hard (even impossible) to compute at compile/link-time. Check the documentation and release notes to see if this is available on HC12.

View solution in original post

0 Kudos
4 Replies
570 Views
bigmac
Specialist III

Hello Li,

 

A similar method of examining whether a stack overflow condition does occur is to initialise a specific, say 16-bit value at the bottom of the stack.  Then at a single position within the main loop, this RAM location can be tested, and if different from the initialised value, a stack overflow event can be flagged during the normal operation of the code.  The test value might then be re-initialised by the test code.

 

Any variables that might be required for the flagging process should be located in zero page RAM, so that they will not be over-written.

 

Regards,

Mac

 

0 Kudos
571 Views
NavidadRedivivu
Contributor III

One thing you can try is to fill the stack space with a pattern, then run the program and at the end check up to which point the pattern has been overwritten. Of course, there is the risk that the program will write exactly the 'pattern' on the stack, but I guess it will give you a fair estimation anyway. I don't know if this is available on HC12 (last I know, it was realeased on HC08), but Freescale tools provide support for a statical analisys of the maximum stack consumption for a given application. This computation is done at link time and does _not_ take into account situations like calls via function pointers or recurrent calls since the above mentioned scenarios are very hard (even impossible) to compute at compile/link-time. Check the documentation and release notes to see if this is available on HC12.

0 Kudos
570 Views
cyli
Contributor I

Hi,

Thank!

I think it's a good way.

I will try in my code.

Regards.

Li

0 Kudos
570 Views
bugfighter
Contributor I

Hi,

any idea of the effect of stack overflow on the HCS12 microcontroller?

I mean, if the microcontroller is out of RAM, any application should go idle until the watchdog resets the micro itself; but what if another interrupt occurrs? Can the stack content alone be reset?

I was just wondering ...

Thank you very much for your help.

Regards

BF

0 Kudos