How to verify safe stack usage on KL17?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to verify safe stack usage on KL17?

1,653件の閲覧回数
rickstuart
Contributor V

We are about mid point in our development and would like to test if our stack usage is safe (not close to overflowing) on our KL17 processor?  What tools are available to a developer to make this assessment?  We are using the IAR Workbench IDE.

-thanks

タグ(4)
0 件の賞賛
返信
3 返答(返信)

1,524件の閲覧回数
bobpaddock
Senior Contributor III

Moving the stack from the top of RAM to near the bottom is an often over looked method.

When it overflows it will generate an exception rather than silently corrupting things.

Explained here:  Are We Shooting Ourselves in the Foot with Stack Overflow? « State Space 

How to read the stack pointer:

In Generic C, a good tools set should complain about returning the address of a local variable:

/*
* void *CheckStackDepth( void )
* {
* volatile uint32_t dummy; // Put a variable on the stack
* return( (void *) &dummy ); // Return its address - therefore the (approx.) present SP value
* }
*/

In GCC:


static __inline__ void *sp_get(void)
{
void *sp;

__asm__ __volatile__ ("mrs %0, msp" : "=r"(sp));

return( sp );
}

I call sp_get() in IRQs then test and save to a global variable (which in general should be avoided) that will show the stack depth.  Something different would need done if have nested IRQs.


0 件の賞賛
返信

1,524件の閲覧回数
rastislav_pavlanin
NXP Employee
NXP Employee

Hello Rick,

I have used this approach to analyses the stack in my applications:

IAR Stack usage analysis for RX 

and get it really usefull.

regards

R.

0 件の賞賛
返信

1,524件の閲覧回数
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Rick,

I think we have not the tools to check if the stack is safe. But I think you can write the stack with a pattern, then running the code and check if pattern has been changed for the out of  range of stack memory.

Hope it can help you.

BR

Xiangjun Rong