STM32F4 linker script for use battery RAM

Sysprogs forums Forums VisualGDB STM32F4 linker script for use battery RAM

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #11232
    kucza
    Participant

    I am trying to make a linker section for battery RAM. I have modyfied oryginal script added:

    MEMORY
    {
    FLASH (RX) : ORIGIN = 0x08000000, LENGTH = 1M
    SRAM (RWX) : ORIGIN = 0x20000000, LENGTH = 128K
    CCMRAM (RWX) : ORIGIN = 0x10000000, LENGTH = 64K
    BKPRAM (RWX) : ORIGIN = 0x40024000, LENGTH = 4K
    }

    and in sections part:

    .backup (NOLOAD) :
    {
    . = ALIGN(4);
    *(.backup);
    *(.backup*);
    . = ALIGN(4);
    } > BKPRAM

    In main.cpp it looks like that:

    struct config_t
    {
    uint8_t a;
    uint16_t b;
    uint32_t c;
    };

    __attribute__((section(“.backup”))) config_t config;

    and init for battery ram looks like that:

    void initBackupRam(void)
    {
    __HAL_RCC_PWR_CLK_ENABLE();
    HAL_PWR_EnableBkUpAccess();
    __BKPSRAM_CLK_ENABLE();
    }

    It does not work, probably I missed something in linker script. I need some adivice what is wrong.

    
    /* Generated by LinkerScriptGenerator [http://visualgdb.com/tools/LinkerScriptGenerator]
    * Target: STM32F407VE
    * The file is provided under the BSD license.
    */
    
    ENTRY(Reset_Handler)
    
    MEMORY
    {
    FLASH (RX) : ORIGIN = 0x08000000, LENGTH = 1M
    SRAM (RWX) : ORIGIN = 0x20000000, LENGTH = 128K
    CCMRAM (RWX) : ORIGIN = 0x10000000, LENGTH = 64K
    BKPRAM (RWX) : ORIGIN = 0x40024000, LENGTH = 4K
    }
    
    _estack = 0x20020000;
    
    SECTIONS
    {
    .isr_vector :
    {
    . = ALIGN(4);
    KEEP(*(.isr_vector))
    . = ALIGN(4);
    } > FLASH
    
    .text :
    {
    . = ALIGN(4);
    _stext = .;
    
    *(.text)
    *(.text*)
    *(.rodata)
    *(.rodata*)
    *(.glue_7)
    *(.glue_7t)
    KEEP(*(.init))
    KEEP(*(.fini))
    . = ALIGN(4);
    _etext = .;
    
    } > FLASH
    
    .ARM.extab :
    {
    . = ALIGN(4);
    *(.ARM.extab)
    *(.gnu.linkonce.armextab.*)
    . = ALIGN(4);
    } > FLASH
    
    .exidx :
    {
    . = ALIGN(4);
    PROVIDE(__exidx_start = .);
    *(.ARM.exidx*)
    . = ALIGN(4);
    PROVIDE(__exidx_end = .);
    } > FLASH
    
    .ARM.attributes :
    {
    *(.ARM.attributes)
    } > FLASH
    
    .preinit_array :
    {
    PROVIDE(__preinit_array_start = .);
    KEEP(*(.preinit_array*))
    PROVIDE(__preinit_array_end = .);
    } > FLASH
    
    .init_array :
    {
    PROVIDE(__init_array_start = .);
    KEEP(*(SORT(.init_array.*)))
    KEEP(*(.init_array*))
    PROVIDE(__init_array_end = .);
    } > FLASH
    
    .fini_array :
    {
    PROVIDE(__fini_array_start = .);
    KEEP(*(.fini_array*))
    KEEP(*(SORT(.fini_array.*)))
    PROVIDE(__fini_array_end = .);
    } > FLASH
    
    . = ALIGN(4);
    _sidata = .;
    
    .data : AT(_sidata)
    {
    . = ALIGN(4);
    _sdata = .;
    
    PROVIDE(__data_start__ = _sdata);
    *(.data)
    *(.data*)
    . = ALIGN(4);
    _edata = .;
    
    PROVIDE(__data_end__ = _edata);
    } > SRAM
    
    .bss :
    {
    . = ALIGN(4);
    _sbss = .;
    
    PROVIDE(__bss_start__ = _sbss);
    *(.bss)
    *(.bss*)
    *(COMMON)
    . = ALIGN(4);
    _ebss = .;
    
    PROVIDE(__bss_end__ = _ebss);
    } > SRAM
    
    .backup (NOLOAD) :
    {
    . = ALIGN(4);
    *(.backup);
    *(.backup*);
    . = ALIGN(4);
    } > BKPRAM
    
    PROVIDE(end = .);
    
    .heap (NOLOAD) :
    {
    . = ALIGN(4);
    PROVIDE(__heap_start__ = .);
    KEEP(*(.heap))
    . = ALIGN(4);
    PROVIDE(__heap_end__ = .);
    } > SRAM
    
    .reserved_for_stack (NOLOAD) :
    {
    . = ALIGN(4);
    PROVIDE(__reserved_for_stack_start__ = .);
    KEEP(*(.reserved_for_stack))
    . = ALIGN(4);
    PROVIDE(__reserved_for_stack_end__ = .);
    } > SRAM
    
    }
    
    • This topic was modified 6 years, 11 months ago by kucza.
    #11237
    support
    Keymaster

    Hi,

    Please try referencing the “config” variable from your code so that the linker does not discard it as unused. Alternatively you can try using the KEEP() statement in the linker script file and attribute__((used)) in your code.

    If it does not help, try enabling the map file generation via Linker Settings and check the map file to see where exactly the linker placed your variable.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.