Initialize const data to zero

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Initialize const data to zero

跳至解决方案
2,967 次查看
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

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,308 次查看
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 项奖励
回复
3 回复数
1,309 次查看
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 项奖励
回复
1,308 次查看
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 项奖励
回复
1,309 次查看
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 项奖励
回复