Skip to main content
jmary
Associate III
September 4, 2022
Question

How to put struct object in absolute memory address?

  • September 4, 2022
  • 4 replies
  • 3399 views

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 topic has been closed for replies.

    4 replies

    Tesla DeLorean
    Guru
    September 4, 2022

    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    jmary
    jmaryAuthor
    Associate III
    September 4, 2022

    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 III
    September 4, 2022
    #define userData (*(USERDATA *)0xE00004)

    jmary
    jmaryAuthor
    Associate III
    September 4, 2022

    Thank, let me try

    Tesla DeLorean
    Guru
    September 4, 2022

    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    jmary
    jmaryAuthor
    Associate III
    September 4, 2022

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

    Tesla DeLorean
    Guru
    September 4, 2022

    Using pointers ​is most portable.

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