data in memory after compilation and link

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

data in memory after compilation and link

1,349 Views
Pang
Contributor I
Enir.: CW4.5 and MC9S12XDP512
 
Problem:
 
#include ...
 
int i = 5;
 
void main(...)
{
....
}
 
Since I am not familar with the Principle of Compiler and Linker, I am wondering, when MCU starts running, will it run a machine code to assign 5 to the memory of i or 5 has already been put into the mory of i after CW debugger loads the program into S12X system.
 
Thanks a lot for any inputs.
 
Pang
Labels (1)
Tags (1)
0 Kudos
3 Replies

371 Views
CrasyCat
Specialist III
Hello
 
When you are using CodeWarrior for HC12, the default startup code we are delivering is initializing the global variable to their initialization value automatically.
 
Just make sure:
  1 - You have created your project using the wizard (or a stationery)
  2- You did select "ANSI C startup" in the wizard when you have created the project.
 
If you are not sure about item 2 above, just check the Compiler for HC12 commend line:
  - Start the IDE
  - Open the project
  - Open the target settings dialog (press ALT+F7)
  - Switch to "Compiler for HC12" panel.
    If you see the option -D__ONLY_INIT_SP this is wrong.
    Just remove that option from the command line and you should be fine.
 
And make sure you are using the startup code we are delivering (module is called start12.c). 
I hope this helps.
 
CrasyCat

371 Views
Pang
Contributor I
I did both steps as you said. There is no that option -D__ONLY_INIT_SP in "Compiler for HC12"
 
Do you mean the gobal variable is defined for the system instead of the global variables declared for my application.
 
My case is like that. when power outage occurs, I have to decide whether my application restarts completely or returns to where it was before power outage. If the duration is longer than 2 seconds, it will go to restart, otherwise return to where it was. I don't have a problem with restart, but I do have a problem with returning back. Remember that, There is a hug capacitor on board so that it can hold power for memory about 5 minutes.
 
When power surge occurs (less than 2 seconds), my application should go back where it was. So it will skip all my application's initializations and jump to its main loop. It appears that I missed something when I make a jump. Therefore, I want to learn if it will keep my data in the memory intact after MCU has been reset by CPU RESET.
 
Do you have any other concerns and advice about power surge and system restart?
 
Thanks,
 
Pang
 
0 Kudos

371 Views
CrasyCat
Specialist III
Hello
 
I am not sure I understand what you are trying to achieve here.
 
When you want to continue where you were previously, this is usually not the Startup code, but some other place in the application.
So In my opinion you are not running the Startup code again in that situation.
 
If you are not able to continue from where you where, it might be that the processor entered an un-determined state that you cannot recover from.
Also I am not sure whether (and how long) the hardware keeps the content of the RAM.
You might have lost the content of the stack or the value of the global variable at that time.
 
 
CrasyCat