How to initialize the RAM of  MC9S08SG8?

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

How to initialize the RAM of  MC9S08SG8?

1,846 Views
tao_s
Contributor I

I want to initialize the unused RAM with zero. I got two ideas, need you guys give me more information.

1. The RAM will be initialized in startup code which auto-created when create a new project follow the start dialog. No more hand-writtened code should be added. But i have try it. It seems doesn't work.

2.Modify the *.PRM file as follows
   RAM  =  READ_WRITE   0x0100 TO 0x027F  FILL 0x00;
   It seems has effect. But i want to ensure it is feasible and appropriate. Is there any latent unexpected side effect.

Need more experience from all of you.

Labels (1)
0 Kudos
5 Replies

611 Views
Klined
Contributor I
Hi,

I think the reason it does not work for your case #1 is that the startup code will only zero-out RAM if it is allocated and used by the application.  If you declared global or static variables with no intial value, for instance, then you would probably see that the RAM locations containing those variables would be set to 0x00 after the call to Init(), if __ONLY_INIT_SP is not defined.  Your case #2 seems to work fine for initializing unused RAM to 0x00.

0 Kudos

611 Views
JimDon
Senior Contributor III
It is possible that it will fill the ram only when "burning" the project, but not in the "C" start up code.

0 Kudos

611 Views
tao_s
Contributor I
I have tried case #2 again. But I find it is only effective after downloading the programme to the target board. And it doesn't work when I repower the board. What's up? And how can I initialize the unused RAM to 0x00 permanent. Is there any other method?
0 Kudos

611 Views
Klined
Contributor I
Strange.  I don't see that the zero-out is associated at all with the burn.  In fact, if you uncheck "Run after successful load" from the file load screen, you should see no zero-outs until after you execute Init() by stepping through.  Try this by filling a few memory locations with 0xFF from the debug screen before executing Init().  This I just verified a moment ago.  Code is generated to take care of the zero-out.  Look in the map file, and you can see a section regarding where the zero-out should happen:

Entry point: 0xE07B (_Startup)
_startupData is allocated at 0xE084 and uses 6 Bytes
extern struct _tagStartup {
  unsigned nofZeroOut     3
  _Range   pZeroOut       0x80     1
                          0x100     5
                          0x155     299
  _Copy    *toCopyDownBeg 0xE15C
} _startupData;

In my PRM I have the following statements:

RAM                      =  READ_WRITE   0x0100 TO 0x027F FILL 0x00;

STACKSIZE 0x50

and my app has 5 bytes of global variables stored starting @ 0x100.

My SP after the call to Init() is 0x154, so the zero-out doesn't start until 0x155, as indicated above.  Also, I have seen this zero-out continue to happen across resets and power cycles, as it should.

What is your SP value after the call to Init()?

0 Kudos

611 Views
tao_s
Contributor I
My SP value after the call to Init() is 0x0151. My app has 2 bytes of global variables stored starting @ 0x100.
 
---------------------------------------------------------------------------------------------
STARTUP SECTION
---------------------------------------------------------------------------------------------
Entry point: 0xE07B (_Startup)
_startupData is allocated at 0xE084 and uses 6 Bytes
extern struct _tagStartup {
  unsigned nofZeroOut     3
  _Range   pZeroOut       0x80     128
                          0x100     2
                          0x152     302
  _Copy    *toCopyDownBeg 0xE10A
} _startupData;
 
My prm file
 
SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
    Z_RAM                    =  READ_WRITE   0x0080 TO 0x00FF FILL 0x00;
    RAM                        =  READ_WRITE   0x0100 TO 0x027F FILL 0x00;
    ROM                       =  READ_ONLY    0xE000 TO 0xFFAD FILL 0x83;
 /* INTVECTS             =  READ_ONLY    0xFFC0 TO 0xFFFF; Interrupt Vectors */
END
 
STACKSIZE 0x50
 
 
My app used below for loop to output the RAM value via SCI.
 
     
  for(p=(uint8 *)0x0100; p<= (uint8 *)0x027f;p++)
  {
      SCI_Transmit(*p);
    __RESET_WATCHDOG();
  }
 
I debug my program on a demo board from freescale. And do the following operation.
1)Download the program and init() haven't executed
2)At this point, RAM from 0x0152 to 0x27F is 0x00
3)Click start button to run the program
4)PC RS232 tools received the RAM value as it should
Till now, everything is OK.
 
But.......
1)Pull out the power cable
2)Plug in again
3)The program run after power on reset
4)PC RS232 tools received the strange RAM value. According to the received data, RAM from 0x0152 to 0x27F is 0x80(not 0x00 which I filled) and the RAM from 0x0100 to 0x0151 is not the same result as what
I received above.
 
What's up? Is it feasible use my app to read the RAM value? What's your test environment?
And would you mind giving me your email and making the communication morr convienent?
Thank you for your aspiring response.
 
0 Kudos