我正在使用IAR Embedded Workbench for Renesas Syenrgy(ARM cortex M4)7.40.5.9722
代码闪存大小:1MB
请考虑以下示例:
void function (void)
{
unsigned char a;
a = a+1;
}
我想将此功能放在flash中的特定位置。 什么是为此代码定义用户定义部分的方法。
我已经阅读了IAR编译器用户指南,并实现了如下所述的方法:
#pragma default_function_attribute = @ "MY_FUNC"
void function (void)
{
unsigned char a;
a = a + 1;
}
#pragma default_function_attribute =
在.icf文件中,我添加了以下部分:
define symbol region_VECT_start = 0x00000000;
define symbol region_VECT_end = 0x000003FF;
define symbol region_ROMREG_start = 0x00000400;
define symbol region_ROMREG_end = 0x000004FF;
define symbol region_FLASH_start = 0x00000500;
define symbol region_FLASH_end = 0x000BFFFF; // Fklsh end address is modified from 0x000FFFFF to 0x000BFFFF
define symbol region_MY_FUNC_start = 0x000C0000; // This statement is added
define symbol region_MY_FUNC_end = 0x000FFFFF; // This statement is added
define symbol region_RAM_start = 0x20000000;
define symbol region_RAM_end = 0x2002FFFF;
define symbol region_DF_start = 0x40100000;
define symbol region_DF_end = 0x40103FFF;
define symbol region_QSPI_start = 0x60000000;
define symbol region_QSPI_end = 0x63FFFFFF;
/* Stack and heap sizes are defined in bsp_cfg.h */
define memory mem with size = 4G;
define region VECT_region = mem:[from region_VECT_start to region_VECT_end];
define region ROMREG_region = mem:[from region_ROMREG_start to region_ROMREG_end];
define region FLASH_region = mem:[from region_FLASH_start to region_FLASH_end];
define region RAM_region = mem:[from region_RAM_start to region_RAM_end];
define region DF_region = mem:[from region_DF_start to region_DF_end];
define region QSPI_region = mem:[from region_QSPI_start to region_QSPI_end];
define region MY_FUNC = mem:[from region_MY_FUNC_start to region_MY_FUNC_end]; // New section is added
通过这些更改,代码正在正确编译。 但是,"功能"未放置在所需位置0x000C0000
为什么会这样?
答案 0 :(得分:0)
您可以将_Pragma("location=\"__your_section__\"")
放在功能前面。
然后在链接器文件中(例如):
define block __your_section_block__ size = 0x100 { section __your_section__ };
并确保将该行添加到链接器:
place in MY_FUNC { block __your_section_block__ };
答案 1 :(得分:0)
您应该在.icf文件中将“ MY_FUNC ”的定义更改为“ MY_FUNC_region ”,以避免混淆:
define region MY_FUNC_region = mem:[from region_MY_FUNC_start to region_MY_FUNC_end];
然后添加以下行,将“ MY_FUNC”代码放入“ MY_FUNC_region”中:
place in MY_FUNC_region { readonly section MY_FUNC };
(不确定是否绝对需要“只读”关键字,但对我有用)
或者,或者:
place at address mem:region_MY_FUNC_start { readonly section MY_FUNC};