[STM32F1] 将常量数据放在闪存末尾的独立区域

[复制链接]
217|2
SocialButterfly 发表于 2025-10-23 22:35 | 显示全部楼层 |阅读模式
code, TE, ig, DA, or, OD
用STM32的CubiIDE,想将常量数据放在闪存末尾的独立区域。但没有成功。该值存储在向量表之后的某个位置,并且在0x8003000处也有存储。因此,在链接器文件中,添加了如下。代码中 const uint32_t data attribute ((section(".udata"))) = 0x1234;如何让变量仅存储在0x8003000?


MEMORY
{
  RAM    (xrw)            : ORIGIN = 0x20000000                                        , LENGTH = 4K
  ROM    (rx)            : ORIGIN = 0x8000000                                        , LENGTH = 12K
  DAT         (r)                : ORIGIN = 0x8000000+12K                                , LENGTH = 4K
}

/* Sections */
SECTIONS
{
  /* The startup code into "ROM" Rom type memory */
  .isr_vector :
  {
    . = ALIGN(4);
    KEEP(*(.isr_vector)) /* Startup code */
    . = ALIGN(4);
  } >ROM

  /* The program code and other data into "ROM" Rom type memory */
  .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 */
  } >ROM

        .udata :
        {
                . = ALIGN(4);
                _udata = .;
                *(.udata)
                *(.udata*)
                . = ALIGN(4);
                KEEP (*(.udata))
        } >DAT
}


classroom 发表于 2025-10-24 10:07 | 显示全部楼层
修改链接器脚本,在C代码中声明变量
cr315 发表于 2025-10-24 10:07 | 显示全部楼层
检查内存布局
您需要登录后才可以回帖 登录 | 注册

本版积分规则

62

主题

62

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部