Linking and locating target code when developing embedded systems with IAR EWARM

Publisher:MeshulunLatest update time:2012-03-27 Source: 单片机与嵌入式系统应用 Keywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 The role of data segments and code segments
The IAR C/C-+ compiler is a world-leading standard C/C-+ compiler that supports C or C++ programming languages ​​that conform to the ANSI C standard. After the source program is compiled, data segments and code segments containing data or code memory logical images are generated. Each segment has a segment name and a segment type that represents its memory space. The segment type CODE represents the execution code in ROM, the segment type CONST represents the data in ROM, and the segment type DATA represents the data in RAM. The segment name can be the same as the segment type, but their meanings are different and should not be confused in actual use. Table 1 lists the various segments, segment types, and their read/write attribute descriptions used by the IAR C/C++ compiler.
1.1 Data segment
Data is located in the DATA segment, including static memory, stack, heap, and located data. The DATA segment can have a suffix. For example, DATA_C is used for constant data, including text strings; DATA_Z is used for static and global variables declared without initial values ​​or with an initial value of 0.
Global variables or declared static variables are stored in static memory space. The declared static variables are: variables with initial values ​​of 0 or non-zero, variables located using the "@" or "#pragma" operator, variables declared as "const" and thus can be saved in ROM, and variables defined using the keyword "__no_init" that are not allowed to be initialized.
The stack is used to store local variables and other temporary data for functions. It is a continuous memory pointed to by the stack pointer register SP. The data segment used as the stack is called "CSTACK". The initialization module cstartup initializes the stack pointer to point to the end of the CSTACK segment. The stack capacity depends largely on the specific program operation details. If the given stack capacity is too small, the data in the stack will be overwritten and cause a program error; if the given stack capacity is too large, RAM space will be wasted. The ARM core processor supports 5 abnormal working modes, each mode has its own stack. The user should initialize each stack pointer separately in the startup code and perform segment positioning in the linker command file.

The heap is used to store dynamically allocated data. The data segment used as the heap is called "HEAP", and it is included in the application system only when dynamic memory allocation is used. Similar to the CSTACK segment, the size of the HEAP segment depends on the specific application. When using the standard input/output library, the HEAP capacity should be set to meet the requirements for buffering standard input/output, usually 512 bytes.
Variables with explicitly specified addresses will be located in the DATA_AC segment or the DATA_AN segment. The DATA_AC segment is used for data initialized to constants, and the DATA_AN segment is used for variables declared as "__no_init". [page]
1.2 Code segment
The code segment includes startup code, ordinary code, and exception code.
The startup code is located in the ICODE segment, including system startup (cstartup), run initialization (cmain), and system termination (cexit) codes. The ICODE segment must be located in a continuous memory space, and the -P command option cannot be used in the linker command file to locate the ICODE segment. The startup code is called through the reset vector. The
ordinary code is located in the CODE segment, which stores the execution code of ordinary functions. The CODE segment can have a suffix, such as the CODE_I segment, which stores the code initialized by the CODE_ID segment and executed in RAM. Similar to the compiler's treatment of initialized variables, the code is copied from the initialization period in the ROM memory to the RAM memory before execution when it is run. The normal code segment is also related to symbols and debugging information. The
exception vector is located in the INTVEC segment. If an instruction that jumps to the exception handler (such as the B instruction) is used at the exception vector, the exception handler must be within the range that the jump instruction can reach. This problem does not exist when using the PC load instruction (such as the LDR PC instruction).

2 Segment Positioning in Memory
The segments generated by the IAR C compiler need to be positioned in memory by the XLINK linker according to a series of command options in the link command file to ensure the normal operation of the target code. The link command file is a text file with an extension of ".xcl" that contains various XLINK command options.
The most commonly used command options are: CPU command option -C, constant definition command option D, segment positioning command option -Z or -P.
The "-c" command option is used to specify the CPU used by the user system, such as: -carm.
The "-D" command option is used to specify the starting and ending addresses of the memory, such as:
-DROMSTART=40000040
-DROMEND=40006FFF
The "-D" command option can also be used to define the stack length or other constants, such as:
-D_CSTACK——STZE=2048
-D_IRQ_STACK_SIZE=5l2
The "-Z" command option locates in the order in which the segments appear, and specifies the end point of each memory range, such as:
-Z(CONST)MYSEGMENTA,MYSEGMENTB=008000-OFFFFF
Two different types of segments can be located in the same memory area if the range of the second segment is not specified, such as:
-Z(CONST)MYSEGMENTA=008000-0FFFFF
-Z(CODE)MYCODE
The two memory ranges can overlap, allowing segments with different positioning requirements to share part of the memory space, such as:
-Z(CONST)MYSMALLSEGMENT=008000-000FFF
-Z(CONST)MYLARGESEGMENT=008000-OFFFFF
The "-P" command option performs segment positioning in a non-continuous manner, which can make full use of the memory space, such as:
-P(DATA)MYDATA=100000-101FFF, 110000-11lFFF
If the user application system also has a section of RAM located in the memory
0x10F000~Oxl0F7FF, just add this range to the above command:
-P(DATA)MYDATA=100000-10lFFF, 10F00010F7FF, 110000-11lFFF


3 Examples of link command file applications
The role of the linker command file is to inform the XLLINK linker to perform various segment positioning in the memory according to the command options given in the file; due to the wide variety of ARM core processors and the different memory configurations of each processor, the linker command file usually needs to be customized according to the specific application system hardware design to ensure that the code and data do not cross the boundary within the given memory range and cause errors.
The following takes the Philips LPC2148 ARM core processor chip as an example to explain how to customize the XLINK link command file. The LPC2148 has 32 KB on-chip SRAM and 512 KB on-chip Flash, and its memory addresses are as follows.
On-chip Flash: 0x00000000~Ox0007FFFF.
On-chip SRAM: 0x40000000~0x413007FFF.
According to the memory address range of the LPC2148, the XLINK link command file for debugging the application in the on-chip SRAM or in the on-chip Flash can be customized separately.
(1) Link command file for debugging application in on-chip SRAM

[page]
(2) Link command file for debugging applications in on-chip Flash
The above link command file can be used to debug applications in LPC2148 on-chip Flash after appropriate modifications. The main thing is to redefine the memory addresses of the code segment and data segment, and sometimes redefine the length of the stack and heap. Only the modified parts are listed below, and other identical parts are omitted:


4 Conclusion
When developing ARM embedded systems using the IAR EWARM integrated environment, it is necessary to inform the XLINK linker through the link command file how to link and locate the code and data segments generated by the C compiler. Users need to be familiar with the SRAM and Flash memory configuration of the ARM core processor used, and determine which XLINK command options to use based on the actual available address space. Only by using appropriate command options to correctly locate the code and data segments, generate reliable execution code, and finally write the execution code into Flash can the ARM embedded system design be successfully completed; otherwise, even if the written C source program is optimized, it will not play its due role.

Keywords:ARM Reference address:Linking and locating target code when developing embedded systems with IAR EWARM

Previous article:Design of Embedded Wireless Video Monitoring System
Next article:Programming and Application of LPC2000 Series CAN Acceptance Filter

Recommended ReadingLatest update time:2024-11-16 18:05

Miniaturized remote monitoring intelligent power supply system based on ARM Cortex-M3
  With the development of contemporary science and technology, the maintenance and management of power supplies for a huge number of various types of equipment requires a lot of manpower and material resources. The environment in which communication/power facilities are located is becoming more and more complex, with
[Microcontroller]
Miniaturized remote monitoring intelligent power supply system based on ARM Cortex-M3
Part3_lesson3---ARM pseudo instruction learning
1. ARM machine code Disassembling the elf format file can get the machine code of the corresponding assembly file: arm-linux-objdump -D -S start.elf For machine code analysis, please refer to the ARM Architecture Reference Manual chapter The ARM Instruction Set. 2. Define class directives
[Microcontroller]
Part3_lesson3---ARM pseudo instruction learning
ASIC Design of SD/MMC Card Controller Based on ARM9
introduction Nowadays, multimedia digital products are developing rapidly, and various audio and video functions are constantly enhanced, which makes the system's requirements for the performance, capacity, and security of storage media increase day by day. MMC cards and SD cards are both flash-based storage de
[Microcontroller]
ASIC Design of SD/MMC Card Controller Based on ARM9
22 commonly used concepts of ARM!
1. Explanation of some common English abbreviations in ARM MSB: most significant bit; LSB: least significant bit; AHB: Advanced High-Performance Bus; VPB: VLSI peripheral bus that connects on-chip and off-chip functions; EMC: External Memory Controller; MAM: Memory Acceleration Module; VIC: Vectored Inte
[Microcontroller]
Construction of embedded platform based on ARM and Linux
Since entering the post-PC era, along with the development of design and manufacturing technology, integrated circuits have evolved from transistor integration to current IP integration, namely SoC (System on Chip) design technology. This has led to embedded systems penetrating into various industries in today's soc
[Microcontroller]
Construction of embedded platform based on ARM and Linux
Real-time data storage solution based on ARM series 32-bit high-performance embedded processor
In the use of data acquisition equipment and instruments with related functions, data storage and transmission is a very important link. Based on successful practice, this article introduces the use of industrial-grade ARM series 32-bit high-performance embedded processors to achieve data storage after data acquisitio
[Microcontroller]
Real-time data storage solution based on ARM series 32-bit high-performance embedded processor
Design of remote control system for campus LED bulletin board based on ARM
  In recent years, LED electronic display screens have attracted increasing attention as a high-tech product. They can display text, graphics and image information in real time or in a loop. They have many advantages, such as rich display modes, strong viewing, convenient display content modification, high brightness,
[Power Management]
Design of remote control system for campus LED bulletin board based on ARM
Application of ARM9 system in intelligent monitoring system of wireless transmitter
1. Overview Guangxi Radio and Television Information Network Co., Ltd. has developed a wireless transmitter remote network monitoring and management system in accordance with the design idea of ​​"someone is left behind, no one is on duty", which conducts remote centralized monitoring and management of 16 r
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号