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.

Export macro from the linker command file



Hello,

how can I use a macro from linker command file in the C code. Which instruction or directive is needed to import the macro APPLICATION_BASE in the C code.

Linker command file:

#define  APPLICATION_BASE   0x00009400

 

C-Code:

    HWREG(NVIC_VTABLE) = (unsigned long) (0x00009400);
    __asm("    movw    r0, #0x00009400\n"    // r0 is now 0x8000
            "    ldr    sp, [r0]\n"// sp is now *(0x8000)
            "    ldr    r0, [r0,#4]\n"// r0 is now *(0x8004)
            "    bx    r0\n" );

 

Thank you.

 

  • I'm sorry, this is not possible.  You could put the macro in a C include file and include it in both the C source and the linker command file.

    Furthermore, the TI compiler does not accept GNU-style extended assembly in the __asm statement, so your C code will not work even if the compiler sees it.

  • Here is a solution to consider.

    Define a symbol in the linker command file ...

    special_symbol = APPLICATION_BASE;
    

    Then access special_symbol in your C code.  This access is a bit different than ordinary C variable access.  Read about it in the Compiler User's Guide, in a section titled Accessing Assembly Language Constants.  You don't say which processor you are using, so here is a link to all of the manuals.

    Thanks and regards,

    -George

  • Thank you for your supports.

    I have read the description in the ARM Optimizing C&C ++ Compiler User's guide and implemented this.
    It works partially. The assembler statement does not work. Do you have any ideas for assembler statement?

     

    Linker file:
    application_base = APPLICATION_BASE;
    
    
    C-Code:
    extern unsigned long application_base;
    #define APPLICATION_BASE_ADDRESS ((unsigned long)(&application_base))
    
    HWREG(NVIC_VTABLE) = APPLICATION_BASE;  		//works
    
        __asm("    movw    r0, #APPLICATION_BASE\n"    // does not work
                "    ldr    sp, [r0]\n"
                "    ldr    r0, [r0,#4]\n"
                "    bx    r0\n" );
    

  • The TI compiler does not support asm statements like 

    Veysel Kasap said:
    __asm(" movw r0, #APPLICATION_BASE\n" // does not work
    " ldr sp, [r0]\n"
    " ldr r0, [r0,#4]\n"
    " bx r0\n" );

    Thanks and regards,

    -George

  • Hello George,

    thanks for your Information.

    I have a question. How can I add an additional linker predefine symbol?

    Which seperator is required (',' ';' '-')?

  • I don't think you can use that interface to define more than one macro name.  This is fixed in CCS v6.

    Thanks and regards,

    -George