This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Global variable not initialized by __main() function

Hi.

I hope this is the right place to ask to open this question.

I define an initialized variable in my C code, let's say:

...

int MyVariable = 0xDEADABBA;

...

Using a scatter file, I instruct the arm linker to locate my variable "MyVariable" at address 0x04020000 :

LR_RAM_1 RAM_1_START RAM_1_SIZE                  ; load region starts at 0x04020000

{                                                                                     ; start of execution region descriptions

   ER_SRAM8 RAM_1_START SRAM8_SIZE

   {

       * (+RW, +ZI)                                   ; All RW sections and All ZI sections are placed consecutively into this region

   }

....

}

I expect the __main() function to initialize "MyVariable" with value 0xDEADABBA at start time, before my application "main()" function is executed.

However, I can clearly see in my RTL simulation that, for some reasons, MyVariable is not initialized, as if the compiler/linker consider the execution region "ER_SRAM8" as being already initialized (basically as if it was a ROM memory).

How to instruct the ARM linker that any initialized variable placed in execution region "ER_SRAM8" must be initialzed by the __main() function at boot time since this correspond to a SRAM area which by definition does not contain any valid data at boot time ?

Thanks in advance for your answers.

ARM Linker, 5.03 [Build 24]

ARM C/C++ Compiler, 5.03 [Build 24]

Didier C.