MC9S08DZ32 - local variable allocation causing reset problem

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

MC9S08DZ32 - local variable allocation causing reset problem

Jump to solution
905 Views
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?

Labels (1)
0 Kudos
Reply
1 Solution
512 Views
mroczeks
Contributor IV

Problem solved. Stack overflow...

View solution in original post

0 Kudos
Reply
3 Replies
512 Views
kef
Specialist I

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

0 Kudos
Reply
512 Views
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 Kudos
Reply
513 Views
mroczeks
Contributor IV

Problem solved. Stack overflow...

0 Kudos
Reply