HCS08 (MC13213), global variable allocation problem!

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

HCS08 (MC13213), global variable allocation problem!

ソリューションへジャンプ
3,263件の閲覧回数
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.

ラベル(1)
0 件の賞賛
返信
1 解決策
1,418件の閲覧回数
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 件の賞賛
返信
4 返答(返信)
1,418件の閲覧回数
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 件の賞賛
返信
1,419件の閲覧回数
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 件の賞賛
返信
1,418件の閲覧回数
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 件の賞賛
返信
1,418件の閲覧回数
CrasyCat
Specialist III

Hello

 

This looks like a COP interrupt is generated.

Please clear the COP interrupt somewhere in the code.

 

CrasyCat

0 件の賞賛
返信