AnsweredAssumed Answered

confusion with data_seg and flash variable

Question asked by rahul krishna on Mar 2, 2015
Latest reply on Mar 2, 2015 by rahul krishna

i am not able to understand the following problem

The aim of the project is to put a variable in the Flash memory at a particular address

For example: in PAGE_E0_0 at the first address 0xE08000

To execute that i have seen (then written) the following code

suppose in the linker file

SEGMENTS

PAGE_E0_0     = READ_ONLY   0xE08000 TO 0xE087FF;

END

PLACEMENT

PARAMETER INTO PAGE_E0_0

END

In the main file

int main(void)

{

#pragma DATA_SEG __GPAGE_SEG CALIB_PARAMS

unsigned char PARAMETER;

#pragma DATA_SEG DEFAULT

}

 

If I write the above code I can see in the map file  that the variable PARAMETER is placed in the address 0xE0800 (as i wanted) . But my doubt is as you can see the variable PARAMETER is defined in the Flash memory then why you want to write the following

#pragma DATA_SEG __GPAGE_SEG CALIB_PARAMS

unsigned char PARAMETER;

#pragma DATA_SEG DEFAULT

specifically the DATA_SEG keyword. what is the meaning of the keyword DATA_SEG when the variable is placed in the Flash memory. It is basically used for RAM variables i think.

In case if i assume that the DATA_SEG is wrong and write something like this

#pragma CODE_SEG __GPAGE_SEG CALIB_PARAMS

unsigned char PARAMETER;

#pragma CODE_SEG DEFAULT

Then the variable is not placed in the expected memory location that is in PAGE_E0_0 but in some default ROM memory location which i did not want. Please help me to understand this? Is it legal that #pragma DATA_SEG can be used for flash variables.

 

thanks in advance

Outcomes