打印

IAR FOR STM8 在RAM运行代码的问题,已解决。走了很多弯路

[复制链接]
20837|12
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jgphu|  楼主 | 2013-6-27 15:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 jgphu 于 2013-6-28 10:15 编辑

我用STVD 做升级的程序是没有问题, 最近想做一个IAR的。

于是参考网上的做法:
icf文件里面

initialize by copy { ro section MyCodeInRAM };//这句是将代码在程序初始化的时候copy到RAM的。
place in NearData  { ro section MyCodeInRAM };//定义段的位置

c文件里面
void abc(void)@"MyCodeInRAM"//直接将函数限定在段中
{
     ......
     ......
     ......
}

结果 只要是调用了这个abc函数就会出现报错。


下面是我改的:
initialize by copy { rw section .far.bss,
                     rw section .far.data,
                     rw section .far_func.textrw,
                     rw section .huge.bss,
                     rw section .huge.data,
                     rw section .huge_func.textrw,
                     rw section .iar.dynexit,
                     rw section .near.bss,
                     rw section .near.data,
                     rw section .near_func.textrw,
                     rw section .tiny.bss,
                     rw section .tiny.data,
                     ro section .tiny.rodata,
        ro section .far.MyCodeInRam};

place in NearData               { block HEAP,
                                  rw section .far.bss,
                                  rw section .far.data,
                                  rw section .far.noinit,
                                  rw section .far_func.textrw,
                                  rw section .huge.bss,
                                  rw section .huge.data,
                                  rw section .huge.noinit,
                                  rw section .huge_func.textrw,
                                  rw section .iar.dynexit,
                                  rw section .near.bss,
                                  rw section .near.data,
                                  rw section .near.noinit,
                                  rw section .near_func.textrw,
                                  ro section .far.MyCodeInRam };

报错是:
Error[Lc036]: no block or place matches the pattern "ro code section MyCodeInRam in app_bootupdata.o"
根据固件库flash.c里的描述
- For IAR Compiler:
    1- Use the __ramfunc keyword in the function declaration to specify that it
    can be executed from RAM..
    This is done within the stm8s_flash.c file, and it's conditioned by
    RAM_EXECUTION definition.
    2- Uncomment the "#define RAM_EXECUTION  (1)" line in the stm8s.h file, or
   define it in IAR compiler preprocessor to enable the access for the
   __ramfunc functions.

只需要在写FLASH的函数前加一个__ramfunc就可以了。__ramfunc void Flash_WriteProgramBlock(uint8_t BlockNum, uint8_t *Buffer)
不需要改ICF文件了。

试了几次,写FLASH操作成功。

不过加了__ramfunc后,IAR会报一个警告不知道是什么意思:Warning[Ta005]: Library call (?epilogue_l2) from within a __ramfunc function







沙发
jgphu|  楼主 | 2013-6-27 15:05 | 只看该作者
调用函数是这个
void BootUpdataHandle(void)@"MyCodeInRam"
{
         ;
}

使用特权

评论回复
板凳
jgphu|  楼主 | 2013-6-27 17:59 | 只看该作者
/////////////////////////////////////////////////////////////////
//      Example ILINK command file for
//      STM8 IAR C/C++ Compiler and Assembler.
//
//      Copyright 2010 IAR Systems AB.
//
//      $Revision: 2384 $
//
/////////////////////////////////////////////////////////////////

define memory with size = 16M;

define region TinyData = [from 0x00 to 0xFF];

define region NearData = [from 0x0000 to 0x0FFF];

define region Eeprom = [from 0x4000 to 0x45FF];

define region BootROM = [from 0x6000 to 0x67FF];

define region NearFuncCode = [from 0x9000 to 0xFFFF];

define region FarFuncCode = [from 0x9000 to 0xFFFF]
                          | [from 0x10000 to 0x17FFF];

define region HugeFuncCode = [from 0x9000 to 0x17FFF];


/////////////////////////////////////////////////////////////////

define block CSTACK with size = _CSTACK_SIZE  {};

define block HEAP  with size = _HEAP_SIZE {};

define block INTVEC with size = 0x80 { ro section .intvec };


// Initialization
initialize by copy { rw section FLASH_CODE,
                     rw section .far.bss,
                     rw section .far.data,
                     rw section .far_func.textrw,
                     rw section .huge.bss,
                     rw section .huge.data,
                     rw section .huge_func.textrw,
                     rw section .iar.dynexit,
                     rw section .near.bss,
                     rw section .near.data,
                     rw section .near_func.textrw,
                     rw section .tiny.bss,
                     rw section .tiny.data,
                     ro section .tiny.rodata};

do not initialize  { rw section .eeprom.noinit,
                     rw section .far.noinit,
                     rw section .huge.noinit,
                     rw section .near.noinit,
                     rw section .tiny.noinit,
                     rw section .vregs };

// Placement
place at start of TinyData      { rw section .vregs };
place in TinyData               { rw section .tiny.bss,
                                  rw section .tiny.data,
                                  rw section .tiny.noinit,
                                  rw section .tiny.rodata };

place at end of NearData        { block CSTACK };
place in NearData               { block HEAP,
                                  rw section .far.bss,
                                  rw section .far.data,
                                  rw section .far.noinit,
                                  rw section .far_func.textrw,
                                  rw section .huge.bss,
                                  rw section .huge.data,
                                  rw section .huge.noinit,
                                  rw section .huge_func.textrw,
                                  rw section .iar.dynexit,
                                  rw section .near.bss,
                                  rw section .near.data,
                                  rw section .near.noinit,
                                  rw section .near_func.textrw};

place at start of NearFuncCode  { block INTVEC };
place in NearFuncCode           { ro section FLASH_CODE,
                                  ro section .far.data_init,
                                  ro section .far_func.textrw_init,
                                                     ro section .huge.data_init,
                                  ro section .huge_func.textrw_init,
                                  ro section .iar.init_table,
                                  ro section .init_array,
                                  ro section .near.data_init,
                                  ro section .near.rodata,
                                  ro section .near_func.text,
                                  ro section .near_func.textrw_init,
                                  ro section .tiny.data_init,
                                  ro section .tiny.rodata_init};

place in FarFuncCode            { ro section .far.rodata,
                                  ro section .far_func.text };

place in HugeFuncCode           { ro section .huge.rodata,
                                  ro section .huge_func.text };

place in Eeprom                 { rw section .eeprom.noinit };

define region BootUpdataCode = [from 0xE000 to 0xFFFF];
place in BootUpdataCode        {ro section .bootupdatatab };



/////////////////////////////////////////////////////////////////

将一个放在 initialize by copy, 一个放在NearFuncCode  。 错误警告没有了,不知道这样改对不对,会不会在RAM里执行。

使用特权

评论回复
地板
hawksabre| | 2013-6-27 18:54 | 只看该作者
不是很了解    楼主   帮你顶一个    再看看别人的意见    需要好好顶一个  

使用特权

评论回复
5
hawksabre| | 2013-6-27 18:55 | 只看该作者
希望有高手能帮忙解决一下    顶一个  

使用特权

评论回复
6
jgphu|  楼主 | 2013-6-27 22:46 | 只看该作者
现在不会报错了。

但是:一执行到这个函数就会重起
void Flash_WriteProgramBlock(uint8_t BlockNum, uint8_t *Buffer)@"FLASH_CODE"

使用特权

评论回复
7
jgphu|  楼主 | 2013-6-28 08:44 | 只看该作者
但我想,即然是在RAM中运行就不应该将ro section FLASH_CODE,放在NearFuncCode 中,这个是FLASH区了

使用特权

评论回复
8
rjw172| | 2013-8-22 23:33 | 只看该作者
楼主解决了没 分享一下方法

使用特权

评论回复
9
zhongquan| | 2014-9-30 16:23 | 只看该作者
Warning[Ta005]: Library call (?epilogue_l2) from within a __ramfunc function  此警告是由于在RAM中的函数去调用一个在FLASH中的函数产生的,此FLASH中的函数是编译器自己产生的,能过查看汇编代码可以发现有一条CALL指令,该指令跳到FLASH区中,我也遇到过这个问题,没有解决,不知怎么样才可以禁止编译器在FLASH中生成代码然后去调用它?

使用特权

评论回复
10
zh113214| | 2014-9-30 19:07 | 只看该作者
恭喜楼主,解决就好,弯路是避免不了的啊QQ@

使用特权

评论回复
11
lexiaoyao2012| | 2015-9-28 17:56 | 只看该作者
感谢,我也搞定了。

使用特权

评论回复
12
lvben5d| | 2016-6-7 08:48 | 只看该作者
帅哥,你的IAR 里 在RAM调用函数 实现了吗? 如果OK,请多多联系啊 有QQ吗

使用特权

评论回复
13
juneII| | 2017-3-16 18:28 | 只看该作者
jgphu 发表于 2013-6-27 17:59
/////////////////////////////////////////////////////////////////
//      Example ILINK command file ...

通过这样改,已经消除错误了,威武!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

7

主题

642

帖子

2

粉丝