This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

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 our 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 ?

Parents
  • Hi,

    The only solution to place a symbol at a given address, is to place it into a separate section.

    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:

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

    To place a constant symbol in Flash use:

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

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

      <MemorySegment name="$(FLASH_NAME:FLASH)">
    [...]
        <ProgramSection alignment="4" load="Yes" runin=".MyVar_run" name=".MyVar" />
    [...]
      </MemorySegment>
      <MemorySegment name="$(RAM_NAME:RAM);SRAM">
    [...]
        <ProgramSection alignment="4" load="No" name=".MyVar_run" start="0x20010000" />
    [...]
      </MemorySegment>
    

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

      ldr r0, =__MyVar_load_start__
      ldr r1, =__MyVar_start__
      ldr r2, =__MyVar_end__
      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.

    Regards, Johannes

  • Hi Johanes, Thanks for the reply. This works like a charm. This seems confused at first but actually this method makes it more flexible to manage data to be placed in a specific address. Cheers

Reply Children
No Data
Related