SocialButterfly 发表于 2025-10-23 22:35

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

用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

检查内存布局
页: [1]
查看完整版本: 将常量数据放在闪存末尾的独立区域