This article introduces how to use
GNU
tools to develop
ARM
-based embedded systems, as well as specific methods for using compilers, connectors and debugging tools, to provide a low-cost development method for the majority of embedded system developers.
At present, ARM's 32-bit
RISC
processors, with their low core power consumption, low cost, powerful functions, and unique 16/32-bit dual instruction sets, have become the RISC standard for embedded solutions such as mobile communications, handheld computing, and multimedia digital consumption, with a market share of more than 75%. Many companies have launched their own processor products based on the ARM core, and more and more developers have begun to develop for the ARM platform. Usually, developers need to purchase development boards provided by chip manufacturers or third parties, and also purchase development software, such as C compilers or development environments integrated with real-time operating systems. The price of development boards ranges from hundreds to thousands of dollars, while the price of compilers and real-time operating systems is easily thousands to tens of thousands of dollars. In this way, in the early stages of development, the investment in software and hardware requires tens of thousands of dollars, which is undoubtedly too expensive for most domestic developers.
Fortunately, the free software advocated by GNU has brought good news to developers. In 1984, the goal was to develop a complete operating system and supporting tools similar to
Unix
that were completely free: the GNU system (pronounced "guh-NEW"). GNU's operating system and development tools are free and follow the GNU General Public License (GPL) agreement. Anyone can obtain all the source code from the Internet. For detailed information about GNU and the public license agreement, readers can refer to the Chinese introduction of the GNU website: http://www.gnu.org/home.cn.html.
In addition to the well-known Linux operating system, GNU's software also includes compilers (gcc, g++), binary conversion tools (objdump, objcopy), debugging tools (gdb, gdbserver, kgdb) and development libraries based on different hardware platforms. The main disadvantage of GNU development tools is that they use command lines, which are difficult for users to master and use, and are not as easy to use as development tools based on Windows systems. However, the complexity of GNU tools is due to its closer proximity to the bottom layer of compilers and operating systems and greater flexibility. Once you learn and master the relevant tools, you will understand the basics of system design and lay the foundation for future development work. GNU development tools are free and follow the GPL agreement. Anyone can get them from the Internet. The author participated in the development of an embedded Linux system based on the ARM platform, using the Motorola Dragon Ball series MC928MX1. From test code, boot program, embedded Linux porting, application program, and graphical interface, GNU tools can be used for development without additional investment in development tools. The development method introduced in this article is also applicable to ARM-based products of other companies.
1 Hardware Platform
MC928MX1 (hereinafter referred to as MX1) is Motorola's first
MCU
based on the ARM core
, mainly for high-end embedded applications. It uses the ARM920T core internally and integrates SDRAM/Flash, LCD, USB,
Bluetooth
(bluetooth), Multimedia Flash Card (
MMC
),
CMOS
camera and other controllers. For detailed information about MX1, interested readers can refer to http://www.motorola.com.cn/semiconductors/. As the minimum system for application development, it must include RAM (program running space), Flash (storing target code) and serial interface (for debugging and downloading programs). MX1 provides 6 chip select terminals (CS0~CS5), built-in SDRAM controller, and data width of 32 bits. In the author's system, two 8M×16-bit SDRAMs and two 4M×16-bit synchronous Flash memories are used, which are connected to the lower 16 bits and higher 16 bits of the data line respectively, as shown in Figure 1.
In Figure 1, SDRAM is connected to the chip select terminal CS2, Flash is connected to the chip select terminal CS3, and the rest are control signals of SDRAM/Flash. The minimum system also includes at least one serial interface, which can use the built-in UART controller of MX1, which is omitted in the figure.
2 Bootstrap mode
Currently, many embedded processors provide a bootstrap mode for users to write boot code. The bootstrap mode uses a boot program that is fixed inside the chip. When the processor is reset, if a signal is added to a specific pin, the processor will execute the program in the fixed ROM after reset. For example, MX1 provides 4 reset pins. Different combinations of pin levels during reset can start the system from different chip select ends. The program in the bootstrap ROM completes the initialization of the serial port and then waits for the user to write the user code from the serial port. The bootstrap mode can accept a text file in a special format, including data and the address to be written/read. For the code format of the bootstrap mode, please refer to the manual of the relevant chip. Motorola's website also provides many small tools to help developers convert files in other formats into the bootstrap mode format. The program downloaded through the bootstrap mode is usually a program that communicates with the host computer software (such as the hyperterminal) to complete the operation of receiving data and writing it to the Flash. The data written can be the user's own application, data or the kernel of the operating system. The bootstrap program downloaded through the bootstrap mode can also be developed with GNU tools.
3 GNU compiler and development tools
The compilation tools provided by GNU include assembler as, C compiler gcc, C++ compiler g++, linker ld and binary conversion tool objcopy. The tools based on ARM platform are arm-linux-as, arm-linux-gcc, arm-linux-g++, arm -linux-ld and arm-linux-objcopy. All GNU development tools can be downloaded from www.gnu.org, and ARM-based tools can be obtained from www.uclinux.org. GNU compiler is very powerful, with hundreds of operation options, which is why such tools give beginners a headache. However, only a limited number of them are needed in actual development, and most of them can use the default options. The development process of GNU tools is as follows: write C, C++ language or assembly source program, use gcc or g++ to generate target files, write connection script files, use the linker to generate the final target file (elf format), and use the binary conversion tool to generate downloadable binary code. GNU tools all run under Linux, and developers need a PC running Linux as the host computer. Due to space limitations, the entire embedded operating system development process cannot be fully introduced. The development process will be explained using the boot program downloaded through the boot mode mentioned in Section 2 as an example. For large systems such as Linux, the basic development process is the same.
The boot program will be downloaded to the MX1's on-chip RAM through the boot mode, starting from address 0x00300000 and executing. After completing the initialization of the serial port and SDRAM, the boot program will wait to receive the application or operating system kernel and place the received data in the SDRAM. After the data is received, the boot program writes the data in the SDRAM to the Flash, and the system can be directly booted from the Flash next time. Since the operating system kernel is relatively large, such as Linux, which is more than 1 MB, error correction must be considered during the download process. Therefore, the receiving part uses the Xmode protocol, and the file can be sent using the Xmode sending method of the Windows HyperTerminal. [page]
(1) Write C, C++ language or assembly source program
Usually, the assembly source program is used for the most basic initialization of the system, such as initializing the stack pointer, setting the page table, and operating the ARM coprocessor. After the initialization is completed, you can jump to the C code for execution. It should be noted that the GNU assembler follows AT&T's assembly syntax. Readers can download the relevant specifications from the GNU website (www.gnu.org). The default entry point of the assembler is the start label. Users can also use the ENTRY flag in the linker script file to specify other entry points (see the description of the linker script below).
(2) Generate target files using gcc or g++
If the application includes multiple files, they need to be compiled separately and finally connected with a connector. For example, the author's boot program includes 3 files: init.s (assembly code, initialization hardware), xmrecever.c (communication module, using Xmode protocol) and flash.c (Flash erase module).
Use the following commands to generate the target files respectively:
arm-linux-gcc-c-O2-o init.o init.s
arm-linux-gcc-c-O2-o xmrecever.o xmrecever.c
arm-linux-gcc-c-O2-o flash.o flash.c
The -c command means only generating the target code without linking; the -o command specifies the name of the target file; -O2 means using secondary optimization, which can make the generated code shorter and run faster. If the project contains many files, you need to write a makefile. For the content of makefile, interested readers are welcome to refer to relevant materials.
(3) Write a connection script file
. Compilers such as gcc have built-in default connection scripts. If the default script is used, the generated target code needs the operating system to load and run. In order to run directly on the embedded system, you need to write your own connection script file. To write a connection script, you must first have a certain understanding of the format of the target file. The target file generated by the GNU compiler is in elf format by default. The elf file consists of several sections. If not specified, the target code generated by the C source program includes the following sections: .text (text section) contains the program's instruction code; .data (data section) contains fixed data, such as constants and strings; .bss (uninitialized data section) contains uninitialized variables, arrays, etc. The target code generated by the C++ source program also includes .fini (destructor code) and .init (constructor code). For the elf file format, readers can refer to relevant materials. The connector's task is to connect the .text, .data, and .bss sections of multiple target files together, and the linker script file tells the connector where to start placing these sections. For example, the author's boot program connection file link.lds is:
ENTRY(begin)
SECTION
{ .=0x00300000;
.text : { *(.text) }
.data: { *(.data) }
.bss: { *(.bss) }
}
Among them, ENTRY(begin) indicates that the entry point of the program is the begin label; .=0x00300000 indicates that the starting address of the target code is 0x00300000, and this address is the on-chip RAM of MX1; .text : { *(.text) } means that the code segments of all target files are placed starting from 0x00300000, and the subsequent .data: { *(.data) } indicates that the data segment starts from the end of the code segment, followed by the .bss segment.
(4) Generate the final target file using the linker
With the linker script file, the following command can generate the final target file:
arm-linux-ld-nostadlib-o bootstrap.elf-T link.lds init.o xmrecever.o flash.o
Among them, ostadlib means not to connect to the system runtime library, but directly from the begin entry; -o specifies the name of the target file; -T specifies the connection script file to be used; and finally, there is a list of target files to be connected.
(5) Generate binary code
The elf file generated by the connection cannot be downloaded and executed directly. The final binary file can be generated by the objcopy tool:
arm-linux-objcopy-O binary bootstrap.elf bootstrap.bin,
where -Obinary specifies that the file is generated in binary format. Objcopy can also generate S format files by replacing the parameter with -O srec. If you want to disassemble the generated target code, you can also use the objdump tool:
arm-linux-objdump-D bootstrap.elf.
At this point, the generated target file can be directly written to the Flash and run. If you want to download it in boot mode, you also need to convert it to the file format of the boot mode. The relevant conversion tools can be found on Motorola's website.
After mastering the GNU tools, developers can develop or port programs in C or C++ code. Users can directly develop simple applications without an operating system. But for more complex applications, an operating system is indispensable. Currently popular operating systems with open source code such as Linux and μC/OS can be compiled with GNU tools. ARM's Linux has many mature versions that can support multiple processors such as ARM720, ARM920, ARM1020, etc. Readers can get the latest information from www.uclinux.org or www.armdevzone.com. The processor-related codes in the Linux porting process are all placed in the arch/arm directory. For the kernel, what users need to do is to set the memory image, RAM start address, I/O address space and virtual I/O address space of their own system, see the arch/arm/mach-integrator/arch.c file. In addition to the kernel, users also need to compile various drivers for their own systems.
4 Debugging tools
The GNU debugging tools under Linux are mainly gdb, gdbserver and kgdb. Among them, gdb and gdbserver can complete the remote debugging of Linux applications on the target board. gdbserver is a very small application that runs on the target board, can monitor the operation of the debugged process, and communicate with gdb on the host computer through the serial port. Developers can input commands through the gdb of the host computer to control the running of the process on the target board and view the contents of the memory and registers. Versions after gdb5.1.1 have added support for ARM processors. Adding the -target==arm parameter during initialization can directly generate a gdbserver based on the ARM platform. The gdb tool can be downloaded from ftp://ftp.gnu.org/pub/gnu/gdb/.
For debugging the Linux kernel, the kgdb tool can be used. It also needs to communicate with the gdb on the host computer through the serial port to debug the Linux kernel of the target board. Due to space limitations, interested readers can learn about the specific usage methods from http://oss.sgi.com/projects/kgdb/.
Conclusion
This article takes a specific example to introduce the common functions in the GNU tool. In fact, the functions of the GNU tool are far more than these. Further operations include: software optimization for different processors and different algorithms, efficient embedded assembly, large project management functions, etc. I believe that GNU will become the choice of more and more developers.
Previous article:Debugging Technology for 32-bit ARM Embedded Processors
Next article:Application and selection of 32-bit RISC CPU ARM chips
Recommended ReadingLatest update time:2024-11-16 18:02
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- What parameter changes does the OBD2 plug use to obtain the engine speed signal from the OBD interface?
- Study and share information about wildfire motors
- 【Qinheng CH582】8 CH582 evaluation summary
- The robotic arm that won the German Technology Innovation Award
- TMS320C66x programming 16-bit to 32-bit operation
- USB Issues
- Some useful terms related to antennas
- ST Low Power RF Products FAQ
- MSP430 FRAM Microcontrollers Enable Energy Harvesting
- EEWORLD University ---- 3-Level Buck Converter: How Does It Work?