-
1.标准方法,定义mem,在section中放置
代码中定义
const uint8 Version[4] attribute((used, section(".version_data"))) = {1,2,3,4};
链接脚本定义
MEMORY:
USR_VER (rx) : ORIGIN = 0x080100C0, LENGTH = 0x00010
SECTIONS:
user_config : ALIGN(4)
{
KEEP(*(.version_data)) /offset 0xCC/
} > USR_VER -
2.未使能-fdata-sections选项情况下
定义变量 const uint8 Version[4] attribute((used, section(".version_data"))) = {1,2,3,4};
链接脚本的SECTIONS中的子段:
.text :
{
(.text) / .text sections (code) /
. = ALIGN(4);
KEEP((.version_data))
或者
xxx_file.o(.rodata)/假定Version定义在xxx_file.c中/
} >FLASH -
3.使能-fdata_sections选项
定义变量 const uint8 Version[4] attribute((used, section(".version_data"))) = {1,2,3,4};
链接脚本的SECTIONS中的子段:
.text :
{
(.text) / .text sections (code) /
. = ALIGN(4);
KEEP((.rodata.Version))
} >FLASH
因为该选项会把所有变量生成独立的段,-ffunction-sections同理
gcc链接放置变量到指定位置
于 2024-06-20 17:47:18 首次发布