MC9S08DZ32 - local variable allocation causing reset problem

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

MC9S08DZ32 - local variable allocation causing reset problem

跳至解决方案
1,457 次查看
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,064 次查看
mroczeks
Contributor IV

Problem solved. Stack overflow...

在原帖中查看解决方案

0 项奖励
回复
3 回复数
1,064 次查看
kef
Specialist I

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

0 项奖励
回复
1,064 次查看
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,065 次查看
mroczeks
Contributor IV

Problem solved. Stack overflow...

0 项奖励
回复