Accessing Banked constants from other Paged memory

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

Accessing Banked constants from other Paged memory

11,264 Views
Vicky
Contributor I
 
Hi,
I am using Code warrior HC12 V2.0. I have placed constant in banked memory and wanted to access the same constant from the code which is residing in another page memory. I am not able to access it, please let me know what could be the problem and let me know the steps also.
 
Thanks in advance.
 
Regards,
Vignesh
Labels (1)
0 Kudos
Reply
10 Replies

2,586 Views
Vicky
Contributor I
Hi Alvin,
I am using MC9S12DP256B and Code warrior CW2.0 version.
 
Issue is:
1. Constant is in Page 0x35, and I am using Ansi Library. But none of the functions like memcpy, strncpy are none working as expected i.e., value is not copied from source to destination.
 
Few solutions I tried:
1. modified libdefs.h file to support far pointer
2. modified datapage.c to enable PPAGE
3. Enable -CpPPAGE=RUNTIME in compiler option.
 
Even then also, its not working.
 
Please let me know, if I have missed any thing else...
 
 
Thanks,
Vicy
0 Kudos
Reply

2,586 Views
CrasyCat
Specialist III

Hello Vicky

I would first suggest you to upgrade to CodeWarrior for HC12 V3.1 or V4.5. Management of banked constants is much simpler with the newer releases. 

If you want to stick with V2.0, basically if you want to use banked constants in ANSI library functions you have to perform the following:

·         Define your string constants or constants in a user defined string segment or constant segment with attribute PPAGE. As you want to allocate string constants in ROM, you have to use PPAGE to access them.

·         Make sure to use far pointers rather than pointer to define any variable pointing to such a string.

 Example:

    #pragma STRING_SEG PPAGE myStrConst

    char *far myStr = "This is a constant String";

    #pragma STRING_SEG  DEFAULT

    #pragma CONST_SEG PPAGE myConst

    const char Tab[]= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xA};

    #pragma STRING_SEG  DEFAULT

·        

Place your segment in banked memory in your PRM file.

·         Use option -CpPPAGE=RUNTIME, to tell the compiler you want to access the string using a runtime function. You cannot directly modify the PPAGE register, because the code accessing the string may be located in another banks.

·         Add the file datapage.c (located in the LIB\HCI12C\SRC installation directory) to your project. Make sure it comes before ansib.lib in the "Link Order" View.

·         Make sure the code in the runtime function is correct. Depending on the MCU you are using, you may have to use a compiler option to activate bank switching for HC12DG128 or HCS12 to select the appropriate page register.

·         To activate page switching for HC12DG128, compile with option -DDG128.

·         To activate page switching for HCS12, compile with option –DHCS12

·         If you intend to use some library functions to manipulate the strings you have to regenerate the library for far string pointer. In this purpose:

·         Edit the file libdefs.h located in the installation directory "LIB\HCI\include". In this file modify lines 74 and 78 as follows:

   #define LIBDEF_FAR_CONST_STRINGS  1  

   #define LIBDEF_FAR_STRINGS        1  

·         Generate the library again. This can be done using the project hc12 lib.mcp located in the installation LIB\HCI directory. Technical note TN105 provide you information how to generate a new library.

If this does not help, submit a service request through the web interface and attach a zip file containing the whole project.

CrasyCat

0 Kudos
Reply

2,586 Views
sjmelnikoff
Contributor III
Alternatively, you can arrange for the constants, and any functions that use them, to be in the same page (by reserving some space in the linker file, and using pragmas in your code to place functions and constants in that area), and then you don't need to worry about PPAGE and compiler options.
 
Note that if you do this, you can't easily use library functions on the constants, as these functions reside in non-banked flash, and so PPAGE handling can get complicated.
 
Steve M.
0 Kudos
Reply

2,586 Views
EmbeddedCoder
Contributor III

Hi Vicky,

This reply may be a little late - but perhaps is useful to others?

Datapage.c contains an error - PPAGE on the MC9S12 256 and 512 variants (at least) resides at 0x30 and not 0x35 as Datapage.c defines it.

I had the same issue, and had to manually modify datapage.c to get this to work!

Hopefully this will be fixed in a later version of Codewarrior?

0 Kudos
Reply

2,586 Views
CrasyCat
Specialist III
Hello
 
If you want to access banked constant on a HCS12 MCU on CodeWarrior HC12 V2.0, you have to:
    1- Add file datapage.c to your project
    2- Make sure it appears before ansi.lib in the link order (you can use drag and
        drop to change the sequence in the Link order view. 
    3- Build with option -CpPPAGE=RUNTIME -DHCS12.
 
Note that switching to V3.1 or V4.5 will make it much simpler to access banked constants.
 
I hope it helps.
 
CrasyCat
0 Kudos
Reply

2,586 Views
Nabla69
Contributor V
Hi Vicki,
 
May you please indicate which device you are using ?
On newer devices you have a Global page (GPAGE) which could be used to point to your constant page and retrieve data easily.
Also, you should be able to access it using the Full address... 0x4FC1000 for instance (far pointers).
 
Cheers,
Alvin.
0 Kudos
Reply

2,586 Views
EmbeddedDude
Contributor I
Hello,
 
I am using the HCS12XDP512 with CodeWarrior V4.5. I am compiling with the BANKED memory model.
 
You mentioned we could use the GPAGE to move constants to paged FLASH, but I am not having success with this. Can you give more details?
 
Basically I want to use paged FLASH for everything except my ISR's.
 
Here is a snippet of my PRM file...
 
SEGMENTS 
     ........
 
      GPAGE_F0      = READ_ONLY   0x7C0000 TO 0x7C3FFF;
      GPAGE_F1      = READ_ONLY   0x7C4000 TO 0x7C7FFF;
      GPAGE_F2      = READ_ONLY   0x7C8000 TO 0x7CBFFF;
      .......
 
END
PLACEMENT /* here all predefined and user segments are placed into the SEGMENTS defined above. */

      _PRESTART,              /* Used in HIWARE format: jump to _Startup at the code start */
      STARTUP,                /* startup data structures */
                        INTO  ROM_4000;
 
      ROM_VAR,                /* constant variables */
      VIRTUAL_TABLE_SEGMENT,  /* C++ virtual table segment */
      STRINGS,
      COPY                    /* copy down information: how to initialize variables */
                        INTO  GPAGE_F0, GPAGE_F1, GPAGE_F2;

      NON_BANKED        INTO  ROM_4000;   /* runtime routines which must not be banked */
 
      DEFAULT_ROM       INTO PAGE_FE, PAGE_FC, PAGE_FB, PAGE_FA, PAGE_F9, PAGE_F8; 
      SSTACK,                 /* allocate stack first to avoid overwriting variables on overflow */
      DEFAULT_RAM             /* all variables, the default RAM location */
                        INTO  RAM;
 
      PAGED_RAM         INTO  /* when using banked addressing for variable data, make sure to specify
                                 the option -D__FAR_DATA on the compiler command line */
                              RAM_F8, RAM_F9, RAM_FA, RAM_FB, RAM_FC, RAM_FD;
END
With this setup, I get the following linker warning...
 
L1128: Cutting value toCopyDownBeg startup data member from 0x7C260F to 0x260F
 
 
Thanks,
Mike
0 Kudos
Reply

2,586 Views
CompilerGuru
NXP Employee
NXP Employee
A few topics.
- You can place constants into paged memory but this does require to place them in a non default section in the flash. There are two technical notes about this topic, TN238 and TN240.
- In the prm file, use logical addersses, not global ones (not 0x7C0000'G but 0xF08000). Basically use the same addresses just as they already exist in a wizard generated prm file.
E.g.:
      GPAGE_F0      = READ_ONLY   0xF08000 TO 0xF0BFFF;
      GPAGE_F1      = READ_ONLY   0xF08000 TO 0xF0BFFF;
      GPAGE_F2      = READ_ONLY   0xF08000 TO 0xF0BFFF;
- Don't place the predefined constant sections into banked memory. In the banked memory model, only place constant sections into that area which are prepared for this. E.g. your own custom sections.

      ROM_VAR,                /* constant variables */
      VIRTUAL_TABLE_SEGMENT,  /* C++ virtual table segment */
      STRINGS,
      COPY                    /* copy down information: how to initialize variables */
                        INTO  ROM_4000;
      PAGED_CONSTANTS INTO GPAGE_F0, GPAGE_F1, GPAGE_F2;



Daniel
0 Kudos
Reply

2,586 Views
EmbeddedDude
Contributor I
Daniel,
 
Thanks for the quick reply.
 
I see from your example that you put ROM_VAR,  VIRTUAL_TABLE_SEGMENT, and STRINGS into ROM_4000. I do not have room for this - which is why I wanted to put them into a higher page.
 
When you say "only place constant sections into that area which are prepared for this" what are my options for preparing the sections for this? I definitely need to put all STRINGS into banked memory. It seems like there should be a simple way to define all STRINGS to automatically address a banked page.
0 Kudos
Reply

2,586 Views
CompilerGuru
NXP Employee
NXP Employee
Please check the TN's for all the details. For string literals use
#pragma STRING_SEG __GPAGE_SEG MY_GPAGE_STRING_SECTION
instead of the CONST_SEG as in the TN's,
and place MY_GPAGE_STRING_SECTION into the paged area.
Make sure all accesses to those strings are using __far pointers.
I would keep on allocating the STRINGS section into a non paged area, it will be empty if the pragma above was visible for all string literals.

Daniel

0 Kudos
Reply