AnsweredAssumed Answered

How to places a variable at a specific absolute address?

Question asked by Giovinetti Roberto on Feb 27, 2014
Latest reply on Mar 5, 2014 by Jorge_Gonzalez

Hello everyone

I'm using CodeWarrior 10.5 from few days. I'm trying to get in touch with Kinetis MCU family, and I'd like to use same approach I always used in the past with S08 and S12 MCU's. I don't like Processor Experts, and I prefer to initialize MCU by particular sub part of a program called at the beginning of the same program, and for doing this operation I refer to registers using the approach used in older CW version, in which, for every derivative, we can find a definition of all the registers we use, and refer to them with acronym, for example to refer to a pin we can write in C "#define GREEN_LED     PTFD_PTFD0", where the bit PTFD0 of the register PTFD is directly accessible.

For doing this in olde CW versions, we find a definition like this:

 

/*** PTFD - Port F Data Register; 0x0000000A ***/

typedef union {

  byte Byte;

  struct {

    byte PTFD0       :1;                                       /* Port F Data Register Bit 0 */

    byte PTFD1       :1;                                       /* Port F Data Register Bit 1 */

    byte             :1;

    byte             :1;

    byte PTFD4       :1;                                       /* Port F Data Register Bit 4 */

    byte PTFD5       :1;                                       /* Port F Data Register Bit 5 */

    byte PTFD6       :1;                                       /* Port F Data Register Bit 6 */

    byte             :1;

  } Bits;

  struct {

    byte grpPTFD :2;

    byte         :1;

    byte         :1;

    byte grpPTFD_4 :3;

    byte         :1;

  } MergedBits;

} PTFDSTR;

 

extern volatile PTFDSTR _PTFD @0x0000000A;

#define PTFD                                 _PTFD.Byte

#define PTFD_PTFD0                     _PTFD.Bits.PTFD0

#define PTFD_PTFD1                     _PTFD.Bits.PTFD1

#define PTFD_PTFD4                     _PTFD.Bits.PTFD4

#define PTFD_PTFD5                     _PTFD.Bits.PTFD5

#define PTFD_PTFD6                     _PTFD.Bits.PTFD6

#define PTFD_PTFD                       _PTFD.MergedBits.grpPTFD

#define PTFD_PTFD_4                    _PTFD.MergedBits.grpPTFD_4

 

 

I've tried to do a similar thing with GCC but I can't find how. First compiler don't let me use @0x000000 method, for forcing a variable a specific asbsolute address. I've found I can use another method

 

/* General Purpose Input/Output (GPIO) */

#define IOPIN0 (*((volatile unsigned long *) 0xE0028000))

.

.

.

IOPIN0 = 0x4;

 

 

But if I try to redefine for example GPIOA register I cannot find how to work with single bit. I like to understand what I'm doing, and really I don't understand why I can't tell the linker that a variable has to have a specific address just like in the older CW versions.

I hope somwbody can help me.

 

For example if I define a type like below:

 

typedef union {

  uint32_t REG32BIT;

  struct {

  uint32_t BIT0        :1;

  uint32_t BIT1        :1;

  uint32_t BIT2        :1;

  uint32_t BIT3        :1;

  uint32_t BIT4        :1;

  uint32_t BIT5        :1;

  uint32_t BIT6        :1;

  uint32_t BIT7        :1;

  uint32_t BIT8        :1;

  uint32_t BIT9        :1;

  uint32_t BIT10       :1;

  uint32_t BIT11       :1;

  uint32_t BIT12       :1;

  uint32_t BIT13       :1;

  uint32_t BIT14       :1;

  uint32_t BIT15       :1;

  uint32_t BIT16       :1;

  uint32_t BIT17       :1;

  uint32_t BIT18       :1;

  uint32_t BIT19       :1;

  uint32_t BIT20       :1;

  uint32_t BIT21       :1;

  uint32_t BIT22       :1;

  uint32_t BIT23       :1;

  uint32_t BIT24       :1;

  uint32_t BIT25       :1;

  uint32_t BIT26       :1;

  uint32_t BIT27       :1;

  uint32_t BIT28       :1;

  uint32_t BIT29       :1;

  uint32_t BIT30       :1;

  uint32_t BIT31       :1;

} Bits;

}REG_MemMap;

 

I would like to define a variable for example

 

REGMemMap REGISTER_GPIOA @0x00000000 at a specific address

 

and the define

 

#define REGISTER_GPIOA_BIT0     REGISTER_GPIOA.Bits.BIT0

 

Something like that.

 

I hope tha someone can help me and give me information about this two (I think for most of you) simple topics.

Thank you very much and exscuse my poor English.

Roberto

Outcomes