HCS08 (MC13213), global variable allocation problem!

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

HCS08 (MC13213), global variable allocation problem!

Jump to solution
2,433 Views
zoz
Contributor I

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.

Labels (1)
0 Kudos
1 Solution
588 Views
CrasyCat
Specialist III

Hello

 

In fact the more global variables you define, the longer the startup code will need to initialize them.

 

If you really have a large amount of global variables in your application you may want to add option -D_DO_FEED_COP_  to your command line when building start08.c.

 

This will add code to feed the COP in the startup function itself and prevent the COP reset.

 

CrasyCat

View solution in original post

0 Kudos
4 Replies
588 Views
zoz
Contributor I

Thanks for the replies, I had to put

    __RESET_WATCHDOG();
   

before my first line:
   SOPT = 0x33; 

 

and this solved the problem!!!

 

I find it little bit strange though. The amount of allocated global variables in RAM had an influence on this.

0 Kudos
589 Views
CrasyCat
Specialist III

Hello

 

In fact the more global variables you define, the longer the startup code will need to initialize them.

 

If you really have a large amount of global variables in your application you may want to add option -D_DO_FEED_COP_  to your command line when building start08.c.

 

This will add code to feed the COP in the startup function itself and prevent the COP reset.

 

CrasyCat

0 Kudos
588 Views
bigmac
Specialist III

Hello, 

 


zoz wrote:

 

 

5. !! The program jumps back to INIT_SP_FROM_STARTUP_DESC(); which is in the Start08.c. What' s this?


This indicates that a reset has occurred.  You would need to examine the SRS register for the source of the reset.

 

I tested your code fragment under full chip simulation, without any problem.

 

Regards,

Mac

0 Kudos
588 Views
CrasyCat
Specialist III

Hello

 

This looks like a COP interrupt is generated.

Please clear the COP interrupt somewhere in the code.

 

CrasyCat

0 Kudos