英文:
how to include C #defines in an .icf linker files?
问题
我在IAR工作环境中有几个在相同STM32硬件上运行的项目。我有一个头文件内存映射文件(mmap.h),描述了Flash部分地址(引导位置、应用程序、永久存储等),供需要它的各个模块使用。
我也想在iar链接脚本.icf文件中包含这个文件,这样我就不必在那里重新定义内存映射。然而,当我尝试包含它时,它似乎期望另一个.icf文件,并且不理解#define C预处理器。在链接脚本和源代码中都包含内存映射定义的最简单方法是什么?
我尝试使用iar的自定义参数变量,但它们需要在每个项目中的C预处理器和链接选项中重新定义。
英文:
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.
答案1
得分: 2
IAR链接器配置文件(ICF)具有其自己的语法,与C语言无关。尽管如此,可以导出链接器符号,以便它们可以从C应用程序中使用。假设所有的.icf
文件都位于与.ewp
项目相同的目录中,最简单的方法可能是这样的。
在mmap.icf
中定义内存映射,使用define exported symbol
,像这样:
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;
/* 内存映射的其余部分... */
然后在您的$PROJ_DIR$/STM32Fxxxxxx.icf
的顶部包含mmap.icf
,该文件由链接器的配置页面使用(相当于--config
选项),像这样:
include "mmap.icf";
/* 顶层ICF的其余部分... */
从应用程序中,使用mmap.h
将链接器符号绑定到应用程序作为extern
,像这样:
#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__;
/* 外部符号的其余部分... */
这种通过define exported symbol
导出已定义符号的自定义链接器配置方法简化了跨同一工作区/范围内的多个项目之间使用相同配置的过程。
英文:
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 extern
als, 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.
答案2
得分: 0
我有一个头文件[...]。
我还想在iar链接脚本.icf文件中包含此文件,以便我不必在那里重新定义内存映射。
我不确定为什么你认为链接器会理解你的头文件的C语法。我猜某些链接器可能会理解,但我觉得这相当令人惊讶。
有什么最简单的方法可以让我的内存映射定义既在链接脚本中又在源代码中?
从另一个方面自动生成一个(或部分)或从一个共同的源生成两者。编写这种翻译/生成的脚本应该不是很难的事情。并且我不认为将其集成到你的构建过程中会很困难,尽管我不熟悉IAR的具体细节。最坏的情况下,你可能不时需要手动运行脚本。
英文:
> 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论