Keil_MDK 中绝对地址定位问题

在项目开发过程中,要求对部分函数接口、变量数组、obj文件、bin文件等要指定位置。

以下是我项目中遇到的问题及如何解决的方案:
## 对部分函数接口指定位置: ##
应用场景说明:当IAP(提供下载程序的功能)和应用程序编写在一个工程文件中时,需要对IAP程序指定相应的地址(如:0x0001000 ~0x0008000),目的是为了保证能区分开IAP和应用程勋的存放位置。
因此需要进行如下操作

a、首先在sct脚本中编写一个段空间(网上可以搜索到sct链接脚本的语法格式及说明,这里不再叙述),如下所示:IAP_IROM的段空间的定义。
LR_IROM1 0x00000000 0x00010000  {    ; load region size_region
  ER_IROM1 0x00000000 0x0001000  {  ; load address = execution address
    *.o (RESET, +First)
    *(InRoot$$Sections)
  }

IAP_IROM 0x0001000 0x0007000   {  ; load address = execution address
    *.o(iapSection)
  }

APP_IROM 0x0008000 0x00010000 {
    .ANY (+RO)
  }

RW_IRAM1 0x20000000 0x00004000  {  ; RW data
   .ANY (+RW +ZI)
  }
}
b、然后在每个需要放入IAP_IROM 区域的函数进行如下定义:
__attribute__ ((section ("iapSection"))) int f3()
{
  return 1;
} 

为了使程序显得更加美观,因此建议采用宏定义的方式编写

#define __IAP (__attribute__ ((section ("iapSection"))))

 int __IAP f3()
{
  return 1;
}

void __IAP f4()
{
  ...
  return 1;
}

以上这个写法是模仿Linux中驱动编写的方式。
c、如果还是不喜欢上述风格,则可以利用下面这种预处理指令

#pragma arm section code="iapSection"
  int f2()
  {
      return 1;
  }          // into the 'iapSection' area

  int f4()
  {
      return 1;
  }         // into the 'iapSection' area   

#pragma arm section                 

## 变量数组指定位置 ##
未完待续。。。

你可能感兴趣的:(Cortex-M0,Cortex-M3,Cortex-M4,Kei-MDK)