Ruffian Heng embedded: several methods of decentralized linking of application RW segments under MCU Xpress IDE

Time:2021-9-17

Hello, I’m ruffian Heng, a serious technical ruffian. What ruffian Heng introduced to you today isSeveral methods of dispersing and linking application RW segments under MCU Xpress IDE

Early MCU chips generally embedded internal flash and ram, and there was only one piece of flash and RAM (i.e. both within the range of continuous mapping addresses). Therefore, it was relatively simple to handle when linking applications. All ro segments of the program were placed in a single flash space and all RW segments of the program were placed in a single RAM space.

With the development of the times, today’s MCU is becoming more and more high-end. For example, the MCU with cortex-m7 core (the most typical representative – NXP I. mxrt Series) generally introduces high-speed TCM ram, and there are also some ordinary on chip ram inside the chip. Of course, the chip can also support external capacity expansion SDRAM, PSRAM, etc, In this case, there are multiple ram areas with discontinuous address space. At this time, how to link the program RW segment to these scattered ram spaces?

Recently, ruffian Heng was supporting an American g customer. The customer chose the mcuxpresso IDE for the project. Under this IDE, the customer did not find the perfect RW segment decentralized link solution. Today, ruffian Heng will introduce several methods of decentralized links under MCU Xpress IDE, and also mention the practices under IAR and MDK.

1、 Prepare development environment

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

2、 Introduce RW segment decentralized link problem

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 saw the.Project project file, opened the project under MCUXpresso IDE, and then adjusted the engineering settings Memory in the following order:

Original hello_ The RW segment size in the world program is 264 bytes (including. Data and. BSS), plus the default 4KB heap and 4KB stack, which are linked to the 256 KB SRAM_ DTC_ There must be no problem in CM7 space (alias named RAM).

We’re in Hello now_ Add two global variables s to the world. C file_ Buf1 and S_ Buf2, recompile the project. It is found that the project cannot be compiled. Under the default link configuration, the IDE puts all RW segments into the space named ram in alias, resulting in insufficient RAM space, but in fact, there are still a lot of spare ram 2-8 on the chip. How to use the spare ramx? This is the problem. Later, we will try to use ram and RAM4 to solve the problem.

uint8_ t s_ buf1[1024 * 128] = {1};

3、 Review solutions on IAR / MDK

Before studying the decentralized link solution under the MCU Xpress IDE, let’s take a look at how it is implemented under the classic ide.

First, let’s look at the RW segment decentralized link solution under IAR. We only need to modify the corresponding link file mimxrt1176xxxxx_ cm7_ flexspi_ Nor.icf is as follows, and the original data is commented out_ Region and data2_ Region, and then use the | operator to connect their MEM spaces together to form a new data_ Region, and the IAR linker will automatically allocate RW and Zi segments to this new data_ Region.

define symbol m_data_start             = 0x20000000;
define symbol m_data_end               = 0x2003FFFF;

define symbol m_data2_start            = 0x202C0000;
define symbol m_data2_end              = 0x2033FFFF;

Let’s look at the RW segment decentralized link solution under MDK. We only need to modify the corresponding link file mimxrt1176xxxxx_ cm7_ flexspi_ Nor.scf is as follows. A new RW needs to be added_ m_ Data2 execution field (pay attention to the statement placement), and in the new execution field, press the original RW_ m_ Just add. Any (+ RW + Zi) in the data field, and the MDK linker will automatically allocate RW and Zi segments to these two RWS_ m_ In data space.

#define m_data_start                   0x20000000
#define m_data_size                    0x00040000

#define m_data2_start                  0x202C0000
#define m_data2_size                   0x00080000

4、 Several solutions under MCU Xpress IDE

Now back to the topic how to implement decentralized links in the MCU Xpress IDE, there are three methods:

4.1 use of Cr_ section_ Macros in macros. H

The first method is to use the header file of MCU Xpress ide_ section_ Macros in macros. H. Use__ Data (ramaliasname) or__ BSS (ramaliasname) macro to modify the variable definition, so that the mcuxpresso ide will automatically put the variable into the specified ramx when linking.

4.2 with GNU C__ attribute__ mechanism

The second method is essentially the same as the first method, but in another form, it needs the help of GNU C__ attribute__ Mechanism, ready to use__ attribute__ ((section (“usersectionname”)) syntax to modify the variable definition, put it into the custom program segment, and then link the configuration setting interface in the MCU Xpress ideExtra linker script input sectionsBox, specify the custom program segment to the specific ramx.

4.3 manually modifying. LD linked files

Although the first two methods can solve the problem, they are more troublesome when they encounter the definition of a large number of variables in multi-source files. They not only need to add corresponding modification codes one by one, but also manually calculate the space size (reasonably control the size of user-defined segments). With the addition, deletion and change of codes, they can not be adaptive. Is there a worry free way like IAR / MDK solution under the MCU Xpress ide?

Of course the answer is yes! In the link configuration setting interface of mcuxpresso IDEManage linker scriptIf the option is checked, the evkmimxrt1170 will be generated automatically_ hello_ world_ demo_ cm7_ Copy the debug.ld file in the same path and rename itLinker scriptSpecify a new linked file in the path.

Open the linked file evkmimxrt1170_ hello_ world_ demo_ cm7_ Debug_ User.ld, find the main data / BSS section execution field respectively, and then add the secondary data / BSS section execution field (follow the writing in the main section, just replace the ram name), and the MCU Xpress ide linker will automatically allocate RW and Zi segments to these two ram spaces.

Of course, we don’t need to modify the link file manually. We can use the link configuration setting interface of MCU Xpress ideExtra linker script input sectionsBox, put a copy of the default segment names * (. Data *) and * (. BSS *) into the specific ramx.

The effect set above is equivalent to. Data in the automatically generated link file_ RAM4 and. BSS_ Adding * (. Data *) and * (. BSS *) statements into the RAM4 execution domain can also achieve the desired purpose.

So far, several methods of decentralized linking of application RW segments 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.