IAR将特定函数或者变量链接放入指定内存位置---Placing a group of functions or variables in a specific section

https://www.iar.com/knowledge/support/technical-notes/linker/how-do-i-place-a-group-of-functions-or-variables-in-a-specific-section/

 

总结有两种办法:

方法一:使用多个  #pragma location

  

 1 #pragma default_function_attributes = @ "MY_FUNC"
 2 
 3 int fun1(int x)
 4 {
 5     return x + 1;
 6 }
 7 
 8 int fun2(int x)
 9 {
10     return x - 1;
11 }
12 
13 /* Stop placing functions in section MY_FUNC */
14 #pragma default_function_attributes =
15 
16 int fun3(int x)
17 {
18     return x + x;
19 }
20 
21 /* Place following data in section MY_DATA */
22 #pragma default_variable_attributes = @ "MY_DATA"
23 
24 int data1;
25 int data2;
26 
27 /* Stop placing data in section MY_DATA */
28 #pragma default_variable_attributes =
29 
30 
31 int data3;
32 
33 int main()
34 {
35     data1 = fun1(5);
36     data2 = fun2(5);
37     data3 = fun3(5);
38 
39     return data1 + data2 + data3;
40 }

icf文件修改如下:

define region DATA_region = mem:[from 0x20000000 to 0x20001FFF ];
place in DATA_region { readwrite section MY_DATA };



方法二:将自己想操作的函数变量放到一个C文件中,然后将其   .o  文件一并放入指定链接区域。

1 define region UTILITIES_region = mem:[ from 0x71000 to 0x71FFF ];
2 place in UTILITIES_region { readonly object Utilities.o };

其中 Utilities.o 就是由  集合了函数和变量的 Utilities.c  生成的。

 

方法二相比方法一,要简易一些。

posted @ 2023-06-05 22:02  昆山皮皮虾  阅读(1134)  评论(0)    收藏  举报