CPU hangs up to Cpu_Interrupt when using large structures

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

CPU hangs up to Cpu_Interrupt when using large structures

Jump to solution
1,032 Views
HarryHirn
Contributor I

hi

 

i got a really strange problem...

i am using mc9s12dp512 and cw 5.9 & pe multilink to write an c program

 

i wrote a routine to check some data and compare it with reference data.

therefore i need the reference data and i collected them in structs like this:

 

typedef struct TEST
{
  uint16_t test_number;
  uint8_t from_pin;
  uint8_t to_pin;
  float measurement_voltage;
  uint16_t reference_curve;
} PIN_TEST;

 

my largest test is an array of 41 of these structs.

i got 13 different tests which are compared one after the other.

 

if i step through that code it works quite fine.

but if i try to let it run on its own without braking then it always

make the codewarrior debugger go into halt state and if i step forward i see that it keeps in the following isr

 

ISR(Cpu_Interrupt)
{
  asm(BGND);
}

 

my question now is if i got problems with the memory blocks because of too large contiguos code or is there anything wrong in my code (could be this, but will be hard to find :smileywink: )?

 

maybe theres an unwanted jump through some illegal memory operation bringing the code to the isr?

this is the cpu halt isr for breakpoints and debugging, right?

 

greetings

Labels (1)
0 Kudos
1 Solution
473 Views
Lundin
Senior Contributor IV

Stack overflow? CW will not use struct padding, yet that is 41 * 10 = 410 bytes of data.

Is the array allocated as global or local?

How large is your stack?

 

The CPU halts like that when the program has gone bananas, most likely because it did a jump outside valid program space. It will for example happen if return addresses on the stack are corrupted.

View solution in original post

0 Kudos
3 Replies
474 Views
Lundin
Senior Contributor IV

Stack overflow? CW will not use struct padding, yet that is 41 * 10 = 410 bytes of data.

Is the array allocated as global or local?

How large is your stack?

 

The CPU halts like that when the program has gone bananas, most likely because it did a jump outside valid program space. It will for example happen if return addresses on the stack are corrupted.

0 Kudos
473 Views
HarryHirn
Contributor I

hi

 

thx for your reply

when i read that i remembered that i had a similar problem already...

my array is local and after increasing my stack to 512 instead of 128 :smileysurprised: it now all works like a charm :smileyhappy:

 

thanks for your help!

0 Kudos
473 Views
Lundin
Senior Contributor IV

Since it is so big, I would allocate that array as a global static instead. That way you won't have to worry about the stack, and you can assign a dedicated RAM area to it. This is good practice whenever you are dealing with buffers of any kind.

 

And since it is structs, there is another advantage of allocating it in a dedicated memory area: should the compiler decide to add struct padding (I doubt CW will, but portable code == good code), you will get a "out of space in segment xxx" linker error, instead of a silent stack overflow.

0 Kudos