Ruffian Heng embedded: project link file configuration management and automatic generation mechanism under MCU Xpress IDE


Hello, I’m ruffian Heng, a serious technical ruffian. What ruffian Heng introduced to you today isConfiguration management and automatic generation mechanism of project link file under MCU Xpress IDE

Ruffian Heng wrote a special topic in early 2018Embedded development document series, this paper systematically introduces the main file types to be understood in the development of arm Cortex-M kernel microcontroller: source file, link file, engineering file, redirectable file, mapping file, executable file, disassembly file and image file.

Among the above eight kinds of files, you should be most familiar with source files, engineering files and image files, while many people should not have studied the other file types in depth, but ruffian Heng has always believed that only by deeply understanding the linked files can you really enter the ranks of embedded development veterans.

We know that the syntax of linked files under different ides is different, and the underlying compiler of NXP MCU Xpress IDE is arm GCC, so its linked files are. LD files under standard GCC. If you are very proficient in. LD file syntax, of course, you can write link files from scratch. If you are not familiar with them, don’t be nervous. The MCU Xpress ide has cleared the way for you for a long time. Under this IDE, you can support link configuration in the graphical interface, and then automatically generate the corresponding link files. Today, ruffian Heng will talk about this feature:

1、 Prepare development environment

First, prepare the environment, including the necessary software. The environment of ruffian Heng is as follows:

2、 Link file configuration under MCU Xpress IDE

Now let’s get to the point. Let’s start withSDK project import and workspace management mechanism under MCU Xpress IDEOne step import from the SDK package to generate a project (choose the simplest hello_world). After the project is successfully imported, it will be displayed in \ mcuxpressoide_ 11.4.0_ 6224\workspace\evkmimxrt1170_ hello_ world_ demo_ CM7, see the. Project project file, and open the project in the mcuxpresso ide.

2.1 memory space definition

Right click on the project name and selectPropertiesEnter the option configuration interface, whereMCU settingsWhat is defined in this column is the actual storage space of MCU, which is the space allocation basis of linked files. We will link all segments of the program in these areas later.

Storage space attributes (types) are divided into two categories: Flash (storing ro segment) and RAM (storing RW segment). There can be many spaces defined for each attribute, but only the space named flash and ram in alias is selected by default for linking program segments (the specified space can be adjusted to the position of the front flash and ram by moving up and down buttons).

2.2 default segment assignment

It was opened in the previous sectionPropertiesOption configuration interface, whereSettings / Managed Linker ScriptThe page is the link setting of the specific program segment in the link file, which is at the top of this pageManage linker scriptTo keep it checked, if it is checked, it means to use the automatic generation function of linked files in the IDE.

In a specific application project, if the source file only contains standard C and assembly code, the program segments will be classified into three categories by default: RO segment (function code, constant, initial value of global variable, etc.), RW segment (global variable, function code redirected to ram, etc.), heap / stack. The IDE provides the space designation of these three types of program segments:

1. Link application to ram check box:

2.3 custom segment assignment

In addition to the default program segment name of the linker in the previous section, we can also customize some user segment names to facilitate some special code processing. Here you need to use__attribute__((section(“UserSectionName”)))Linker syntax to modify the specified function / variable, so that the function / variable will be placed in the usersectionname section, and then we will at the end of the link setting box in the figure in the previous sectionExtra linker script input sectionsBox to specify the link space separately for the custom usersectionname segment.

For example, engineering clock_ The following function updatesemclock() in the config. C file is in the default ro. Text section. The RO sections are linked in flash, but we want to redirect this function to ITCM for execution, so we can use it__ attribute__ ((section (“codequickaccess”)) linker syntax to modify this function, and then put the codequickaccess segment into SRAM in the extra linker script input sections box_ ITC_ CM7 space.

#define AT_QUICKACCESS_SECTION_CODE(func) __attribute__((section("CodeQuickAccess"), __noinline__)) func
#define AT_QUICKACCESS_SECTION_DATA(func) __attribute__((section("DataQuickAccess"))) func

AT_QUICKACCESS_SECTION_CODE(void UpdateSemcClock(void));
void UpdateSemcClock(void)
    SEMC->IPCMD = 0xA55A000D;
    while ((SEMC->INTR & 0x3) == 0);
    SEMC->INTR                                = 0x3;
    SEMC->DCCR                                = 0x0B;
    CCM->CLOCK_ROOT[kCLOCK_Root_Semc].CONTROL = 0x602;

2.4 automatically generated linked files

After the link setting is completed, it will be displayed in the project directory \ mcuxpressoide_ 11.4.0_ 6224\workspace\evkmimxrt1170_ hello_ world_ demo_ CM7 \ debug automatically generates the final link file (assuming debug build is used). There are three files in total, including evkmimxrt1170_ hello_ world_ demo_ cm7_ Debug.ld is the main link file. If you are interested, you can open this link file and learn it (if you don’t understand the syntax, you can combine it with this article )。

2.5 check the map file for confirmation

According to the link settings in sections 2.1 and 2.2, we compile the link evkmimxrt1170_ hello_ world_ demo_ CM7 project can get the following link results, which are in line with expectations in terms of space occupation.

Now we can open the generated evkmimxrt1170_ hello_ world_ demo_ file specifically analyzes the final link. Ruffian Heng excerpts the most core parts as follows:

Memory Configuration

In a brief summary, the RO segment is generally linked from the front of flash, the. Text segment is at the front, then the ramfunc function entity, and finally. Data_ Init segment (initial value of global variable). RW segment is also linked from the front of ram, with. Data segment in front and. BSS in back, followed by heap and stack (the specific location of heap / stack can be set, including start, end and post data).

3、 Link experiment under MCU Xpress IDE

According to the above knowledge, let’s do some link setting experiments. Before the experiment, we adjust the memory definition and move the SDRAM related space to the back. The default ram is SRAM_ DTC_ CM7 space, so it seems to be used to it.

3.1 default XIP link

The link results after adjusting the memory space order are as follows:

3.2 non XIP link

Now we try to enableLink application to RAMOption, and the rest remain unchanged. At this time, you can see that the RO segment of 28396 bytes has also reached the SRAM_ DTC_ CM7 space, board_ There is no occupation of flash space at all:

3.3 XIP link, resize the stack and place it in ocram1

We try to adjust the stack size to 1KB and put it into SRAM_ OC1, the rest remain unchanged, and SRAM can be seen at this time_ DTC_ CM7 consumes 4KB less space than in Section 3.1, but SRAM_ OC1 consumes 1KB more space:

3.4 XIP link, adjust RW segment to ocram2

We try to adjust RW segment to SRAM_ Oc2, the rest remain unchanged, and SRAM can be seen at this time_ DTC_ CM7 space consumption is 264 bytes less than that in Section 3.1, but SRAM_ Oc2 consumes 264 bytes more space:

So far, the project link file configuration management and automatic generation mechanism under MCU Xpress ide have been introduced. Where are the applause~~~

Welcome to subscribe

The article will be published to me at the same timeBlog Park home pageCSDN home pageZhihu home pageWeChat official accountOn the platform.

Wechat search“Ruffian scale“Or scan the QR code below to see it for the first time on the mobile phone.