返回> 网站首页 

IAR环境中实现数据或函数的FLASH定位

yoours2014-09-12 11:21:28 阅读 1720

简介一边听听音乐,一边写写文章。

一、
1、__no_init char alpha @ 0x0200; 
2、#pragma location=0x0202
const int beta; 
3、const int gamma @ 0x0204 = 3; 

二、
1、__no_init int alpha @ "MYSEGMENT"; //MYSEGMENT段可在XCL中开辟
2、#pragma location="MYSEGMENT"
const int beta; 
3、const int gamma @ "MYSEGMENT" = 3; 

icf文件
place at address mem: 0x08004184 { ro section ConstSection1};
 代码文件
#pragma location= "ConstSection1"
//__root const unsigned char test = 0xaa;
//__root const BYTE ll = 0;
__root const unsigned char Lcodes_32[4][2];

三、函数定位如下面两种写法
1、
void g(void) @ "MYSEGMENT" //MYSEGMENT段可在XCL中开辟
{
}

2、
#pragma location="MYSEGMENT"
void h(void)
{
}

五、更改XCL文件
注意:在实现过程中可能涉及到.XCL连接文件的更改,请保存好原来的.XCL文件!
1.打开相应的*c.xcl文件,用"-Z(CONST)段名=程序定位的目标段-FFDF"定义段的起始地址.
2.在自己的C程序中用#pragma constseg(段名)定位自己的程序
3.结束后恢复编译器的默认定位#pragma default

IAR 1.26b环境下:
1、将常量数组放在FLASH段自定议的MYSEG段中

原来的MSP430F149 XCL文件如下:
// Constant data
-Z(CONST)DATA16_C,DATA16_ID,DIFUNCT,CHECKSUM=1100-FFDF
如果想从中分出一部分做数据存储区,做如下修改:
-Z(CONST)DATA16_C,DATA16_ID,DIFUNCT,CHECKSUM=1500-FFDF //将1100-14FF从ROM中分出存储arry数组
-Z(CONST)MYSEG=1100-14FF区间大小可自行决定

在程序中描写如下即可:
#pragma memory = constseg(MYSEG) //在.XCL文件中修改
char arry[]={1,2,3,4,5,6,7};
#pragma memory = default

2、将变量放入所命名的段
在XCL文件中开辟一段MYSEG段,如上所述
#pragma memory = dataseg(MYSEG)
char i;
char j;
int k;
#pragma memory = default

===================================================================
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.

微信小程序扫码登陆

文章评论

1720人参与,0条评论