TrueSTUDIO中在flash指定位置保存常量

TrueSTUDIO中在flash指定位置保存常量

在TrueSTUDIO开发软件中如何实现在flash指定位置保存常量,使用官方文档“user_guide.pdf”修改多次不能实现。
在这里插入图片描述
通过阅读“ld.pdf”以及网上该文档的翻译版本,历时2天,实现方法总结如下。
步骤1
STM32L071RB_FLASH.ld

/* Specify the memory areas */
MEMORY
{
RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 20K
FLASH0 (rx)      : ORIGIN = 0x08008000, LENGTH = 512
FLASH (rx)      : ORIGIN = 0x08008200, LENGTH = 96K
}

/* Define output sections */
SECTIONS
{
  /* The startup code goes first into FLASH */
  .isr_vector :
  {
    . = ALIGN(4);
    KEEP(*(.isr_vector)) /* Startup code */
    . = ALIGN(4);
  } >FLASH0
  
  .myvars :			/* const var 2019.9.27 */
  {
	*(.MYVARS) 
  } >FLASH

  /* The program code and other data goes into FLASH */
  .text :
  { 
    . = ALIGN(4);
    *(.text)           /* .text sections (code) */
    *(.text*)          /* .text* sections (code) */
    *(.glue_7)         /* glue arm to thumb code */
    *(.glue_7t)        /* glue thumb to arm code */
    *(.eh_frame)

    KEEP (*(.init))
    KEEP (*(.fini))

    . = ALIGN(4);
    _etext = .;        /* define a global symbols at end of code */
  } >FLASH

...
}

步骤2
main.c

__attribute__((section(".MYVARS"))) const uint8_t MyVars[] ={"IDENTIFY"};

注意,程序中需确保使用MyVars变量,而不会被编译器优化掉!

查看
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值