cancel
Showing results for 
Search instead for 
Did you mean: 

External Memory access for ST92F150

scott239955
Associate II
Posted on January 14, 2004 at 20:35

External Memory access for ST92F150

6 REPLIES 6
scott239955
Associate II
Posted on May 17, 2011 at 11:35

I revised my question to make it short and clear. Please help!

I can do the following to access unmapped external memory:

in the linker script file:

-----------

EXT_RAM0 : ORIGIN = 0x300000, LENGTH = 16K

.ext_ram0 : { *(.ext_ram0) } > EXT_RAM0

in my c-file:

--------------

unsigned char var; // internal RAM variable

unsigned char ext_var UNINITIALIZED_DATA_SECTION(.ext_ram0);

volatile unsigned char far *eram_ptr; // far pointer sets DPR0

eram_ptr = &ext_var;

*eram_ptr = 5; // set variable in External RAM to 5

var = *eram_ptr; // read variable from External RAM

However, the compiler does not let me do this:

--------

unsigned char var; // internal RAM variable

unsigned char ext_var[5]; UNINITIALIZED_DATA_SECTION(.ext_ram0);

eram_ptr = &ext_var[2];

*eram_ptr = 5; // set byte2 in array to 5 => gives compiler error

I can not access elements of arrays or components of structures in external memory. I really need to use structures (MyStruct[3].type = 5). I have attached sample code. Does anyone know how to do this?

[ This message was edited by: Smiles on 27-10-2003 10:33 ]

I modified the attached file - I still have the same problem if anyone can help?

[ This message was edited by: Smiles on 27-10-2003 23:56 ]

ritu
Associate II
Posted on May 17, 2011 at 11:35

Hello Smiles,

As you are using unmapped data so you can't use

eram_ptr = &ext_var[2]; statement instead you will have to initialize

eram_ptr to ext_var

and then to access 2 element you can use

*(eram_ptr + 2) = 5;

Similarly for the structure you can't use a pointer to char type for pointing to a structure so you will need a pointer for structure type e.g.,

volatile struct struct_type far *eram1_ptr;

and then initialize eram1_ptr = ext_struct;

to acess specific member of structure use derefrencing operator ->

(eram1_ptr + 2)->memberA = 5;

I attach with this message the modified zip file of your code which is getting build properly.

Ritu

scott239955
Associate II
Posted on May 17, 2011 at 11:35

Hi Ritu,

Thank you very much for responding. I have since found out what you mentioned - that compiler requires pointer notation instead of array notation for data in external sections. I also noticed that looking at the list file, the compiler converts the array notation to pointer notation correctly, but then loads zero (through another register) into R224, which is DPR0 in the medium model (DPRREM = 1)

scott239955
Associate II
Posted on May 17, 2011 at 11:35

I have another related problem. I can use the pointer notation ok to access data:

struct my_struct[5] {whatever...};

struct my_struct far *eram_ptr;

eram_ptr = &my_struct[0];

value = *(eram_ptr + 2) // gets the value of the second structure ok

But, when eram_ptr is a pointer to a structure I can not typecast it to point to a byte so that I can increment it. Adding to the example above:

unsigned char far *eram_ptr2;

eram_ptr2 = (unsigned char *) (eram_ptr + 2); // debugger gets lost

In my actual code the 2 is a variable. I want to be able to copy the whole structure from external RAM into internal RAM by incrementing the pointer. Any ideas?

ritu
Associate II
Posted on May 17, 2011 at 11:35

I don't think you need to type cast the pointer to structure to access any element of the smae structure you can use indirection operator.

Like ptr_to _struct -> memberA

And to acess next structure in the array you can increment the pointer to structure as it will automatically point to the next structure. So to copy structure from external RAM to Internal RAM you can use the following code:

ptr_to_struct_iram ->mem A = ptr_to_struct_eram ->mem A

ptr_to_struct_eram ++

ptr_to_struct_iram ++

ptr_to_struct_iram ->mem A = ptr_to_struct_eram ->mem A

Ritu
scott239955
Associate II
Posted on May 17, 2011 at 11:35

I agree, but I'm trying to copy the structure without regard to the components in it. In other words, if the structure had 20 components and the size of the structure is 300 bytes, I was trying to copy 300 bytes. The following may work, but it gives me a warning about the pointer being incompatible and I have not fully tested it out:

struct stype my_struct[60] UNINITIALIZED_DATA_SECTION(.ext_ram0);

struct stype far *struct_ptr;

unsigned char far *eram_ptr;

struct_size = sizeof(my_struct);

struct_ptr = &my_struct + struct_num;

eram_ptr = struct_ptr; // I get warning here

for (byte=0; bytes< struct_size; byte++)

{

*eram_ptr++ = EE_value; //EE_value got from serial EEPROM, could be an internal RAM pointer to the same structure type...

}

I was trying to type case the pointer to remove the warning, or type cast the pointer that points to the structure and only use one pointer.