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: code、rwdata、rodata、zidata
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
__thumbAvailable data type attributes:
__big_endian
__little_endian
__packedobject_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 =
本文详细介绍了如何在ARMCortex-M处理器的只读存储器(ROM)中定义特定区域空间、常量段、可读写和只读数据块,并使用`__attribute__((used,section()))`和`#pragmaarmsection`等编译器指令进行代码段排序和存储区域分配。

1430

被折叠的 条评论
为什么被折叠?



