Initialize const data to zero

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

Initialize const data to zero

Jump to solution
2,262 Views
RValls
Contributor III

Hi everyone! I'm having an isue with the initialization of constant data to zero:

 

I have got a section wich is mapped to ROM, and in this section there is only one constant variable initialized to zero. The problem is that this information is not written to the .bin file generated by the compiler so when I donwload it to the device, it is initialized to 0xFFFFFFFF (not initialized, just the memory erased).

The mapping and the .lcf is correct, because if I initialize this variable to 1, it appears in the .bin file, and when I debug, it is correctly initialized.

 

Any idea of what is happening?

 

I am using CodeWarrior V 6.4 and a Coldfire 52233 device.

 

.lcf:

----------------------------------------------------------------------------
    vectorrom  (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000800
    rom     (RX) : ORIGIN = 0x00000800, LENGTH = 0x0003F000
    persVars (RX) : ORIGIN = 0x0003F800, LENGTH = 0x00000800

 

                     . . .

 

    .persisteVariables:
    {
     ___DIR_RAM_PERSISTENT_VARS_START = .;
     *(persistVars)
     ___DIR_RAM_PERSISTENT_VARS_END = .;
     . = ALIGN (0x10);
    } > persVars

 

---------------------------------------------------------------

In ConstantVars.c:

 

#pragma define_section persistentVars "persistVars" far_absolute R
#pragma force_active on

__declspec(persistentVars) uint32 ROM_contrast_level=0; //Almacena el nivel de contraste del dispositivo (de 0 a 15)
//Mismas variables en RAM.
uint32 contrast_level;

#pragma force_active off

 

I tried with force_active, but it is not necessary because it is already in use (anyway, it appears in the map file) .

 

Why if I initialize it to 1 it appears in the .bin file, and in the debugger is correctly programmed and if I initialize to 0 it doesn't?

 

Thanks everyone for the help,

Rubén

Labels (1)
0 Kudos
1 Solution
603 Views
CrasyCat
Specialist III

Hello

 

Did you try to specify the pragma explicit_zero_data prior to the constant definition?

 

#pragma define_section persistentVars "persistVars" far_absolute R
#pragma force_active on

__declspec(persistentVars) uint32 ROM_contrast_level=0; //Almacena el nivel de contraste del dispositivo (de 0 a 15)
 

#pragma explicit_zero_data on

 

//Mismas variables en RAM.
uint32 contrast_level;

 

#pragma explicit_zero_data off

#pragma force_active off

 

CrasyCat

 

View solution in original post

0 Kudos
3 Replies
604 Views
CrasyCat
Specialist III

Hello

 

Did you try to specify the pragma explicit_zero_data prior to the constant definition?

 

#pragma define_section persistentVars "persistVars" far_absolute R
#pragma force_active on

__declspec(persistentVars) uint32 ROM_contrast_level=0; //Almacena el nivel de contraste del dispositivo (de 0 a 15)
 

#pragma explicit_zero_data on

 

//Mismas variables en RAM.
uint32 contrast_level;

 

#pragma explicit_zero_data off

#pragma force_active off

 

CrasyCat

 

0 Kudos
603 Views
RValls
Contributor III

Thank you CrasyCat! It works fine. Now the variable is placed in persistVars section instead in bss section and initialized to 0.

Thank you again,

Rubén

0 Kudos
604 Views
RValls
Contributor III

Ohh I don't even know that that directive exists. I will try it next week (I'm now on holidays) and tell you...

 

Thanks about the tip,

Rubén

0 Kudos