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.
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.
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] ;
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 }
.myBuffer (NOLOAD): { *(.myBuffer) } > MyBufferRAM
struggling to do this in RT1024_EVK, the link inside the post for for how to do own linker script is no longer available, a whole example could help please!
Regards!
Ping
Hello, This worked fine for me. But how can define values to the buffer?
Hi, i would add , to the initial post to also , add this specific preprocessor directive as mentionned in this post : https://community.nxp.com/t5/i-MX-RT/How-to-use-on-board-external-SDRAM-for-global-variables/m-p/123...
"to enable the SDRAM, you need to add the XIP_BOOT_HEADER_DCD_ENABLE=1 in the C/C++ Build > Settings > Preprocessor, then the ROM code will fetch the DCD to initialize the SDRAM during the boot-up process. "
In my case the use of both :
__DATA(RAM4) struct array_2 arr_2_struct[ARRAY_2_SIZE];
// create an initialised 1k buffer in RAM4= BOARD_SDRAM
The name of trhe ram block is accessible in project -> settings->C/C++ Build-> MCU settings-> memory details( MIMXRT1062xxxxxA)
and the use of the preprocessor directive as mentionned at the init of this post allowed the code to run without the hard fault error
Those link are also sharing explanation about he same subject:
https://community.nxp.com/t5/LPCXpresso-IDE-FAQs/Placing-data-into-different-RAM-blocks/m-p/473455
Bye