[SOLVED] MemorySegment for only the Stack

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

  • [SOLVED] MemorySegment for only the Stack

    Hello,

    i want to split a RAM into two different MemorySegment. On segment for .data_run and .bss and an extra segment for the stack.

    The position of the RAM is: 0x2000 0000 and the size is 0x0004 0000
    Used Linker: GCC

    the following initual situation works fine:
    (i know that i can place the stack to the end with place_from_segment_end)

    XML Source Code

    1. <MemorySegment name="RAM" start="0x2000 0000" size="0x0004 0000">
    2. <ProgramSection alignment="0x4" load="No" name=".data_run"/>
    3. <ProgramSection alignment="0x4" load="No" name=".bss"/>
    4. <ProgramSection alignment="0x8" load="No" name=".stack" start="0x2000 0000 + 0x0004 0000 - __STACKSIZE__" size="__STACKSIZE__"/>
    5. </MemorySegment>



    The reason why i want to split the regions is i have two different applications, bootloader and firmware. In the bootloader project i want to specify the RAM to reservate RAM section for .data_run and .bss datas.

    Bootloader RAM definition:

    XML Source Code

    1. <MemorySegment name="RAM" start="0x2000 0000" size="0x0000 8000">
    2. <ProgramSection alignment="0x4" load="No" name=".data_run"/>
    3. <ProgramSection alignment="0x4" load="No" name=".bss"/>
    4. </MemorySegment>
    5. <MemorySegment name="STACK" start="0x2000 0000" size="0x0004 0000">
    6. <ProgramSection alignment="0x8" load="No" name=".stack" start="0x2000 0000 + 0x0004 0000 - __STACKSIZE__" size="__STACKSIZE__"/>
    7. </MemorySegment>

    With this solution i would get an linker error if .data_run and .bss are bigger than 0x8000 because of set size of the RAM memory segment. And with the STACK MemorySegment i can move the Stack to the end of the phyiscal RAM memory!


    Application RAM definition for example:

    XML Source Code

    1. <MemorySegment name="RAM" start="0x2000 8000" size="0x0003 8000">
    2. <ProgramSection alignment="0x4" load="No" name=".data_run"/>
    3. <ProgramSection alignment="0x4" load="No" name=".bss"/>
    4. </MemorySegment>
    5. <MemorySegment name="STACK" start="0x2000 0000" size="0x0004 0000">
    6. <ProgramSection alignment="0x8" load="No" name=".stack" start="0x2000 0000 + 0x0004 0000 - __STACKSIZE__" size="__STACKSIZE__"/>
    7. </MemorySegment>
    with this definition the first 0x8000 bytes of ram are reservated for the bootloader, because the application definition starts with offset of 0x8000.
    And the Stackpointers of each bootloader and application are on the end of the RAM.


    When i try to link the bootloader project with the two MemorySegments RAM and STACK i get the following linker error: (see attachment)
    I have also tried to add the "keep" propertie to memorySegment.

    when i look into the linker skript i can see that no region for stack will be created. (see linker skript attached).

    for me it looks like that stack only can be in the memorysegment with the name "RAM".

    Thank you for your support
    Best Regards
    Markus
    Images
    • LinkerError.png

      27.13 kB, 1,838×195, viewed 56 times
    Files
    • Bootloader.txt

      (8.22 kB, downloaded 59 times, last: )
  • Hello Markus,

    Your section placement file looks fine,
    but you will need to also add the segments to the memory map file as follows:

    XML Source Code

    1. <MemorySegment name="RAM" start="0x2000 8000" size="0x0003 8000" access="Read/Write" />
    2. <MemorySegment name="STACK" start="0x2000 0000" size="0x0004 0000" access="Read/Write" />



    Best regards
    Johannes
  • Hello Johannes,

    thanks for the information, now it works.
    I dont use an mamory map file i use the Memory Segments Option in the Build options.
    The option i have changed to this: "FLASH RX 0x0 0x100000;RAM RWX 0x20000000 0x8000; STACK RWX 0x20000000 0x100000" and now it works, thanks!

    This is now my flash_placement.xml

    XML Source Code

    1. <MemorySegment name="RAM" start="$(RAM_PH_START)" size="$(RAM_PH_SIZE)">
    2. <ProgramSection alignment="0x4" load="No" name=".data_run"/>
    3. <ProgramSection alignment="0x4" load="No" name=".bss"/>
    4. </MemorySegment>
    5. <MemorySegment name="STACK" start="$(STACK_PH_START)" size="$(STACK_PH_SIZE)">
    6. <ProgramSection alignment="0x8" load="No" name=".stack" place_from_segment_end="Yes" size="__STACKSIZE__"/>
    7. </MemorySegment>

    One more question is it possible to see the STACK section also in the Memory Usage Window? I only can see the FLASH and RAM Segments (see atachment)?

    Best Regards
    Markus
    Images
    • MemoryUsage.png

      17.25 kB, 757×1,128, viewed 53 times
  • Hi,

    Great to hear that you are up and running again.

    maxl_1989 wrote:

    One more question is it possible to see the STACK section also in the Memory Usage Window? I only can see the FLASH and RAM Segments (see atachment)?

    Currently not. But it is already on our todo list.

    Best regards,
    Nino
    Please read the forum rules before posting: Forum Rules

    Keep in mind, this is not a support forum. Its main purpose is user to user interaction.
    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.