cancel
Showing results for 
Search instead for 
Did you mean: 

Can I use preprocessor commands in linker script and how ?

JureL
Associate III

Hey,

Is it possible to use preprocessor commands in linker script file (***.ld) and how it can be done if possible. I want to have diffrent memory definitions depending on the macro.

I tried this but it's not working:

/* Memories definition */
MEMORY
{
/* IF BOATLOADER IS ENABLED USE THIS MEMORY CONFIG*/
#ifdef ENABLE_BOOTLOADER
  SHARED (xrw)    : ORIGIN =0x20000000 , LENGTH = 64K
  RAM    (xrw)    : ORIGIN =0x20000040 , LENGTH = (512K - 64K)
  FLASH    (rx)   : ORIGIN =0x08008000 , LENGTH = (2048K-32K)*/
#else 
/* IF BOATLOADER IS DISABLED USE THIS MEMORY CONFIG*/
  RAM    (xrw)    : ORIGIN =0x20000000 , LENGTH = 512K
  FLASH    (rx)   : ORIGIN =0x08000000 , LENGTH = 2048K 
#endif
  QUADSPI (r)     : ORIGIN =0x90000000 , LENGTH = 16M
}

2 REPLIES 2
TDK
Guru

Sort of. You need to do the legwork manually.

https://stackoverflow.com/questions/28837199/can-i-use-preprocessor-directives-in-ld-file

If you feel a post has answered your question, please click "Accept as Solution".
JureL
Associate III

@TDK thank you for your anwser. I managed to preprocess linker script file in pre-build steps with command:

arm-none-eabi-gcc -E -x c -Iinclude  ../STM32F767IITX_FLASH_in.ld  | grep -v '^#'   > ../STM32F767IITX_FLASH.ld 

But there is a problem that global MACROS are not taken into account when preprocessing. Do you have any idea how to do that ?

With global macros i mean Symbols of project in Project->Properties->C/C++ General->Path and Symbols->Symbols