self-define specific section, block, region within IAR linker config file.

本文详细介绍了如何在ARMCortex-M处理器的只读存储器(ROM)中定义特定区域空间、常量段、可读写和只读数据块,并使用`__attribute__((used,section()))`和`#pragmaarmsection`等编译器指令进行代码段排序和存储区域分配。
Initialize
do not initialize
{
    .noinit // 不初始化的段
    .my_custom_section // 自定义段
}
except
{
    .my_custom_section // 这个段会被初始化,即使在 do not initialize 中
};
Define specific region space within ROM

define exported symbol __MY_SEGMENT_start__ = 0x08003800;
define exported symbol __MY_SEGMENT_end__ = 0x08003FFF;
define region MY_SEGMENT_REGIN = mem:[from __MY_SEGMENT_start__ to __MY_SEGMENT_end__];

Define specific block (RO / RW) area under region

define block PROGRAMVALID_BLOCK with alignment = 4, size = 4 { readonly section .programvalid };
define block PROGRAMNAMESTRING with alignment = 4, size = 12 { readonly section .programname };
define block PROGRAMNAMEVERSION with alignment = 4, size = 4 { readonly section .programversion };
define block PROGRAMID_BLOCK with alignment = 4, size = 16 { readonly section .programID };

define `block name` [ with param1, param2... ]
{
extended-selectors
}
[ except
{
section-selectors
} ];
-- Note:
where param can be one of:
size = expr
minimum size = expr
maximum size = expr
expanding size
alignment = expr
fixed order = expr
...
Place designated block in the region area

place in MY_SEGMENT_REGIN { first block PROGRAMVALID_BLOCK, block PROGRAMNAMESTRING, block PROGRAMNAMEVERSION, block PROGRAMID_BLOCK};

OR
(I usually place it like this)
"MY_SEGMENT":place in MY_SEGMENT_REGIN
{
ro section .prod_profile,
block PROGRAMVALID_BLOCK,
block PROGRAMNAMESTRING,
block PROGRAMNAMEVERSION,
block PROGRAMID_BLOCK
};

results kind like:
在这里插入图片描述

  • Note: user could employ this below attribute syntex format to define your specific functions within above section.
    KEIL COMPILER
__attribute__((used, section("section-name"))) void userSpecificFunc()
{
    // contents
}

or

 __attribute__((used, section(".fileSys"))) const FILE_INFO fileTable[] =
{
  {"USER SETTING", FILE_TYPE_EE, 0x00, RD | WR, USER_SETTING_FILE_OFFSET, USER_SETTING_FILE_SIZE},
};

Or
batch definition


#pragma arm section sort_type="section-name" [, sort_type="section-name"*]
  ...  //contents
#pragma arm section     // restore to default section.


eg:
 #pragma arm section code= "SRAM",zidata = "SRAM"
        static OS_STK  helloworld[256];              // code,zidata(like the hellpworld array) will be defined in SRAM section。
 #pragma arm section     
  • Tips:

sort_type: coderwdatarodatazidata

IAR Embedded Workbench

  • Customize Lonely One
__attribute__((used, section("section-name"))) void userSpecificFunc()
{
    // contents
}

or

 __attribute__((used, section(".fileSys"))) const FILE_INFO fileTable[] =
{
  {"USER SETTING", FILE_TYPE_EE, 0x00, RD | WR, USER_SETTING_FILE_OFFSET, USER_SETTING_FILE_SIZE},
};
  • Customize Bach Definitions
#pragma default_variable_attributes=[ attribute...] @ section_name
... // contents

#pragma default_variable_attributes =

where attribute can be:

type_attribute

Available function type attributes (affect how the function should be called)
__arm
__cmse_nonsecure_call
__exception
__fiq
__interwork
__irq,
__svc
__swi__no_scratch
__task
__thumb

Available data type attributes:
__big_endian
__little_endian
__packed

object_attribute
__root
__weak
__no_init
__irq
__naked
__nested
__noreturn,
__ramfunc
__stackless

e.g.

typedef __packed struct {
char a;  // 1 byte
__little_endian int b;   // 4 bytes
} packedStruct;
// Place following variables in section "MYSEC"
#pragma default_variable_attributes = @ "MYSEC"
  packedStruct myStruct
  ...
#pragma default_variable_attributes =

// Place following functions in section "MYSEC"
#pragma default_function_attributes = @ "MYSEC"
 int myfunc(int x)
 {
   return x + 1;
 }
 ...
#pragma default_function_attributes =

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值