2

I have a IAR workplace with several projects running on the same STM32 hardware. I have a header memory map file (mmap.h) that describes the flash section addresses (boot location, application, permanent storage ect..) that is made available to the various modules that need it.

I would also like to include this file in the iar linker scripts .icf files so that i don't have to redefine the memory map there. However when i try to include it, it seems to expect another .icf file and doesn't understand the #define C preprocessors. What would be the easiest way to have my memory map defines both in the linker scripts AND in te source code ?

I tried to use the Custom Argument Variables from iar but they need to be redefined in each project in both Cpreprocessors and linker options.

morfl
  • 21
  • 2

2 Answers2

2

The IAR Linker Configuration File (ICF) has its own syntax, which is detached from the C Language. Although, it is possible to export linker symbols so that they can used from within the C application. Assuming that all the .icf files are located in the same directory as the .ewp project. The easiest way might be this one.

Define your memory map in mmap.icf using define exported symbol like this:

define exported symbol __region_FLASH_start__  = 0x08000000;
define exported symbol __region_FLASH_end__    = 0x080FFFFF;
define exported symbol __region_SRAM1_start__  = 0x20000000;
define exported symbol __region_SRAM1_end__    = 0x2001BFFF;
define exported symbol __region_SRAM2_start__  = 0x2001C000;
define exported symbol __region_SRAM2_end__    = 0x2001FFFF;
/* Remaining of the Memory Map... */

Then include mmap.icf at the top of your $PROJ_DIR$/STM32Fxxxxxx.icf which is used by the linker's configuration page (equivalent to the --config option) like this:

include "mmap.icf";
/* Remaining of the top-level ICF... */

From the application, use mmap.h to bind the linker symbols to the application as externals, like this:

#pragma once
extern unsigned int __region_FLASH_start__;
extern unsigned int __region_FLASH_end__;
extern unsigned int __region_SRAM1_start__; 
extern unsigned int __region_SRAM1_end__;    
extern unsigned int __region_SRAM2_start__;  
extern unsigned int __region_SRAM2_end__;    
/* Remaining of the external symbols... */

This approach for a custom linker configuration that exports defined symbols (via define exported symbol) simplifies spanning the same configuration across multiple projects within the same workspace/scope.

sharpgeek
  • 481
  • 2
  • 14
0

I have a header [...].

I would also like to include this file in the iar linker scripts .icf files so that i don't have to redefine the memory map there.

I'm not sure why you suppose that a linker would understand the C syntax of your header. I guess it's possible that some linker would, but I'd find that pretty surprising.

What would be the easiest way to have my memory map defines both in the linker scripts AND in te source code ?

Generate one (or part of one) from the other programmatically, or generate both from a common source. A script to do such translation / generation should not be very difficult to prepare. Nor do I expect it to be hard to integrate into your build process, though I am unfamiliar with the specifics of IAR. At worst, you might have to re-run the script manually from time to time.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157