Working with 9S12 RAM Pages

cancel
Showing results for 
Search instead for 
Did you mean: 

Working with 9S12 RAM Pages

499 Views
jcdammeyer
Contributor III

I'd like to be able to have the compiler use the 4K available from 0x1000 to 0x1FFF so that I have contiguous RAM from 0x1000 to 0x3FFF.  By default the data sheet says the RPAGE is set to 0xFD.  I can also expressly set that.

Is this the right way to tell the C compiler that I have a structure with 640 bytes in 0x1000 to 0x1FFF area?

 

The linker PLACEMENT section has

  PAGED_RAM           /* paged data accessed by CPU12 only */
                  

INTO  RAM_FD;

The command line for the C compiler has:

-D__FAR_DATA

Also

-CpRPAGE=0xFD

 

In the application file the variable is declared as follows:

#pragma DATA_SEG PAGED_RAM

TECNREC ACNPacket;

#pragma DATA_SEG DEFAULT

 

Stepping through the code a pointer to the variable is loaded with 0x1000 and the application appears to work.

 

Am I missing anything?  If I want to use two pages of RAM then what?  Will the compiler fill in a value for RPAGE?

If I want to access the data in an interrupt routine it's probably best to first save the RPAGE and expressly set it to FD if I use more than one page?

Thanks

John

Labels (1)
0 Kudos
2 Replies

134 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi John.

I think Edward was well-answered the question, if you still can't figure out the problem, please upload your sample code to demonstrate the problem. also mention how to see your problem with your project.

Best Regards.

ZhangJun

0 Kudos

134 Views
kef2
Senior Contributor IV

John,

did you search community for this. I think this was explained several times in the past.

There are 3 ways on S12X, which you can use to access the same physical RAM: 1) fastest and simplest CPU address space @0x1000..0x3FFF, 2) via R-page 1k window at @0x1000..0x1FFF, 3) using global addressing instructions, G-page.

You asked for contiguous 0x1000..0x3FFF and also what about using two R-pages. These two are mutually exclusive. Using contiguous 0x1000..0x3FFF requires keeping RPAGE=0xFD constant. So either you fix RPAGE and edit PRM to enable contiguous 12k, or use paged RAM. To enable contiguous 12k just change PRM as follows

/* non-paged RAM */

      RAM           = READ_WRITE  DATA_NEAR            0x1000 TO   0x3FFF;


-D__FAR_DATA  is required for proper data initialization at startup

-CpRPAGE=0xFD

CpRPAGE tells compiler to save/restore RPAGE on entry/exit from interrupt. It is the best to not use slower paged RAM from interrupts. But if you need to, then this switch is required.

     In the application file the variabe is declared as follows:    

     #pragma DATA_SEG PAGED_RAM

     TECNREC ACNPacket;

     #pragma DATA_SEG DEFAULT

     Stepping through the code a pointer to the variable is loaded with 0x1000 and the application appears to work.

It "worked" but didn't set up RPAGE. Wouldn't work for multiple R-pages. You told linker to placed ACNPacket in paged RAM, but didn't tell compiler how it should access paged RAM. It seemed working, but didn't set up RPAGE. You need to use __RPAGE_SEG or __GPAGE_SEG to make compiler aware about access method.

#pragma DATA_SEG __RPAGE_SEG PAGED_RAM

TECNREC ACNPacket;

#pragma DATA_SEG DEFAULT

If you want to use more R-pages, then you need to add -PsegObj to compiler settings or try searching old messages, I wrote about -PsegObj in the past.

0 Kudos