硬汉嵌入式论坛

 找回密码
 立即注册
查看: 1063|回复: 7
收起左侧

[IAR] IAR Linker报错问题

[复制链接]

0

主题

3

回帖

3

积分

新手上路

积分
3
发表于 2025-1-11 10:12:20 | 显示全部楼层 |阅读模式
本帖最后由 AwesomeOY 于 2025-1-11 10:16 编辑

MCU: STM32H750VB
环境: IAR 9.30.1

内存分配: Flash空间存储代码;ITCM存储关键代码;DTCM存储ReadWrite数据
icf文件配置如下:
[C] 纯文本查看 复制代码
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\linker\ST\IcfEditor\stm32h7xx.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x08000000;

/*-Memory Regions-*/
define symbol __ICFEDIT_region_FLASH1_start__ = 0x08000000;
define symbol __ICFEDIT_region_FLASH1_end__   = 0x0801FFFF;
define symbol __ICFEDIT_region_ITCMR_start__  = 0x00000008;
define symbol __ICFEDIT_region_ITCMR_end__    = 0x0000FFFF;
define symbol __ICFEDIT_region_DTCMR1_start__ = 0x20000000;
define symbol __ICFEDIT_region_DTCMR1_end__   = 0x2001FFFF;
define symbol __ICFEDIT_region_AXISR_start__  = 0x24000000;
define symbol __ICFEDIT_region_AXISR_end__    = 0x2407FFFF;
define symbol __ICFEDIT_region_SRAM1_start__  = 0x30000000;
define symbol __ICFEDIT_region_SRAM1_end__    = 0x3001FFFF;
define symbol __ICFEDIT_region_SRAM2_start__  = 0x30020000;
define symbol __ICFEDIT_region_SRAM2_end__    = 0x3003FFFF;
define symbol __ICFEDIT_region_SRAM3_start__  = 0x30040000;
define symbol __ICFEDIT_region_SRAM3_end__    = 0x30047FFF;
define symbol __ICFEDIT_region_SRAM4_start__  = 0x38000000;
define symbol __ICFEDIT_region_SRAM4_end__    = 0x3800FFFF;
define symbol __ICFEDIT_region_BKPR_start__   = 0x38800000;
define symbol __ICFEDIT_region_BKPR_end__     = 0x38800FFF;
define symbol __ICFEDIT_region_SDR1_start__   = 0x0;
define symbol __ICFEDIT_region_SDR1_end__     = 0x0;
define symbol __ICFEDIT_region_SDR2_start__   = 0x0;
define symbol __ICFEDIT_region_SDR2_end__     = 0x0;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__     = 0x800;
//define symbol __ICFEDIT_size_proc_stack__ = 0x0;
define symbol __ICFEDIT_size_heap__       = 0x800;
/**** End of ICF editor section. ###ICF###*/

define memory mem with size = 4G;
define region FLASH_region  =   mem:[from __ICFEDIT_region_FLASH1_start__ to __ICFEDIT_region_FLASH1_end__];
define region ITCMR_region  =   mem:[from __ICFEDIT_region_ITCMR_start__  to __ICFEDIT_region_ITCMR_end__ ];
define region DTCMR_region  =   mem:[from __ICFEDIT_region_DTCMR1_start__ to __ICFEDIT_region_DTCMR1_end__];
define region AXISR_region  =   mem:[from __ICFEDIT_region_AXISR_start__  to __ICFEDIT_region_AXISR_end__ ];
define region SRAM1_region  =   mem:[from __ICFEDIT_region_SRAM1_start__  to __ICFEDIT_region_SRAM1_end__ ];
define region SRAM2_region  =   mem:[from __ICFEDIT_region_SRAM2_start__  to __ICFEDIT_region_SRAM2_end__ ];
define region SRAM3_region  =   mem:[from __ICFEDIT_region_SRAM3_start__  to __ICFEDIT_region_SRAM3_end__ ];
define region SRAM4_region  =   mem:[from __ICFEDIT_region_SRAM4_start__  to __ICFEDIT_region_SRAM4_end__ ];

define block CSTACK     with alignment = 8, size = __ICFEDIT_size_cstack__     { };
//define block PROC_STACK with alignment = 8, size = __ICFEDIT_size_proc_stack__ { };
define block HEAP       with alignment = 8, size = __ICFEDIT_size_heap__       { };

initialize by copy { readwrite };
initialize by copy { section .text_rw };

if (isdefinedsymbol(__USE_DLIB_PERTHREAD))
{
  // Required in a multi-threaded application
  initialize by copy with packing = none { section __DLIB_PERTHREAD };
}

place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place in DTCMR_region  { readwrite, section dtcm_ram, block CSTACK, block HEAP};
place in AXISR_region  { section .sram_axi };
place in SRAM1_region  { section .sram1 };
place in SRAM2_region  { section .sram2 };
place in SRAM3_region  { section .sram3 };
place in SRAM4_region  { section .sram4 };

place in FLASH_region  { readonly };

initialize by copy {
  section .text object msp.o
};

place in ITCMR_region  { section .textrw };
place in ITCMR_region  {
  section .text object msp.o
};

但是编译会报链接器错误,不知道什么原因,有大神指点下吗?
[C] 纯文本查看 复制代码
错误:
	Warning[Lp051]: some sections in automatic block ".text" would have been placed differently if they were not part of an automatic block. Example: section ".text (msp.o #8)" would have matched "object msp.o section .text" Hat line 75 of "D:\SVN_Project\UAM221\trunk\UAM221_H750VB_APP\EWARM\stm32h750xx_flash.icf"h. Instead, it is placed in block ".text" which matched "rw" Hat line 60 of "D:\SVN_Project\UAM221\trunk\UAM221_H750VB_APP\EWARM\stm32h750xx_flash.icf"h.			
	Error[Lp008]: ambiguous placement when building the automatic block ".text": member "ro code section .text" matches a different place ("P7" Hat line 67 of "D:\SVN_Project\UAM221\trunk\UAM221_H750VB_APP\EWARM\stm32h750xx_flash.icf"h) than member "rw code section .text" ("P1" Hat line 60 of "D:\SVN_Project\UAM221\trunk\UAM221_H750VB_APP\EWARM\stm32h750xx_flash.icf"h)			
	Error[Lp005]: placement includes a mix of sections with content (example "ro code section .text in app.o symbols: [app_loop, get_radar_core, app_init]")  [suitable for placement in ROM] and sections without content (example "rw code section .text in msp.o symbols: [msp_rangfinder_data_message_encode, crc8_calc, crc8_update]") [suitable for placement in RAM]	D:\SVN_Project\UAM221\trunk\UAM221_H750VB_APP\EWARM\stm32h750xx_flash.icf	67	

单独用简单的工程使用icf配置是没有问题的,但是结合该工程(源码模块多)就出现上面的报错。

回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117512
QQ
发表于 2025-1-12 07:29:00 | 显示全部楼层
GPT回复:

这些错误通常是由于只读和读写部分混合在同一个块中引起的。以下是一些解决方案:

分离只读和读写部分:确保只读部分(如代码)放置在ROM中,而读写部分(如数据)放置在RAM中。你可以将只读部分放置在FLASH_region中,将读写部分放置在DTCMR_region中。

明确部分放置:避免在多个区域中定义同一个部分。例如,可以将.text部分明确放置在一个区域中,避免在其他区域中重复定义。

检查初始化指令:确保initialize by copy指令正确使用,并且被初始化的部分已正确定义。


[C] 纯文本查看 复制代码
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\linker\ST\IcfEditor\stm32h7xx.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x08000000;

/*-Memory Regions-*/
define symbol __ICFEDIT_region_FLASH1_start__ = 0x08000000;
define symbol __ICFEDIT_region_FLASH1_end__   = 0x0801FFFF;
define symbol __ICFEDIT_region_ITCMR_start__  = 0x00000008;
define symbol __ICFEDIT_region_ITCMR_end__    = 0x0000FFFF;
define symbol __ICFEDIT_region_DTCMR1_start__ = 0x20000000;
define symbol __ICFEDIT_region_DTCMR1_end__   = 0x2001FFFF;
define symbol __ICFEDIT_region_AXISR_start__  = 0x24000000;
define symbol __ICFEDIT_region_AXISR_end__    = 0x2407FFFF;
define symbol __ICFEDIT_region_SRAM1_start__  = 0x30000000;
define symbol __ICFEDIT_region_SRAM1_end__    = 0x3001FFFF;
define symbol __ICFEDIT_region_SRAM2_start__  = 0x30020000;
define symbol __ICFEDIT_region_SRAM2_end__    = 0x3003FFFF;
define symbol __ICFEDIT_region_SRAM3_start__  = 0x30040000;
define symbol __ICFEDIT_region_SRAM3_end__    = 0x30047FFF;
define symbol __ICFEDIT_region_SRAM4_start__  = 0x38000000;
define symbol __ICFEDIT_region_SRAM4_end__    = 0x3800FFFF;
define symbol __ICFEDIT_region_BKPR_start__   = 0x38800000;
define symbol __ICFEDIT_region_BKPR_end__     = 0x38800FFF;
define symbol __ICFEDIT_region_SDR1_start__   = 0x0;
define symbol __ICFEDIT_region_SDR1_end__     = 0x0;
define symbol __ICFEDIT_region_SDR2_start__   = 0x0;
define symbol __ICFEDIT_region_SDR2_end__     = 0x0;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__     = 0x800;
//define symbol __ICFEDIT_size_proc_stack__ = 0x0;
define symbol __ICFEDIT_size_heap__       = 0x800;
/**** End of ICF editor section. ###ICF###*/

define memory mem with size = 4G;
define region FLASH_region  =   mem:[from __ICFEDIT_region_FLASH1_start__ to __ICFEDIT_region_FLASH1_end__];
define region ITCMR_region  =   mem:[from __ICFEDIT_region_ITCMR_start__  to __ICFEDIT_region_ITCMR_end__ ];
define region DTCMR_region  =   mem:[from __ICFEDIT_region_DTCMR1_start__ to __ICFEDIT_region_DTCMR1_end__];
define region AXISR_region  =   mem:[from __ICFEDIT_region_AXISR_start__  to __ICFEDIT_region_AXISR_end__ ];
define region SRAM1_region  =   mem:[from __ICFEDIT_region_SRAM1_start__  to __ICFEDIT_region_SRAM1_end__ ];
define region SRAM2_region  =   mem:[from __ICFEDIT_region_SRAM2_start__  to __ICFEDIT_region_SRAM2_end__ ];
define region SRAM3_region  =   mem:[from __ICFEDIT_region_SRAM3_start__  to __ICFEDIT_region_SRAM3_end__ ];
define region SRAM4_region  =   mem:[from __ICFEDIT_region_SRAM4_start__  to __ICFEDIT_region_SRAM4_end__ ];

define block CSTACK     with alignment = 8, size = __ICFEDIT_size_cstack__     { };
//define block PROC_STACK with alignment = 8, size = __ICFEDIT_size_proc_stack__ { };
define block HEAP       with alignment = 8, size = __ICFEDIT_size_heap__       { };

initialize by copy { readwrite };
initialize by copy { section .text_rw };

if (isdefinedsymbol(__USE_DLIB_PERTHREAD))
{
  // Required in a multi-threaded application
  initialize by copy with packing = none { section __DLIB_PERTHREAD };
}

place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place in DTCMR_region  { readwrite, section dtcm_ram, block CSTACK, block HEAP};
place in AXISR_region  { section .sram_axi };
place in SRAM1_region  { section .sram1 };
place in SRAM2_region  { section .sram2 };
place in SRAM3_region  { section .sram3 };
place in SRAM4_region  { section .sram4 };

place in FLASH_region  { readonly };

initialize by copy {
  section .text object msp.o
};

place in ITCMR_region  { section .textrw };
place in ITCMR_region  {
  section .text object msp.o
};
回复

使用道具 举报

3

主题

90

回帖

99

积分

初级会员

积分
99
发表于 2025-1-13 11:05:26 | 显示全部楼层
你自己也说了,Flash空间存储代码;ITCM存储关键代码。ITCM是RAM,也就是说一部分代码是在RAM里的。在icf文件里需要对RAM代码有正确的定位和初始化。
回复

使用道具 举报

0

主题

3

回帖

3

积分

新手上路

积分
3
 楼主| 发表于 2025-1-13 11:22:36 | 显示全部楼层
eric2013 发表于 2025-1-12 07:29
GPT回复:

这些错误通常是由于只读和读写部分混合在同一个块中引起的。以下是一些解决方案:

现在确实还没有弄明白,其中msp.o是一个和其他模块没有关联的程序模块,完全独立的,但编译一直报错。
我看icf文件也没有错误,只是DTCM内存用于存储readwrite数据,ITCM内存存储msp程序,Flash存储其他程序代码。
回复

使用道具 举报

0

主题

3

回帖

3

积分

新手上路

积分
3
 楼主| 发表于 2025-1-13 14:08:55 | 显示全部楼层
qinfeng173 发表于 2025-1-13 11:05
你自己也说了,Flash空间存储代码;ITCM存储关键代码。ITCM是RAM,也就是说一部分代码是在RAM里的。在icf文 ...

问题是我已经按照iicf文件规则定了分配了各个段的存储范围,请看下面,或者你能发现其中哪里有问题
[C] 纯文本查看 复制代码
initialize by copy { readwrite, section .text_rw, section .text object msp.o };
place in ITCMR_region  { section .text object msp.o };
place in FLASH_region  { readonly };
place in DTCMR_region  { readwrite, block CSTACK, block HEAP};
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117512
QQ
发表于 2025-1-14 13:34:49 | 显示全部楼层
AwesomeOY 发表于 2025-1-13 14:08
问题是我已经按照iicf文件规则定了分配了各个段的存储范围,请看下面,或者你能发现其中哪里有问题
[mw_ ...

ITCM配置应该有问题,你得保证加载域在Flash里面,而执行域在ITCM,这种才合理
回复

使用道具 举报

0

主题

3

回帖

3

积分

新手上路

积分
3
 楼主| 发表于 2025-1-17 16:41:24 | 显示全部楼层
eric2013 发表于 2025-1-14 13:34
ITCM配置应该有问题,你得保证加载域在Flash里面,而执行域在ITCM,这种才合理

这个要怎么确定呢?加载程序代码是放在Flash中的
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117512
QQ
发表于 2025-1-18 09:03:55 | 显示全部楼层
AwesomeOY 发表于 2025-1-17 16:41
这个要怎么确定呢?加载程序代码是放在Flash中的

这个得搜下了,看下IAR这里应该怎么正确配置加载域和执行域
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-8-12 03:37 , Processed in 0.045500 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表