Mic_chen

It is not the strongest of the species that survive, nor the most intelligent, but the one most responsive to change

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

在嵌入式应用场景中,有些代码和数据是运行在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 这两个符号实现代码的加载。

 

posted on 2022-08-11 20:20  Mic_chen  阅读(455)  评论(0编辑  收藏  举报