返回> 网站首页
IAR环境中实现数据或函数的FLASH定位
yoours2014-09-12 11:21:28
简介一边听听音乐,一边写写文章。
EW targets: | ARM |
EW component: | C/C++ compiler |
Keywords: | "@" / #pragma locate, absolute address |
Last update: | October 29, 2013 |
This tech note applies to...
...versions 5.xx to 6.20 of EWARM
About newer versions (6.30 and higher)
The ELF format is open for vendor/toolchain-specific extensions. ICCARM uses such an extension since version 6.30 to deal with absolutely placed constants.
Background
Background - general
There are major changes in the EWARM between version 4.x and version 5.x. The link to the right gives some more information.
Background - specific
Absolute placement of constants are not allowed in v5.xx - v6.20, example:
int const a @ 102030;
Problem
There is no _standard_ way of expressing the above in an output file in the elf/dwarf format.
Solution suggestions
Solution 1 - (if you must use const)
The solution consists of two changes.
In the .c file place the variable in a named segment. In the .icf (for the linker) place the segment at a specific location.
The C source can have looked like this in v4.xx (also allowed in v6.30 and later):
const char RELEASEDATE[16] @ 0x0000FF10 = __DATE__ ; const char RELEASETIME[16] @ 0x0000FF20 = __TIME__ ;
Note: In v6.30 and later, compiling with option --aeabi will generate the same error for absolute placed constant data as the previous versions (v5.xx - v6.20).
The C source needs to be changed in the .c file (v5.xx - v6.20) to the following:
#pragma location = "ConstSection1" __root const char RELEASEDATE[16] = __DATE__ ; #pragma location = "ConstSection2" __root const char RELEASETIME[16] = __TIME__ ;
In the .icf file are these lines added:
place at address mem: 0x0000FF10 { readonly section ConstSection1 }; place at address mem: 0x0000FF20 { readonly section ConstSection2 };
The linker will place the sections ConstSection1 at address 0x0000FF10, and the section ConstSection2 at address 0x0000FF20.
Solution 2 - (if you dare not to use const)
The solution (v5.xx - v6.20) consists of a change from..
int const a @ 102030;
...to...
int a @ 102030;
...the drawback of this solution is that you disable the ICCARM which make checks for "do not write to const object". So this solution can lead to run-time errors.
Migration
It is also highly recommended that you have a look at the "The migration process" in the above guide. This will give you a good picture of what has to be done to migrate from version 4 to version 5 of the ARM IAR Embedded Workbench.
All product names are trademarks or registered trademarks of their respective owners.