Compiler option to NOT initialize global variables

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

Compiler option to NOT initialize global variables

5,661件の閲覧回数
SVC
Contributor I

Is there a compiler option that omits initializing the .bss section (global and static variables)?

 
Thanks in advance,
S.
 
ラベル(1)
0 件の賞賛
7 返答(返信)

660件の閲覧回数
Lundin
Senior Contributor IV
This is how to do it (example is for HCS12 but should be similar for any MCU):

In the .prm file, make sure the reset isr is your own custom-made one and not _Startup(). In this example the reset isr is called "interrupt_reset":

#pragma TRAP_PROC
void interrupt_reset(void)
{
  #pragma MESSAGE DISABLE C12053 /* Disable LDS warning */
  asm LDS ... /* set stack pointer */

  (void) main();
}



I strongly recommend doing the above on any Codewarrior program. It will work fine as long as you are aware that your statics/globals aren't initialized any longer.


Reasons to get rid of it (taken from another recent post of mine):

One problem is that the copy-down code will add plenty of "startup-lag" at the beginning of the program. Lets say you have several kb of objects with static storage duration: it will take quite some time before they are set, which might be bad for program performance. But worse: during this time, hardware registers will have out-of-reset values, including the COP register. This might in worst case cause unwanted behavior of the MCU.

One such example is all port I/O pins that are not connected to external resistors. I/O pins are always set as inputs out of reset on Freescale micros. If such pins are exposed to ESD during the startup time the MCU might be damaged, as your code has yet to either set them to outputs or to activate internal pull resistors.

The next problem is electronical: you can never rely on RAM cells during long periods of time. The program might in some cases run for years before a certain variable is used. Therefore, you cannot assume that those variables initialized by the copy-down code still have the correct values when using them.
0 件の賞賛

660件の閲覧回数
CrasyCat
Specialist III
Hello
 
Just my 2 cents on that.
 
That would work fine for HC12 & HC08.
I would not recommend to use it for Coldfire code.
 
Some additional registers needs to be set up appropriately to allow a correct execution of Coldfire code.
 
Initializing only SP may generate very strange side effect.
 
CrasyCat
0 件の賞賛

660件の閲覧回数
allawtterb
Contributor IV
I don't know about your particular version of CodeWarrior, but the compiler option -D__ONLY_INIT_SP will turn off ANSI initialization of globals and statics. It will only initialize the stack pointer and call main.
0 件の賞賛

660件の閲覧回数
SVC
Contributor I
My version is 5.7.0 and I cannot find the information ( D__ONLY_INIT_SP) anywhere.
 
Which document describes this?
 
Thanks,
S.
0 件の賞賛

660件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee
5.7 happens to be the version of the ide, the  editor, and not the product version.
Which target do you use? Which derivative? Which product?

For 8/16 bits (HC08/HC12), placing the .bss section into a NO_INIT segment in the prm file is one way to achieve this.

Daniel
0 件の賞賛

660件の閲覧回数
SVC
Contributor I
I am contemplating in using the MFC5282 as our new platform and trying to achieve a hitless software upgrade (download).
 
Which brings me to my second question (for which I should perhaps open a new thread): is there a utility that will convert the output binary file (COEFF) to ASCII (hex) in order to be able to download the image?
 
Simon
 
0 件の賞賛

660件の閲覧回数
CrasyCat
Specialist III
Hello
 
There is no option to disable code initializing data in CodeWarrior for Coldfire.
If you wish to make sure data are not initialized, you need to create your own startup code, where you do not initialize memory.
 
The startup code is encoded in module
  {Install}\E68K_Support\Runtime\Runtime_68K\Runtime_ColdFire\(Source)\E68k_startup.c,
where {Install} refers to your installation directory.
 
Copy that file to your project directory and insert the required modification.
 
In order to prevent RAM initialization you need to remove the corresponding code from the _Start function.
 
The sections of code you need to comment out are the section between the comment:
 /* zero initialize the .bss section */
 and the label done_picpid_copy
 
I hope this helps.
 
CrasyCat
0 件の賞賛