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

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

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

Jump to solution
1,597 Views
hongjianzhang
Contributor III

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

Labels (1)
1 Solution
1,442 Views
RadekS
NXP Employee
NXP Employee

Hi Hongjian,

Few notes for you:

1. Address 0x0efbc0 is not valid. The flash memory window is in range 0x8000~0xBFFF. So, banked address for page 0x0E should be in range 0x0E8000~0x0EBFFF

2. You should define __FAR_DATA for support initializing of paged memory (Alt+F7, Compiler for HC12, add “-D__FAR_DATA”). Note: This is necessary mainly for variables

3. You should also put CheckHead into ENTRIES section in prm file for avoiding optimizing out as an unused object. For example:

ENTRIES /* keep the following unreferenced variables */

CheckHead

END

If your constant is directly referenced in your code, this is not necessary.

4. The “const_seg” and “default” must be written with upper cases. For example: #pragma CONST_SEG DEFAULT

5. I would like to recommend to keep this rule also for your user segment name – just for better readability. For example: #pragma CONST_SEG BANK_FLASH1

6. You didn’t specify your modifications in prm file. Here is example of prm file modifications for your reference:

  a)

SEGMENTS

//…

      //PAGE_0E      = READ_ONLY  0x0E8000 TO 0x0EBFFF;

PAGE_0E_8000  = READ_ONLY  0x0E8000 TO 0x0E80FF;

PAGE_0E      = READ_ONLY  0x0E8100 TO 0x0EBFFF;

//…

END

  b)

PLACEMENT

//…

    BANK_FLASH1      INTO PAGE_0E_8000;

//…

END

  c)

ENTRIES /* keep the following unreferenced variables */

CheckHead

END


I hope it helps you.

Have a great day,
RadekS

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

View solution in original post

0 Kudos
Reply
4 Replies
1,442 Views
kef2
Senior Contributor V

Thanks for providing (almost) compileable code with all things like uint16 defined!

#define uint16 unsigned int

#pragma CONST_SEG __PPAGE_SEG bank_flash1 // CONST_SEG must be upper case.

                                                                                      // Regarding __PPAGE_SEG see below

const uint16 CheckHead = 0x22AA;

#pragma CONST_SEG DEFAULT

void ValuleCheck(void)

{

     uint16 * far Value1;

     volatile uint16 Value2;

     Value1 = & CheckHead;            // & was missing

      Value2 = * Value1;

}

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.

1,442 Views
hongjianzhang
Contributor III

Really Thank you

The day laterly I define the const varible like this

#pragma COSNT_SEG BANK_FLASH1

const uint16 far CheckHead = 0x22AA;

#pragma CONST_SEG DEFAULT

and it works,it's like what you say the second method

0 Kudos
Reply
1,443 Views
RadekS
NXP Employee
NXP Employee

Hi Hongjian,

Few notes for you:

1. Address 0x0efbc0 is not valid. The flash memory window is in range 0x8000~0xBFFF. So, banked address for page 0x0E should be in range 0x0E8000~0x0EBFFF

2. You should define __FAR_DATA for support initializing of paged memory (Alt+F7, Compiler for HC12, add “-D__FAR_DATA”). Note: This is necessary mainly for variables

3. You should also put CheckHead into ENTRIES section in prm file for avoiding optimizing out as an unused object. For example:

ENTRIES /* keep the following unreferenced variables */

CheckHead

END

If your constant is directly referenced in your code, this is not necessary.

4. The “const_seg” and “default” must be written with upper cases. For example: #pragma CONST_SEG DEFAULT

5. I would like to recommend to keep this rule also for your user segment name – just for better readability. For example: #pragma CONST_SEG BANK_FLASH1

6. You didn’t specify your modifications in prm file. Here is example of prm file modifications for your reference:

  a)

SEGMENTS

//…

      //PAGE_0E      = READ_ONLY  0x0E8000 TO 0x0EBFFF;

PAGE_0E_8000  = READ_ONLY  0x0E8000 TO 0x0E80FF;

PAGE_0E      = READ_ONLY  0x0E8100 TO 0x0EBFFF;

//…

END

  b)

PLACEMENT

//…

    BANK_FLASH1      INTO PAGE_0E_8000;

//…

END

  c)

ENTRIES /* keep the following unreferenced variables */

CheckHead

END


I hope it helps you.

Have a great day,
RadekS

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

0 Kudos
Reply
1,442 Views
hongjianzhang
Contributor III

I am sorry for the mistake that I pushed before, I worked in company and when I went home, I push this question and I didn't use the code in company, so I didn't realize I had made these mistakes.

Also thank you for answered my question

0 Kudos
Reply