incorrect value is read for const variable in banked memory area

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

incorrect value is read for const variable in banked memory area

700 Views
ketanshah
Contributor I

Hello All,

 

in my linker file i have defined as below

 

PAGEF8 0xF88000 to 0xF8BFFF

 

APP_CONST_DATA  INTO PAGEF8

 

 

while i have define a variable in

 

partnumber.c as below

 

#pragma CONST_SEG __PPAGE_SEG APP_CONST_DATA

volatile const partnumber[3]={1,2,3};

#pragma CONST_SEG DEFAULT

 

and in partnumber.h

#pragma CONST_SEG __PPAGE_SEG APP_CONST_DATA

extern volatile const partnumber[3];

#pragma CONST_SEG DEFAULT

 

 

and i trying to read this variable in appfile.c as below, but it is always reading garbage value instead of above mention values. I gave included partnumber.h in appfile.c

 

appdata[0] = partnumber[0];

appdata[1] = partnumber[1];

appdata[2] = partnumber[2];

 

what could be the reason , what am i doing wrong ? I am using HCS12X family controller.

 

 

Kind regards

Ketan

Labels (1)
0 Kudos
5 Replies

418 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

I myself suggest you use __PPAGE_SEG instead of __FAR_SEG . we rarely use it .

__FAR_SEG  is the alias of FAR, while __PPAGE_SEG is the alias of PPAGE.

there are two methods to access paged memory. accessing via PPAGE(paged address) or GPAGE(global address).

I attached two demo code for each of them. can this help you?

Have a great day,

Zhang Jun

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

0 Kudos

418 Views
kef2
Senior Contributor IV
  • I myself suggest you use __PPAGE_SEG instead of __FAR_SEG . we rarely use it .

Zhang, certainly it is a typo and you meant __GPAGE_SEG here. __PPAGE_SEG is not useful for paged data on S12X, unless small memory model is used.

Since __FAR_SEG applied to data is alias for __GPAGE_SEG on S12X, and alias for __PPAGE_SEG on older HC12 and S12 (which lack GPAGE and Gxxx CPU instructions), it makes some sense to use __FAR_SEG, if you want better code compatibility and want to use same code on both HC12/S12 and S12X.

  • there are two methods to access paged memory. accessing via PPAGE(paged address) or GPAGE(global address).

Right. But unless small memory model is used, accessing paged data via PPAGE is very slow.

0 Kudos

418 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

hello, there is some misunderstanding (maybe i didn't say it clear ). i don't suggest use __FAR_SEG is not because it uses GPAGE. but because it is rarely used in HCS12x family.  at least among my customer, because HCS12X has keyword __GPAGE_SEG which is specially designed for HCS12X family for global access. Using __GPAGE_SEG is more clear and readable for programmer.

__FAR_SEG is used in HCS12, HCS12X, HC12 and even HCS08 and RS08.   If user considers porting code for these different platforms, yes, __FAR_SEG wins.


Have a great day,
Zhang Jun

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

0 Kudos

418 Views
kef2
Senior Contributor IV

On S12X you should use GPAGE to access data from P-paged memory. Just replace __PPAGE_SEG to __GPAGE_SEG in your code.

0 Kudos

418 Views
ketanshah
Contributor I

Thanks for the reply, this works.

But I also tried as below and that also works, could you please tell which one is better ?

partnumber.c  as below

#pragma CONST_SEG __FAR_SEG APP_CONST_DATA

volatile const UNUM8  __far partnumber = {1,2,3};

#pragma CONST_SEG DEFAULT

partnumber.h as below

#pragma CONST_SEG __FAR_SEG APP_CONST_DATA

volatile const UNUM8 __far partnumber[3];

#pragma CONST_SEG DEFAULT

0 Kudos