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.

CCS/F28M35H52C: Using predefined preprocessor symbols in linker command file

Part Number: F28M35H52C

Tool/software: Code Composer Studio

I work with Concerto M35, ARM linker

I am trying to define memory allocation size in C and pass it to linker.

Of cause I can directly #define it in cmd file, but I want to use value from C or globally defined symbol

Ideally I would like to define in C file :  #define WEB_RAM_LEN 0x3800

and use this definition in my custom m3_link.cmd, in MEMORY {}

MEMORY
{
......
WEB_RAM (RWX) : origin = 0x20010000, length = WEB_RAM_LEN // M3: WEB_RAM segment for dynamic files
......
}

But linker does not know about this C definition and gives an error.

I tried global definitions also:

I see in properties of the project, ARM linker my globally defined symbols:

-mv7M3 --code_state=16 -me -O3 --opt_for_speed=5 --fp_mode=strict --define=ccs --define=BOOT_FROM_FLASH --define=M3CORE  -g --gcc --diag_suppress=9 --diag_warning=225 --display_error_number --gen_func_subsections=on --abi=eabi --ual -z -m"M3.map" --heap_size=0x300 --stack_size=0x1000

But even this example does not work: the WEB_RAM_LEN alwaus comes to 0x3000 and allocation fails.

#ifdef M3CORE
  #define WEB_RAM_LEN 0x3800
#else
  #define WEB_RAM_LEN 0x3000
#endif

Is this even possible to define memory block size in C or globally?

Thanks!

Igor

  • Hello,
    I will move this thread to the compiler forum. The experts there can guide you best.

    Thanks
    ki
  • Igor Kordunsky said:
    Is this even possible to define memory block size in C or globally?

    Yes.  Define it in a header file.  Then include that same header file in both your C code and your linker command file.

    Thanks and regards,

    -George

  • Thanks, George,

    So simple :-)

    Works like a charm !

    One should be careful: the usual C header with other definitions like:

    err_t get_dynamic_web_file(struct fs_file *file, char *name);

    is treated in command file as file name, and processing cmd file gives errors similar to: 

    cannot find file "err_t"

    cannot find file "get_dynamic_web_file"

    expecting filename, option, MEMORY, or SECTIONS instead of "("

    etc.

    So, only simple statements are allowed for both "C" and "cmd" files:

    content of "web_ram.h"

    #ifndef WEB_RAM_H_
    #define WEB_RAM_H_

    #define WEB_RAM_LEN 0x3800

    #endif // WEB_RAM_H_

    Use #include "web_ram"

    in C code and in "*.cmd" file

    Igor