其他分享
首页 > 其他分享> > 如何将部分代码和数据加载到sram中运行

如何将部分代码和数据加载到sram中运行

作者:互联网

在嵌入式应用场景中,有些代码和数据是运行在ddr中,甚至有些代码是在flash中,有的时候需要提升性能,需要将频率比较高的代码和数据放到片内sram中运行。

如下说明实现实现方式

首先在连接脚本中定义相应的段:

.rtm_code : {
*(.rtm_code.*);
. = ALIGN(0x4);
} > OCM_CODE

.rtm_data : {
_start_rtm_data = .;
*(.rtm_data.*);
. = ALIGN(0x4);
} > OCM_DATA

 

__RTM_START = ADDR(.rtm_code );
__RTM_SIZE = SIZEOF(.rtm_code );

然后在程序中将代码和数据定向到制定的段中

uint32_t __attribute__((aligned(0x04))) mem_sram[1024] __attribute__((__section__(".rtm_data.*")));
uint32_t __attribute__((aligned(0x04))) mem_sram2[1024] __attribute__((__section__(".rtm_data.*")));

__attribute__((__section__(".rtm_code.*"))) int mem_sram_test_func(int i)
{
int j = 0;

for(j = 0; j < i; j++) {
bios_log("sram code test, sram[%d]=%d\r\n",j, mem_sram[j]);
}

while(1);
}

最后程序的加载可以在启动代码中添加分段加载代码。

 在汇编代码中可以引用__RTM_START 和__RTM_SIZE 这两个符号实现代码的加载。

 

标签:__,code,rtm,sram,代码,attribute,加载
来源: https://www.cnblogs.com/mic-chen/p/16577747.html