AnsweredAssumed Answered

Placing data at an address

Question asked by LPCware Support on Mar 31, 2016

Introduction

 

Sometimes it is useful to be able to place a specific variable at a specific location in memory, rather than relying upon the automatic placement carried out by default by the linker. For example, you might need to place a buffer variable accessed by a peripheral into your system to a know location in RAM.

 

Placement using the memory configuration editor

 

By default the LPCXpresso IDE provides a standard memory layout for known MCUs. This defines the locations of the available banks of RAM, and any internal flash. If the variable you want to place needs to be located as the only variable in a particular bank of the defined RAM, then you can simply use the attribute macros provided by the "cr_section_macros.h" header file, as described in the FAQ:

 

 

However, if you need a finer level of granuality, then it is then possible to edit the predefined memory layout for your particular project using the "Memory Configuration Editor" (sometimes referred to as simply the "Memory Editor") - often to add details of external flash devices. For more details, please see the LPCXpresso User Guide.

 

Thus you can use the Memory Configuration Editor to divide up (and rename) the existing banks of RAM. This then allows you to provide a specific named block of RAM into which to place the variable that you need at a specific address, again by using the attribute macros provided by the "cr_section_macros.h" header file.

 

Placement by modifying the linker script file

 

In some situations rather than using the managed linker script mechanism, you may wish you wish to place data at a known address when you are maintaining the linker script by hand. In such circumstances you can use the following technique to place your data:

 

  • Place your data into its own section. e.g.

 

__attribute__ ((section(".myBuffer"))) unsigned char myBuffer[1024] ;

 

  • Modify your project to provide your own linker script, as detailed in the FAQ "Using your own linker scripts".
  • If it doesn't exist, create a Memory region in the linker script for Memory

 

MEMORY 
{
      /* Define each memory region */
      MFlash32 (rx) : ORIGIN = 0x0, LENGTH = 0x8000 /* 32k */
      RamLoc8 (rwx) : ORIGIN = 0x10000000, LENGTH = 0x2000 /* 8k */
      MyBufferRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x2000
}

 

  • Modify the linker script to place your data section to a known address

 

.myBuffer (NOLOAD): 
{ *(.myBuffer)
} > MyBufferRAM

 

 

Outcomes