AnsweredAssumed Answered

HCS08 (MC13213), global variable allocation problem!

Question asked by Zoltan Lengyel on Aug 6, 2009
Latest reply on Aug 10, 2009 by CrasyCat

Please try to find an explanation for this! The situation is as simple as this:

 

1. I create a new project in code warrior 5.9 for MC13213

(ANSI stratup code, small memory model)

 

2. I declare these 2 global arrays:

 

typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;

 

typedef struct datetime_tag {
  uint16_t year;
  uint8_t month;
  uint8_t day;
  uint8_t hours;
  uint8_t minutes;
  uint8_t seconds;
} tDateTime;

 

tDateTime timestamp[96];
uint32_t impulse[96];

3. My main is like this:

 

void main(void) {

 

  SOPT = 0x33;

  impulse[10] = 1;
  timestamp[10].seconds = 1;

 

  for(;:smileywink: {
  } /* loop forever */
  /* please make sure that you never leave main */

 }

 

4. Compile OK + Programming OK + Trying to debug

 

5. !! The program jumps back to INIT_SP_FROM_STARTUP_DESC(); which is in the Start08.c

  What' s this?

 

6. The strangest thing: I declare another global variable: uint8_t DUMMY[2300]; And I put DUMMY[2] = 1; so that the array is really allocated in the RAM.

 

7. Programming, trying to debug -> and the program works fine!!!

 

I really don't understand what is behind this.

Outcomes