Hi
I'd like to put a struct
typedef struct { U32 a; U8 b[8]; U8 c; } MyType;
...
MyType xdata *pMyVar;
in XRAM to a particular address section that starts at 0x1000. Therefore I added "XDATA(0x1000)" in the linker command (BL51). But unfortunately the linker doesn't place the variable to an address above 0x1000 but somewhere below instead!
But when I swap the deklaration to
xdata MyType *pMyVar;
everything works as expected! Is there a different between those two declarations? According to http://www.keil.com/support/man/docs/c51/c51_le_xdata.htm the first (not-working) variant is the correct one!
I am confused. Any ideas?
Jonathan
Note that a pointer is a variable.
And a pointer can point to something.
So when you specify the type of the pointer, you have to take into account if xdata says that the pointer should be stored in xdata - or if the pointer should point to objects in xdata.
Oh of course...! Such a simple mistake. Thank you for your hint!!
Just a second! I did some further investigations and I also came across this site: www.keil.com/.../c51_le_memspecificptrs.htm .
According to it, my construct
is a ptr to MyType in xdata. So pMyVar points to xdata while the pointer itself resides anywhere (in data?).
But, and this is the surprise, it points to addresses below the 0x1000 border - even though I explicitly instructed the linker with "XDATA(0x1000)" not to use this area!
What's wrong? Where is my mistake? Does anybody of you know?
The Pointer itself will reside in the default memory spaced (as defined by you).
Allright, but why does it point to an xdata area below 0x1000, even though I told the linker not to do?
Hi Jonathan,
This instances an unassigned pointer of the type MyType that points to xdata (means it is accessed with an MOVX instruction). Since it is not initialized it will point somewhere. There is no relation between your linker directive telling the linker the XDATA space is starting at 0x1000 and the fact that you declared the pointer as xdata.
If you want your pointer to point somewhere defined you need to initialize it.
Regards, Matthias
Oh allright, I see! Of course this makes sense, Matthias!
I just did your suggested rework and my code works fine. Thank you all!
Regards Jonathan
View all questions in Keil forum