problem when access paged ram variable by pointer

cancel
Showing results for 
Search instead for 
Did you mean: 

problem when access paged ram variable by pointer

117 Views
Contributor IV

My mcu is MC9S12XE.

I have defined a variable named such as msg_buffer in the PAGED RAM,and it's actually allocated address is F91000.I want to put data into this buffer using pointer,but doesn't work.Codes look like this:

pbsor = msg;

pbdst = msg_buffer;

for(i = 0; i < size; ++i)

   *pbdst++ = *pbsor++;

But when i defined pbdst with prefix '__far',it works.

When i use prefix '__far' in the function which get data from msg buffer,it doesn't work.Codes look like this:

pbsor = msg_buffer;

pbdst = msg;

for(i = 0; i < size; ++i)

   *pbdst++ = *pbsor;

But when i defiend pbsor without prefix '__far',it works.

why does it execute like this?By the way,the variable msg allocated in the stack,and stack is allocated in the UNPAGEED RAM(0x2000~0x3FFF).

Labels (1)
0 Kudos
5 Replies

31 Views
NXP TechSupport
NXP TechSupport

Hi,

better than presented code is full, short, functional example. It is better to see all dependencies.

I have attached an example (SW-XEP100-RAM-addressing-v1_0-CW51.zip) I prepared few days ago. It shows you how to + some important notes like _D_FARDATA definition.

I believe it will help you. (Otherwise, I would prefer to get short, issue highlighting project)

Best regards,

Ladislav

0 Kudos

31 Views
Contributor IV

Thanks for your reply very much.

But my situation is some different with normal principle.

I want to copy data in Unpaged RAM into Paged RAM,normally i need use prefix '__far' to define my pointer toPaged RAM,but it does not work.However use a pointer without any prefix can copy the data correctly.

0 Kudos

31 Views
NXP TechSupport
NXP TechSupport

Hi,

As I wrote before "better than presented code is full, short, functional example. It is better to see all dependencies."

I do not want to speculate what is where and what could be where.
I need to have full project to have exactly visible project setup and variables definitions.

Best regards,

Ladislav

0 Kudos

31 Views
Contributor IV

Now i know how to cause the problem exactly.As show in the prm file of project:

default setting is:

XGATE_DATA INTO RAM_F8, RAM_F9, RAM_FA, RAM_FB

PAGED_DATA INTO RAM_FD, RAM_FC

change it to:

XGATE_DATA INTO RAM_F8

PAGED_DATA INTO RAM_F9, RAM_FA, RAM_FB, RAM_FD, RAM_FC

Then the access to the global variable allocate at RAM_F9 will be failed.

I forget to add prefix 'far' back to code,but even if i add it back to local variable pddst,structure member size also can not be access correctely.

So i use a structure pointer to point global variable with prefix 'far',and everything is ok.Is it mean that it should use 'far' pointer to access a PAGED RAM allocated variable?

0 Kudos

31 Views
Senior Contributor IV

Hi,

your problem you need to and forgot to use far or proper #pragma memory qualifiers. Once it is done properly, compiler will emit warnings each time you use wrong pointers:

// variables in paged memory have to be always either:
// 1) be put into qualified __R/E/GPAGE_SEG memory. This will let compiler know
//    memory is paged and how this paged memory is to be accesses, using RPAGE/GPAGE/etc addressing
// 2) use far keyword

// Don't forget as well when exporting data from paged memory to other C files to use

// correct #pragma with the the same __RPAGE_SEG/__GPAGE_SEG attribute, or far keyword
// in header file! #pragma often is better, since it specifies which way compiler should access data

#pragma push
#pragma DATA_SEG __RPAGE_SEG PAGED_RAM
MSGBUF gst_mb;
#pragma pop