cancel
Showing results for 
Search instead for 
Did you mean: 

How to put struct object in absolute memory address?

jmary
Associate III

My old project using 16bit infineon MCU with tasking c166, now I am moving to spc5 with free gnu gcc spc5studio.

I am working with typedef struct.

typedef struct
{
	struct
	{
		struct
		{
			INT16  Rpm[6];
			INT16  Load[7];
			INT16  Threshold[6];
		}
		pickup;
       } sensor;
     
      UINT16	checksum;
} USERDATA;

in c166 I set a struct object to an absolute address with ___at

USERDATA __at( 0xE00004 ) userData;

how to do the same with spc5 free gnu gcc?

This discussion is locked. Please start a new topic to ask your question.
11 REPLIES 11

Perhaps it would be less disruptive in the Linker Script, as a section?

Or in C just as a pointer with it cast to the appropriate address?

Does it have any initialize content, or is it device unique calibration data written during testing, etc?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jmary
Associate III

I need the object in absolute address to manipulate the value by uart, can from PC for calibration. so it will be easier on absolute memory address.

I need the same code that working same as __at in tasking c166 on gnu gcc. any sample code for the section?

ne562
Associate II
#define  userData (*(USERDATA *)0xE00004)

I'd probably move to a model that's not compiler dependent,rather than non-portable

USERDATA *userData = (USERDATA *)0xE00004;
 
userData[0].checksum =12345;
 
or
 
 if (userData->checksum == computed) { ... };
 
or .LD something like
 
 
MEMORY
{
...
 
  USRDAT (r) : ORIGIN = 0xE00004, LENGTH= 256
}
 
 
SECTIONS
{
...
 
  .usrdat (NOLOAD) :
  {
    *(.usrdat)
  } >USRDAT
 
...
 
}
 
 
In C, something like
 
 
USERDATA  userData __attribute__ ((section (".usrdat")));

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I see, thanks. So the first option, without section is enaugh? What the drawback compare with using section and linker?

jmary
Associate III

Thank, let me try

jmary
Associate III

But when I try to change the object value, got segmentation fault.

Using pointers ​is most portable.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jmary
Associate III

The command to change to checksum value is not working.

userData[0].checksum =12345;