常量固定地址-S32 Design Studio for ARM

常量固定地址-S32 Design Studio for ARM
Codewarrior 也类似

常量放在固定地址上
以fs32k144 为例

查看手册确定地址

Flash 大小为 5 12 K ,地址 0 x 0 0000 到 0x7 FFFF
用最后4 K 放置配置常量 则:
代码Flash 地址: 0 x 0 0000 到 0x7 EFFF
配置常量地址:0x7 F 000 到 0x7 FFFF

修改配置文件 S32K144_64_flash.ld

原文件:

/* Flash */
m_interrupts (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000400
m_flash_config (RX) : ORIGIN = 0x00000400, LENGTH = 0x00000010
m_text (RX) : ORIGIN = 0x00000410, LENGTH = 0x0007FBF0

修改后:

/* Flash */
m_interrupts (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000400
m_flash_config (RX) : ORIGIN = 0x00000400, LENGTH = 0x00000010
m_text (RX) : ORIGIN = 0x00000410, LENGTH = 0x0007EBF0
m_config (RX) : ORIGIN = 0x0007F000, LENGTH = 0x00001000

添加段:

.const_var :
{
. = ALIGN(4);
KEEP(*(.m_const_config))
} > m_config

定义变量

const int config_alpha[4]__attribute__ ((section(".m_const_config"))) = {1,2,3,4};
const int config_beta[8]__attribute__ ((section(".m_const_config"))) = {1,2,3,4};

查看map文件验证

 *(.m_const_config)
 .m_const_config
                0x0007f000       0x30 ./src/main.o
                0x0007f000                config_alpha
                0x0007f010                config_beta

你可能感兴趣的:(常量固定地址-S32 Design Studio for ARM)