HC12: RAM Initalization Qu

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

HC12: RAM Initalization Qu

Jump to solution
1,624 Views
NZ_Design
Contributor I
Im using a MC9S12DP256 processor
 
1. My ICC compiler would automatically generate code to initalize variables if I decleared it as such
 
uchar cTemp = 12;
 
cTemp would contain 12 I cannot see any code added. Also if I write my own init routine the system works correctly. Is the a switch or something I need to allow this to happen. This is in Internal processor RAM.
 
.prm file declears it as such
   RAM = READ_WRITE 0x1000 TO 0x3FFF;
   DEFAULT_RAM                  INTO RAM;
 
I also have bettery backed external ram. It is decleared as such
 
   /* banked RAM */
   PAGE_10 = NO_INIT    0x104000 TO 0x107FFF;
   PAGE_11 = READ_WRITE 0x114000 TO 0x117FFF;
   PAGE_12 = READ_WRITE 0x124000 TO 0x127FFF;
   PAGE_13 = READ_WRITE 0x134000 TO 0x137FFF;
   PAGE_14 = READ_WRITE 0x144000 TO 0x147FFF;
   PAGE_15 = READ_WRITE 0x154000 TO 0x157FFF;
   PAGE_16 = READ_WRITE 0x164000 TO 0x167FFF;
   PAGE_17 = READ_WRITE 0x174000 TO 0x177FFF;
   PAGE_18 = READ_WRITE 0x184000 TO 0x187FFF;
   PAGE_19 = READ_WRITE 0x194000 TO 0x197FFF;
   PAGE_1A = READ_WRITE 0x1A4000 TO 0x1A7FFF;
   PAGE_1B = READ_WRITE 0x1B4000 TO 0x1B7FFF;
   PAGE_1C = READ_WRITE 0x1C4000 TO 0x1C7FFF;
   PAGE_1D = READ_WRITE 0x1D4000 TO 0x1D7FFF;
   PAGE_1E = READ_WRITE 0x1E4000 TO 0x1E7FFF;
   PAGE_1F = READ_WRITE 0x1F4000 TO 0x1F7FFF;    
   BATTERY_RAM                  INTO PAGE_11,PAGE_12,PAGE_13,PAGE_14,PAGE_15,PAGE_16,PAGE_17,
                                     PAGE_18,PAGE_19,PAGE_1A,PAGE_1B,PAGE_1C,PAGE_1D,PAGE_1E,PAGE_1F;
   PROGRAM_RAM                  INTO PAGE_10;
The program ram is the one I are concerned about at present.
 
I have a variable that has a dat value of 255 and 253 in it and I are looking for these values at start up. They are there before reset but cannot be found at startup. The page is set so as it doesn't initalize the variables. The access to the external ram is working as I can mut valid data in the memory and read it off correctly.
 
It seems to me the bit of data I wont to keep I cant and the bit I dont wont I can.
 
does anyone have a surgestion or come accross something simalar.
 
 

Message Edited by CrasyCat on 2007-04-13 11:21 AM

Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
602 Views
CrasyCat
Specialist III
Hello
 
Not sure what you mean with ICC compiler.
Answer below will assume you are using a CodeWarrior for HC12.
 
Code to copy initialization values from ROM to RAM is usually included in the startup module start12.c.
You just have to make sure you are using the ANSI C startup (not minimal startup) when you are
creating your project.
 
If you have already created your project with minimal startup, remove option -D__ONLY_INIT
from the compiler command line.
For sure this is valid only if you are using the standard startup code delivered with CodeWarrior.
 
I hope this helps.
 
CrasyCat

View solution in original post

0 Kudos
Reply
2 Replies
603 Views
CrasyCat
Specialist III
Hello
 
Not sure what you mean with ICC compiler.
Answer below will assume you are using a CodeWarrior for HC12.
 
Code to copy initialization values from ROM to RAM is usually included in the startup module start12.c.
You just have to make sure you are using the ANSI C startup (not minimal startup) when you are
creating your project.
 
If you have already created your project with minimal startup, remove option -D__ONLY_INIT
from the compiler command line.
For sure this is valid only if you are using the standard startup code delivered with CodeWarrior.
 
I hope this helps.
 
CrasyCat
0 Kudos
Reply
602 Views
Lundin
Senior Contributor IV
As a comment, good programming practice in embedded systems is to not initialize your global/static variables at startup but rather in runtime before they are to be used. In some systems it may take weeks or even years before the variables are used. It is not wise to rely on the init values placed in RAM cells after such a long period of time.

ANSI C states that globals/statics are set to zero unless you init them explicitly, but if we ignore that feature and init them in runtime, we will get a much safer system. And since you are likely using a microcontroller and not some RAM-based system which the C standard was designed for, there is no such thing as pre-programmed init values. They need to be copied from ROM to RAM at some point.

By skipping the init at startup you can also get rid of the pesky start12.c which does nothing useful except setting the init values. Simply write your own reset vector, set the stack pointer inside it, as well as INITRM and similar registers, then call main() from there.