Howto Define a Variable type In Specific Memory Region

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

Howto Define a Variable type In Specific Memory Region

715 Views
tunayan
Contributor II

Dear All,

 

I am using MPC5644A dev kit. I have a problem about memory relocation.

Is there any way to define "volatile const" variables in predefined memory region with LCF?

 

I can solve that issue with below example:

 

#pragma explicit_zero_data on #pragma push #pragma section sconst_Type const_type ".__Cal_DataArea" ".__Cal_DataArea"    const uint8_T acuc_DC_override_en = 1U;   const real32_T acuc_DC_override_val = 0.0F;   #pragma pop

 

But i dont need that.  Because with that method , i need to write these pragmas before all variables. I have too many variables in different places. So is there any way to wirite on LCF sth and define all volatile consts to specific area?

Thanks all.

Labels (1)
1 Reply

425 Views
stanish
NXP Employee
NXP Employee

Hello Tuna Ayan,

I'm afraid that CW linker cannot distinguish between constant vs. volatile constant.

I'd recommend you to use __declspec(section ... ) instead of #pragma section + push/pop. since it's easier to replace it with macro:

e.g. you can add the statements below into your prefix .h file or into a custom .h file that is included into each source file :

prefix.h

-----------

#pragma section R ".__Cal_DataArea" ".__Cal_DataArea"

#define VOLATILE_CONST __declspec(section ".__Cal_DataArea") volatile const

Now in all the source files where you declare a volatile constant just replace keyword "volatile const" with "VOLATILE_CONST"

VOLATILE_CONST char hello[]= "Hello World!";

and all these constant will be placed into ".__Cal_DataArea" section.

Note: If a constant is not referenced in the code you should instruct the linker to avoid dead-stipping this symbol e.g. in .lcf file, FORCEACTIVE { "hello" }

Hope it helps.

Stan