LPC: How to place data/function/file in specified memory under MCUXpresso IDE

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC: How to place data/function/file in specified memory under MCUXpresso IDE

LPC: How to place data/function/file in specified memory under MCUXpresso IDE

Contents

  1.     The default storage address space of code and data. 1
  2.     Customize Flash and RAM partitions. 2
  3.     Place the data in the specified address space. 3
  4.     Place the function in the specified address space. 4
  5.     Place the specified file in the specified address space. 5

 

During MCU development, placing data, function, and file in the specified memory address according to actual requirements is important for the memory usage. We Combine customer’s frequent ask questions, explain how to operate these features step by step.

1.     The default storage address space of code and data

Take the hello world demo in LPC54628 as an example, and the development environment: MCUXpresso IDE.

After building, the memory allocation is as shown in the following console window:

ZhangJennie_0-1627878064170.png

 

The relationship between .text, .data, .bss, .dec and Flash and RAM is as follows:

ZhangJennie_1-1627878082349.png

 

2.     Customize Flash and RAM partitions

In order to place the data, function or file in the specified address space, we split some new partitions.

Open the project property setting interface, and split MY_FLASH and MY_RAM address spaces in the MCU settings option for testing. The size of these two address spaces can be customized, as follows:

ZhangJennie_2-1627878137349.png

 

After configuring Flash and RAM, click ‘Apply and Close’ button and you will see Flash2 and RAM2 in the project column, as follows:

ZhangJennie_3-1627878156391.png

3.     Place the data in the specified address space

1)The default storage address space of variables and constants

View the default address space of variables and arrays, as follows:

Initialized variable:uint16_t value1 = 1;

Uninitialized arraychar data_buffer1[1024];

Constant array  const char data_buffer2[1024] = "hello nxp";

View storage address space of arrays using the Image Info window in MCUXpresso IDE, as follows:

ZhangJennie_4-1627878215030.png

 

Readable and writable variables and arrays are stored in RAM (0x20000000-0x20014000) named "SRAM_UPPER" by default, and const arrays are stored in Flash (0x0-0x40000) named "PROGRAM_FLASH".

 2) Place the specified variables and constants in the specified address space

To place the array in custom Flash and RAM, you need to call the C language:

__attribute__ ((section(#type #bank)))

For example, place the data in .text of Flash2:

__attribute__ ((section("text_Flash2" ".$Flash2"))) + data declaration

The NXP official has encapsulated this and defined it in cr_section_macros.h. __DATA(RAM2) means that the readable and writable array is placed into the .data section of RAM2, and __RODATA(Flash2) means that the read-only array is placed into the .rodata section of Flash2.

__DATA(RAM2) char data_buffer3[1024];

__RODATA(Flash2) const char data_buffer4[1024] = "hello nxp";

Note that you must #include "cr_section_macros.h".

ZhangJennie_5-1627878262754.png

 

Global variables and arrays are placed in custom RAM2 (0x20014000-0x20028000) named "MY_RAM", and const arrays are placed in custom Flash2 (0x40000-0x80000) named "MY_FLASH".

4.      Place the function in the specified address space

1)The default storage address space of functions

The code is placed in the Flash (0x0-0x40000) named "PROGRAM_FLASH" by default, and the following function is defined:

int hello1(void)

{

        return 1;

}

2)Place the specified function in the specified address space

To place the function in custom Flash, you need to call the C language:

__attribute__ ((section(#type #bank)))

For example, place the function in .text of Flash2:

__attribute__ ((section("text_Flash2" ".$Flash2")))+function declaration

The NXP official has also encapsulated this and defined it in cr_section_macros.h. The method to change the address space of the function is as follows, and place the function in a custom Flash named "MY_FLASH" (0x40000-0x80000).

__TEXT(Flash2) int hello2(void)

{

               return 2;

}

ZhangJennie_6-1627878362300.png

 

5.      Place the specified file in the specified address space

When there are many functions that need to be placed in the specified Flash, it is a little clumsy to use the __TEXT(Flash) method to set each function. If you need to place all the functions in the c file in the specified Flash, you only need to place the compiled .o file in the specified Flash. Split a new partition named "MY_FLASH_O" , create a new hello.c under the source folder, compile and generate hello.o, and configure Linker Script to place hello.o in the partitioned Flash, as follows:

ZhangJennie_7-1627878399425.png

 

Reference:

https://mcuoneclipse.com/2021/05/26/placing-code-in-sections-with-managed-gnu-linker-scripts/

Relocating Code and Data Using the CW GCC Linker File for Kinetis .pdf

 

Attachments
100% helpful (1/1)
Version history
Last update:
‎08-01-2021 09:29 PM
Updated by: