confusion with data_seg and flash variable

cancel
Showing results for 
Search instead for 
Did you mean: 

confusion with data_seg and flash variable

228 Views
Contributor IV

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

Labels (1)
Tags (3)
0 Kudos
4 Replies

27 Views
NXP TechSupport
NXP TechSupport

hi rahul,

there are several problems in your code.

1, if you need to define constant data in flash, we need use "const" keyword:

const unsigned char PARAMETER;

without const, the data will be defined in RAM.

2. the const data must be defined as global.

3.0xE08000 is paged adderss but not global address, we need to use __PPAGE_SEG instead of __GPAGE_SEG.

4. add global variable to prm ENTRIES section can be avoid optimized.

see attached demo code and video.

can this help?


Have a great day,
Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

27 Views
Contributor IV

Thank you very much for the reply. I did not find the attachment of the video. I have created the following codewarrior project and it is compiling properly, why is not showing any error.  The main task of the project is to put the configuration parameters in the flash memory at known addresses and during the run time read those configuration parameters.

In main.c file

#pragma DATA_SEG __GPAGE_SEG PARAMETERS

unsigned int TESTDATA_1=3;

unsigned int TESTDATA_2=1;

unsigned int TESTDATA_3=2;

unsigned int TESTDATA_4=5;

unsigned int TESTDATA_5=8;

unsigned int TESTDATA_6=0;

#pragma DATA_SEG DEFAULT

void main(void) {

  /* put your own code here */

 

  unsigned int *__far localpointer;

  unsigned int localvalue;

   localpointer = (unsigned int * __far)(&TESTDATA_1);

  localpointer = (unsigned int * __far)(&TESTDATA_2);

  localpointer = (unsigned int * __far)(&TESTDATA_3);

  localpointer = (unsigned int * __far)(&TESTDATA_4);

  localpointer = (unsigned int * __far)(&TESTDATA_5);

  localpointer = (unsigned int * __far)(&TESTDATA_6);

  localvalue = *localpointer;  

}

Linker file

PARAMETERS INTO PAGE_E0_0;

The output of the map file is generating as

TESTDATA_1  E08000 2 2 2 PARAMETERS

TESTDATA_2  E08002 2 2 1 PARAMETERS

TESTDATA_3  E08004 2 2 2 PARAMETERS

TESTDATA_4  E08006 2 2 2 PARAMETERS

TESTDATA_5  E08008 2 2 2 PARAMETERS

TESTDATA_6  E0800A 2 2 1 PARAMETERS

Why it is generating correctly at the expected addresses? Or it is wrong I am not able to understand properly. My concern is i have to place some 200 Variables in Flash from One known fixed location to another fixed location how to do it? The code i have shown is the actual code running in some of my systems should i plan to change the code immediately?

Thanks in advance

0 Kudos

27 Views
NXP TechSupport
NXP TechSupport

hi rahul,

the video is in the zip file of my first post.

regarding your code. can you please upload a demo project so i can check it directly on my side? thanks!


Have a great day,
Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

27 Views
Contributor IV

Thank you. please find the project for review.

Just now i have seen the video, thankyou very much it was very good.

0 Kudos