STM8S IAR 中常量变量函数绝对位置设置

三种方法,举例如下:

1.需要修改icf文件。
#pragma location ="ConstSection1"
__root __no_int char RELEASEDATE[16]  @"ConstSection1";

在icf文件中增加下面
place at address mem:0x08001000 { readonly section ConstSection1 };

注意:icf中需要有';'结尾;
2.
__root __no_init char RELEASEDATE[16] @0x08010000;

3.
#pragma location =0x08010000
__root __no_init char
RELEASEDATE[16];

#if  1
 #pragma location= "ConstSection1"
__root const unsigned int test = 0xaabb;
 #pragma location= "ConstSection2"
__root const unsigned int test1 = 0xccdd;
#endif
 
#pragma location=0x9ff0
__root const unsigned int test[]   = {0xaa,0xbb,0xcc};
__root const unsigned int test1 @0x9ff8 = 0xaabc;

变量绝对定位:

__no_init char array1[100]@0x2000B000;


变量绝对定位,无须修改.icf,直接指定


这个array1就定位在RAM中的0x2000B000处


常量绝对定位:

const char str1[8]@".MYSEG"="test11!!";

常量绝对定位,需要改.icf文件:

place at address mem:0x08018500 { readonly section .MYSEG};

const 常量 icf里面加上 place at address mem: 0x8402 { ro section ConstSection1}; 然后在程序段 #pragma location= "ConstSection1" __root const unsigned char test = 0xaa; 编译结果hex部分截取如下 :01840200AACF 函数应该也是同理

你可能感兴趣的:(编程)