搜索
bottom↓
回复: 15

请教:关于IAR中,将变量定位到指定位置的问题

[复制链接]

出0入0汤圆

发表于 2017-11-4 13:34:18 | 显示全部楼层 |阅读模式
大家好。

我遇到一个问题,在IAR编译器环境下,我想将某个文件中的所有变量指定到某段内存中。

我参考网上资料用如下代码却得不到正确的结果。

place in RAM_region2 {  readwrite data object aa.o};
place in RAM_region2 {  readwrite data object bb.o};

上面的代码就是希望连接器将aa.o和bb.o中的readwrite data 放到内存段 RAM_region2 中。

但链接出来后却不是这样的。

请教大家问题出再哪里?

阿莫论坛20周年了!感谢大家的支持与爱护!!

月入3000的是反美的。收入3万是亲美的。收入30万是移民美国的。收入300万是取得绿卡后回国,教唆那些3000来反美的!

出0入0汤圆

发表于 2017-11-4 13:43:14 | 显示全部楼层
https://www.iar.com/support/tech ... a-specific-section/

出0入0汤圆

发表于 2017-11-4 13:44:03 | 显示全部楼层
/* Place following data in section MY_DATA */
#pragma default_variable_attributes = @ "MY_DATA"

int data1;
int data2;

/* Stop placing data in section MY_DATA */
#pragma default_variable_attributes =

int data3;

int main()
{
    data1 = fun1(5);
    data2 = fun2(5);
    data3 = fun3(5);

    return data1 + data2 + data3;
}

define region DATA_region = mem:[from 0x20000000 to 0x20001FFF ];
place in DATA_region { readwrite section MY_DATA };

出0入0汤圆

 楼主| 发表于 2017-11-4 13:55:22 | 显示全部楼层
shangdawei 发表于 2017-11-4 13:44
/* Place following data in section MY_DATA */
#pragma default_variable_attributes = @ "MY_DATA"


感谢!

不过,有没有简单一点的办法,可以整个OBJ文件一起处理。KEIL是可以的,只要放入文件名就可以了。

如果用您的方式,就必须每个文件都要处理以下才行。

出0入0汤圆

 楼主| 发表于 2017-11-4 13:59:28 | 显示全部楼层

下面是网上找到的,不过好像不好用

place in ROM { readonly }; /* all readonly sections */ place in RAM { readwrite }; /* all readwrite sections */

place in RAM { block HEAP, block CSTACK, block IRQ_STACK };
place in ROM { section .text object myfile.o }; /* the .text section of myfile.o */
place in ROM { readonly object myfile.o }; /* all read-only sections of myfile.o */
place in ROM { readonly data object myfile.o }; /* all read-only data sections myfile.o */

出0入0汤圆

发表于 2017-11-4 17:52:01 | 显示全部楼层



define block objectx { rw object object*.o }; <== 支持通配符
place in IRAM2_region  { block objectx };

  1. ==================================================================================
  2. uint8_t object1_var_uint8;
  3. uint16_t object1_var_uint16;
  4. uint32_t object1_var_uint32;

  5. ==================================================================================
  6. uint8_t object2_var_uint8;
  7. uint16_t object2_var_uint16;
  8. uint32_t object2_var_uint32;

  9. ==================================================================================
  10. __root uint32_t main_var_result;
  11. __root uint8_t main_var_uint8_zi = 0;
  12. __root uint8_t main_var_uint8 = 8;
  13. __root uint16_t main_var_uint16 = 16;
  14. __root uint32_t main_var_uint32 = 32;

  15. ==================================================================================
  16. main_var_result         0x20000004   0x4  Data  Gb  main.o [1]
  17. main_var_uint16         0x20000008   0x2  Data  Gb  main.o [1]
  18. main_var_uint32         0x20000000   0x4  Data  Gb  main.o [1]
  19. main_var_uint8          0x2000000a   0x1  Data  Gb  main.o [1]
  20. main_var_uint8_zi       0x2000000b   0x1  Data  Gb  main.o [1]

  21. ==================================================================================
  22. object1_var_uint16      0x20010008   0x2  Data  Gb  object1.o [1]
  23. object1_var_uint32      0x20010000   0x4  Data  Gb  object1.o [1]
  24. object1_var_uint8       0x2001000c   0x1  Data  Gb  object1.o [1]

  25. object2_var_uint16      0x2001000a   0x2  Data  Gb  object2.o [1]
  26. object2_var_uint32      0x20010004   0x4  Data  Gb  object2.o [1]
  27. object2_var_uint8       0x2001000d   0x1  Data  Gb  object2.o [1]

  28. ==================================================================================
  29. objectx$Base           0x20010000         --   Gb  - Linker created -
  30. objectx$Limit          0x20010010         --   Gb  - Linker created -


复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

 楼主| 发表于 2017-11-4 17:54:03 来自手机 | 显示全部楼层
shangdawei 发表于 2017-11-4 17:52
define block objectx { rw object object*.o };

非常感谢您!

出0入0汤圆

 楼主| 发表于 2017-11-4 18:26:32 | 显示全部楼层
shangdawei 发表于 2017-11-4 17:52
define block objectx { rw object object*.o };

压缩文件下载不了,谢谢

出0入0汤圆

发表于 2017-11-4 18:51:05 | 显示全部楼层
advarx21ic 发表于 2017-11-4 18:26
压缩文件下载不了,谢谢

正常啊,你试试其他办法下载。

出0入0汤圆

 楼主| 发表于 2017-11-4 19:15:56 | 显示全部楼层
shangdawei 发表于 2017-11-4 18:51
正常啊,你试试其他办法下载。

嗯,能下载,不能解压,解压报错.

出0入0汤圆

 楼主| 发表于 2017-11-4 21:20:35 | 显示全部楼层

试了大半个晚上,发现用#pragma default_variable_attributes 的方式来做是可以正确分配到指定的内存段的.

但是,下面的方式就不行.但有个例外,如果变量用_no_init来定义又可以.

define block objectx { rw object object*.o }; <== 支持通配符
place in IRAM2_region  { block objectx };

出0入0汤圆

发表于 2017-11-4 21:53:30 | 显示全部楼层
advarx21ic 发表于 2017-11-4 19:15
嗯,能下载,不能解压,解压报错.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

 楼主| 发表于 2017-11-4 22:30:41 | 显示全部楼层


下载了2345压缩软件就可以解压了

3s.

出0入296汤圆

发表于 2017-11-5 19:02:15 | 显示全部楼层
本帖最后由 Gorgon_Meducer 于 2017-11-5 19:03 编辑

横跨四编译器的常见编译器扩展:


  1. //! \note for IAR
  2. #ifdef __IS_COMPILER_IAR__
  3.     #undef __IS_COMPILER_IAR__
  4. #endif
  5. #define __IS_COMPILER_IAR__ defined(__IAR_SYSTEMS_ICC__)

  6. //! \note for gcc
  7. #ifdef __IS_COMPILER_GCC__
  8.     #undef __IS_COMPILER_GCC__
  9. #endif
  10. #define __IS_COMPILER_GCC__ defined(__GNUC__)
  11. //! @}

  12. //! \note for arm compiler 5
  13. #ifdef __IS_COMPILER_ARM_COMPILER_5__
  14.     #undef __IS_COMPILER_ARM_COMPILER_5__
  15. #endif
  16. #define __IS_COMPILER_ARM_COMPILER_5__ ((__ARMCC_VERSION >= 5000000) && (__ARMCC_VERSION < 6000000))
  17. //! @}

  18. //! \note for arm compiler 6
  19. #ifdef __IS_COMPILER_ARM_COMPILER_6__
  20.     #undef __IS_COMPILER_ARM_COMPILER_6__
  21. #endif
  22. #define __IS_COMPILER_ARM_COMPILER_6__ ((__ARMCC_VERSION >= 6000000) && (__ARMCC_VERSION < 7000000))
  23. //! @}
复制代码


  1. //! \brief none standard memory types
  2. #if __IS_COMPILER_IAR__
  3. #   define FLASH                const
  4. #   define EEPROM               const
  5. #   define NO_INIT              __no_init
  6. #   define ROOT                 __root
  7. #   define INLINE               inline
  8. #   define ALWAYS_IN_LINE       __attribute__((always_inline))
  9. #   define WEAK                 __weak
  10. #   define RAMFUNC              __ramfunc
  11. #   define __asm__              __asm
  12. #   define __ALIGN(__N)         _Pragma(__STR(data_alignment=__N))
  13. #   define __AT_ADDR(__ADDR)    @ __ADDR
  14. #   define __SECTION(__SEC)     _Pragma(__STR(location=__SEC))

  15. #   define PACKED               __packed
  16. #   define UNALIGNED            __packed
  17. #   define TRANSPARENT_UNION    __attribute__((transparent_union))

  18. #elif __IS_COMPILER_GCC__
  19. #   define FLASH                const
  20. #   define EEPROM               const
  21. #   define NO_INIT              __attribute__(( section( ".bss.noinit"))
  22. #   define ROOT                 __attribute__((used))   
  23. #   define INLINE              inline
  24. #   define ALWAYS_IN_LINE       __attribute__((always_inline))
  25. #   define WEAK                 __attribute__((weak))
  26. #   define RAMFUNC              __attribute__((section (".textrw")))
  27. #   define __asm__              __asm
  28. #   define __ALIGN(__N)         __attribute__((aligned (__N)))
  29. #   define __AT_ADDR(__ADDR)    __attribute__((at(__ADDR)))
  30. #   define __SECTION(__SEC)     __attribute__((section (__SEC)))

  31. #   define PACKED               __attribute__((packed))
  32. #   define UNALIGNED            __attribute__((packed))
  33. #   define TRANSPARENT_UNION    __attribute__((transparent_union))

  34. #elif __IS_COMPILER_ARM_COMPILER_5__
  35. #   define FLASH                const
  36. #   define EEPROM               const
  37. #   define NO_INIT              __attribute__( ( section( ".bss.noinit"),zero_init) )
  38. #   define ROOT                 __attribute__((used))   
  39. #   define INLINE              __inline
  40. #   define ALWAYS_IN_LINE       __attribute__((always_inline))
  41. #   define WEAK                 __attribute__((weak))
  42. #   define RAMFUNC              __attribute__((section (".textrw")))
  43. #   define __asm__              __asm
  44. #   define __ALIGN(__N)         __attribute__((aligned (__N)))
  45. #   define __AT_ADDR(__ADDR)    __attribute__((at(__ADDR)))
  46. #   define __SECTION(__SEC)     __attribute__((section (__SEC)))


  47. #   define PACKED               __packed
  48. #   define UNALIGNED            __packed
  49. #   define TRANSPARENT_UNION    __attribute__((transparent_union))

  50. #elif __IS_COMPILER_ARM_COMPILER_6__
  51. #   define FLASH                const
  52. #   define EEPROM               const
  53. #   define NO_INIT              __attribute__( ( section( ".bss.noinit")) )
  54. #   define ROOT                 __attribute__((used))   
  55. #   define INLINE              __inline
  56. #   define ALWAYS_IN_LINE       __attribute__((always_inline))
  57. #   define WEAK                 __attribute__((weak))
  58. #   define RAMFUNC              __attribute__((section (".textrw")))
  59. #   define __asm__              __asm
  60. #   define __ALIGN(__N)         __attribute__((aligned (__N)))
  61. #   define __AT_ADDR(__ADDR)    __attribute__((section (".ARM.__at_" #__ADDR)))
  62. #   define __SECTION(__SEC)     __attribute__((section (__SEC)))

  63. #   define PACKED               __attribute__((packed))
  64. #   define UNALIGNED            __unaligned
  65. #   define TRANSPARENT_UNION    __attribute__((transparent_union))

  66. #endif


  67. #define AT_ADDR(__ADDR)     __AT_ADDR(__ADDR)
  68. #define ALIGN(__N)          __ALIGN(__N)
  69. #define SECTION(__SEC)      __SECTION(__SEC)
复制代码

出0入0汤圆

 楼主| 发表于 2017-11-6 11:54:35 来自手机 | 显示全部楼层
Gorgon_Meducer 发表于 2017-11-5 19:02
横跨四编译器的常见编译器扩展:

很不错,学习一下,谢谢!

出0入0汤圆

发表于 2017-11-6 12:03:28 来自手机 | 显示全部楼层
Cmsis_compiler.h 这个文件也有好多定义可以参考。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-25 13:39

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表