This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to get the start address of the memory segment defined in linker file.

MEMORY
{
    SFR                     : origin = 0x0000, length = 0x0010
    PERIPHERALS_8BIT        : origin = 0x0010, length = 0x00F0
    PERIPHERALS_16BIT       : origin = 0x0100, length = 0x0100
    RAM                     : origin = 0x1100, length = 0x1000
    INFOA                   : origin = 0x10C0, length = 0x0040
    INFOB                   : origin = 0x1080, length = 0x0040
    INFOC                   : origin = 0x1040, length = 0x0040
    INFOD                   : origin = 0x1000, length = 0x0040
    FLASH                   : origin = 0x2100, length = 0xCA27
    IDR_SEGS                : origin = 0xEBDC, length = 0x11FF
...

I want to the start address of a segment IDR_SEGS, that is 0xEBDC.
How do i get start adress using a macro and store it in a variable in c source code?

 

  • You could do something like this in the linker command file ...

    #define IDR_SEG_BASE 0xEBDC
    /* ... */
    
    csymbol_idr_seg_base = IDR_SEG_BASE;
    /* ... */
    
    MEMORY
    {
       /* ... */
       IDR_SEGS : origin = IDR_SEG_BASE, length = 0x11FF
       /* ... */
    }
    
    /* ... */
    

    For the details on how to use csymbol_idr_seg_base in your C code, please see the section titled Accessing Assembly Language Constants in the MSP430 compiler manual.

    Thanks and regards,

    -George

  • I will try this, but if i need multiple segment base address how can i do it?

    ex FLASH segment or any application specific like IDR_SEGS segment..

  • There is no automated method.  You have to repeat the #define technique for every memory range where it is needed.

    Thanks and regards,

    -George

  • George, Thanks for ur inputs..

    Do u mean Something like below for multiple segment base.

    ==============

    In Linker File

    ==============

    #define IDR_SEG_BASE 0xEBDC
    #define SEC_KEY_SEG_BASE 0xFDDB
     
    /* ... */
     
    csymbol_idr_seg_base = IDR_SEG_BASE; /* ... */
    csymbol_sec_key_seg_base = SEC_KEY_SEG_BASE; /* ... */
     
    MEMORY
    {
       /* ... */
       IDR_SEGS : origin = IDR_SEG_BASE, length = 0x11FF
       SEC_KEY_SEG : origin = SEC_KEY_SEG_BASE, length = 0x01FF
       /* ... */
    }
      /* ... */

     ===========

    In source file

    =============

    WORD var1 = IDR_SEG_BASE;

    WORD var2 = SEC_KEY_SEG_BASE;

     

  • Yes.  Except the C code should use the "csymbol" names per the technique I mentioned in my first post.

    Thanks and regards

    -George