iar中 让代码在sram中运行

环境:iar 8.40.1  MCU:mk64

1.关键字__ramfunc

        iar中可以利用关键字__ramfunc将函数放在ram中,带__ramfunc的函数调用不带__ramfunc的函数会出现警告,同时cpu 执行速度会变慢。__ramfunc不能指定地址。

  

        

        ox1fff0015是sram中

2.通过修改icf文件

       1.添加自动copy

initialize by copy { readwrite, section RAMCODE};

       2.将section RAMCODE放到ram中

place in DATA_region                        {section RAMCODE};

       3.添加测试代码

       

//方式1
 void testfun(void) @"RAMCODE"
{
  uint8_t a=3, b=4, c;
  c=a+b; 
  PRINTF("\r\n c is value is %d\r\n", c);
}
//方式2
#pragma location = "RAMCODE" 
void testfun(void) //@"RAMCODE"
{
  uint8_t a=3, b=4, c;
  c=a+b; 
  PRINTF("\r\n c is value is %d\r\n", c);
}
//方式3 该方法可以同时将多个函数放到 RAMCODE中
#pragma default_function_attributes = @"RAMCODE" 
void testfun1(void) //@"RAMCODE"
{
  uint8_t a=3, b=4, c;
  c=a+b; 
  PRINTF("\r\n c is value is %d\r\n", c);
}

void testfun2(void) //@"RAMCODE"
{
  uint8_t a=3, b=4, c;
  c=a+b; 
  PRINTF("\r\n c is value is %d\r\n", c);
}
    .
    .
    .
#pragma default_function_attributes =
发布了6 篇原创文章 · 获赞 0 · 访问量 516

猜你喜欢

转载自blog.csdn.net/qq_34492122/article/details/99703507