[SOLVED] Placing data at a specific memory address with Segger Embedded Studio

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] Placing data at a specific memory address with Segger Embedded Studio

    Hi all,

    I'm having problem porting some project from Keil to SES since my
    project use absolute memory location to put some variable that will be
    share between main application and the bootloader and it seems i can't
    do it in SES, at least in an easy way.


    With Keil, i can use __attribute__((at(0x20002000))), for example, to
    place a variable at memory location 0x20002000 but since the "at"
    attribute is a Keil-specific feature, i can't use it with SES. In SES, i
    can use attribute__((section("name"))) to put them in a section defined
    in the section placement xml file but there is no guarantee that the
    variable will be place at exactly the memory address that i want it to
    be unless i modified the linker script and define separate named
    section and address for each variable.


    Is there any easier method to place data (eg: a variable) in a specific memory address in RAM in SES ?
  • Hi,

    Thank you for your inquiry.
    Placing directly at a address is not possible due to GCC restrictions.
    An alternative is unfortunately also not possible.
    As you wrote you need to create a section for each variable you want to be placed at a "fixed" address.

    EDIT: For clarification, I meant that you need to edit the section placement file not the linker script.

    If you create one section per "fixed address" symbol, it is guaranteed that the symbol is at the start of that section.
    You can supply a start address (and optionally even the size) to a section.

    To place an unitialized symbol in RAM use:

    C Source Code

    1. <MemorySegment name="$(RAM_NAME:RAM);SRAM">
    2. [...]
    3. <ProgramSection alignment="4" load="No" name=".MyVar" start="0x20010000" />
    4. [...]
    5. </MemorySegment>


    To place a constant symbol in Flash use:

    C Source Code

    1. <MemorySegment name="$(FLASH_NAME:FLASH)">
    2. [...]
    3. <ProgramSection alignment="4" load="Yes" name=".MyVar" start="0x00010000" />
    4. [...]
    5. </MemorySegment>


    To place a symbol in RAM that should be initialized by startup, use:

    C Source Code

    1. <MemorySegment name="$(FLASH_NAME:FLASH)">
    2. [...]
    3. <ProgramSection alignment="4" load="Yes" runin=".MyVar_run" name=".MyVar" />
    4. [...]
    5. </MemorySegment>
    6. <MemorySegment name="$(RAM_NAME:RAM);SRAM">
    7. [...]
    8. <ProgramSection alignment="4" load="No" name=".MyVar_run" start="0x20010000" />
    9. [...]
    10. </MemorySegment>

    and copy from .MyVar to .MyVar_run in crt0 (thumb_crt0.s, before /* zero the bss. */)

    C Source Code

    1. ldr r0, =__MyVar_load_start__
    2. ldr r1, =__MyVar_start__
    3. ldr r2, =__MyVar_end__
    4. bl memory_copy


    You can then use __attribute__((section(".MyVar"))) to place a symbol into that section at the address given by the start attribute.

    Best regards,
    Nino
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hi,

    Great to hear that you are up and running again.
    We will consider this case as closed then.

    Best regards,
    Nino
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.