Skip to main content
JureL
Associate III
October 5, 2020
Question

Can I use preprocessor commands in linker script and how ?

  • October 5, 2020
  • 2 replies
  • 5888 views

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
}

This topic has been closed for replies.

2 replies

TDK
Super User
October 5, 2020
"If you feel a post has answered your question, please click ""Accept as Solution""."
JureL
JureLAuthor
Associate III
October 7, 2020

@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