I have some problem in far pointer use on hy64 microcontroller: I defined a banked flash section and put a const varible in it;

I have some problem in far pointer use on hy64 microcontroller: I defined a banked flash section and put a const varible in it; and I want to know the address of this const varible, so I defined a varible to get the address, but it does't work well. my code is like this:

#define uint16 unsigned int

#pragma const_seg bank_flash1

const uint16 CheckHead = 0x22AA;

#pragma const_seg default

void ValuleCheck(void)

{

uint16 * far Value1;

volatile uint16 Value2;

Value1 = CheckHead;

Value2 = * Value1;

}

the bank_flash1 in .prm file is defined as 0x0efbc0~0x0efbc1

and every time the Value2 is not the const value ,it is just the value of the page of unbanked

You need to add -CpPPAGE to compiler command line. It seems being missing creating new empty S12HY project in CW5.0.

It is not enough to place you const in non default placement, you need to tell compiler that special steps (switching PPAGE) should be done to access your variable. This is why you either need __PPAGE_SEG in #pragma or far in your var definition. I recommend using __PPAGE_SEG. Please note that you need to use __PPAGE_SEG or far also in your header files while declaring your paged vars to other source modules. For example

//Your H file

#pragma CONST_SEG __PPAGE_SEG bank_flash1

extern const uint16 CheckHead;

#pragma CONST_SEG default

Radek,

Since there's no paged (far) RAM on S12HY, FAR_DATA define is not required. It makes startup code slower, but able to initializing paged RAM variables properly. Not relevant for const's.