record the maximal usage size of the stack space

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

record the maximal usage size of the stack space

跳至解决方案
843 次查看
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

标签 (1)
0 项奖励
1 解答
578 次查看
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 项奖励
4 回复数
578 次查看
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 项奖励
579 次查看
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 项奖励
578 次查看
cyli
Contributor I

Hi,

Thank!

I think it's a good way.

I will try in my code.

Regards.

Li

0 项奖励
578 次查看
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 项奖励