MC9S08DZ32 - local variable allocation causing reset problem

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

MC9S08DZ32 - local variable allocation causing reset problem

ソリューションへジャンプ
1,461件の閲覧回数
mroczeks
Contributor IV

Hi All,

 

While working with MC9S08DZ32 unit I found some strange issue.

 

Have a look at the function causing the problem:

 

 

U8 eepromSaveAll(EEPROM_DATA_BLOCK * paramBlock,EEPROM_TAddress epp_address){     U8 status;     U8 i = 0;     U8 size = sizeof(EEPROM_DATA_BLOCK);     byte Array[sizeof(EEPROM_DATA_BLOCK)];     (void)memcpy(Array,paramBlock,sizeof(EEPROM_DATA_BLOCK));     while(size)     {         status = EEPROM_SetByte(epp_address++,Array[i]);         size--;         i++;     }     return status;

 

It is causing heavy instability of the system. Every call or every second call causes device reset.

Interesting thing is that when Array array is declared with static the problem disappears:

 

 

static byte Array[sizeof(EEPROM_DATA_BLOCK)];

 

I have had no time to investigate that more deeply. Problem is solved but curosity remains :smileywink:

 

 

Any ideas?

ラベル(1)
0 件の賞賛
返信
1 解決策
1,068件の閲覧回数
mroczeks
Contributor IV

Problem solved. Stack overflow...

元の投稿で解決策を見る

0 件の賞賛
返信
3 返答(返信)
1,068件の閲覧回数
kef
Specialist I

How big is EEPROM_DATA_BLOCK and how big is your stack? Nonstatic Array is allocated on stack...

0 件の賞賛
返信
1,068件の閲覧回数
mroczeks
Contributor IV

EEPROM_DATA_BLOCK is 42 bytes. Stack is 128 bytes. There's a lot code inside so probably stack is overflown. I will have a look at it later but it seems to be clear for me now.

Thanks!

0 件の賞賛
返信
1,069件の閲覧回数
mroczeks
Contributor IV

Problem solved. Stack overflow...

0 件の賞賛
返信