Tuesday, April 24th 2018, 6:37pm UTC+2

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

TrungNguyen

Beginner

Date of registration: Dec 15th 2017

Posts: 2

1

Friday, December 15th 2017, 9:57am

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

SEGGER - Nino

Super Moderator

Date of registration: Jan 2nd 2017

Posts: 954

2

Monday, December 18th 2017, 10:40am

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/C++ Source code

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


To place a constant symbol in Flash use:

C/C++ Source code

1
2
3
4
5
  <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:

C/C++ Source code

1
2
3
4
5
6
7
8
9
10
  <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. */)

C/C++ Source code

1
2
3
4
  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.

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

Keep in mind, this is not a support forum. Its main purposes 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 contact us per e-mail.
The following contact form can be used for this: https://www.segger.com/about-us/contact-us/


TrungNguyen

Beginner

Date of registration: Dec 15th 2017

Posts: 2

3

Tuesday, December 19th 2017, 4:16am

Hi,

Thanks for the reply, this seems to solve the problem perfectly.

Cheers

SEGGER - Nino

Super Moderator

Date of registration: Jan 2nd 2017

Posts: 954

4

Tuesday, December 19th 2017, 9:13am

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: Forum Rules

Keep in mind, this is not a support forum. Its main purposes 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 contact us per e-mail.
The following contact form can be used for this: https://www.segger.com/about-us/contact-us/