The development boards of microcontroller manufacturers, and the software project routines they provide with the development boards, can be of great help when engineers embark on a new design. However, after the design project has completed its early stage, the software provided by the manufacturer may also cause some problems during further design.
The design of using a real-time operating system as an application code platform still faces many challenges, such as how to allocate functions to different parallel tasks, how to design highly reliable inter-process communication, and how to test the entire software package on hardware.
More and more OEM manufacturers have discovered that the best way to avoid the above two problems is to start a new design with the open source, proven, scalable, and scalable operating system Linux that can run on different hardware platforms. In terms of the number of operating systems that have been ported to various computer hardware platforms, Linux is second to none. Derivatives of Linux have been running in a wide range of embedded systems, including: network routers, mobile phones, building automation controls, televisions, and video game consoles.
Although Linux is successfully used, it does not mean that it is easy to use. Linux contains more than one million lines of code, and its operation has a distinct flavor of Linux methodology, which may be difficult for beginners to grasp quickly.
Therefore, the purpose of this article is to start a new design project for using the embedded operating system version of Linux-μClinux. The guide is divided into five steps. To illustrate this guide, this article introduces a μClinux project implementation on STMicroelectronics' STM32F429 microcontroller (ARMCortex-M4 core, up to 180MHz), using Emcraft's STM32F429 DiscoveryLinux Board Support Package (BSP).
Step 1: Linux tools and project layoutEvery embedded software design starts with choosing the right tool.
Tool chain is a group of software development tools connected (or linked) together, which includes such as the GNU Compiler Collection (GCC), binutils (a group including linkers, assemblers and other development tools for object files and archive tools) ) And glibc (a C function library that provides system calls and basic functions); in some cases, it may also include other tools such as compilers and debuggers.
The tool chain used for embedded development is a cross tool chain, more commonly called a cross compiler.
GNUBinuTIls is the first component of the embedded Linux tool chain. GNUBinuTIls contains two important tools:
â— "as", assembler, converts assembly code (generated by GCC) into binary code
â— "ld", linker, connect discrete object code segments to libraries or form executable files
The compiler is the second important part of the tool chain. In embedded Linux, it is called GCC and supports many kinds of microcontrollers and processor architectures.
Next is the C function library. It implements the traditional POSIX application programming interface (API) of Linux, which can be used to develop user space applications. It interfaces with the kernel through system calls and provides high-level services.
Engineers have several choices of C library:
â—glibc is an available C function library provided by the open source GNU project. The library is full-featured, portable, and it complies with Linux standards.
â—Embedded GLIBC (EGLIBC) is a derivative version optimized for embedded systems. The code is streamlined, supports cross-compilation and cross-testing, and its source code and binary code are compatible with GLIBC.
â—uClibc is another C function library, which can be used when the flash memory space is limited and/or the memory footprint must be minimal.
The debugger is usually part of the tool chain, because when debugging the application running on the target machine, a cross-debugger is required. In the field of embedded Linux, GDB is a common debugger.
The above tools are so indispensable, but when they are fighting on their own, it will take too long to compile the Linux source code and integrate it into the final image (image). Fortunately, Buildroot (a tool that automatically generates cross-compilation tools) will automatically complete the process of building a complete embedded system, and simplifies cross-compilation by generating any or all of the following tasks:
â—Cross compilation tool chain
â— Root File System
â—Kernel image
â— Boot image
For embedded system designers, it is also convenient to use a tool (uTIlity) aggregation tool, such as BusyBox, which integrates the tools that are usually most needed. According to BusyBox's information page, "It integrates miniature versions of many common UNIX tools into a small executable file. It provides an alternative to most of the tools you usually see in tools such as GNUfileuTIls and shellutils. BusyBox The tools in it usually have fewer choices than its full-featured GNU counterpart; but the expected functions and behaviors provided by the included options are almost the same as those provided by the corresponding GNU. For any small or embedded system, BusyBox provides The environment is quite complete."
The last important tool is a BSP, which is specially made for the motherboard equipped with the target MCU or processor of the project.
The BSP includes pre-configured tools and a boot loader that loads the operating system onto the motherboard. It also provides source code for the kernel and device drivers (see Figure 1).
Figure 1: Main components of EmcraftBSP for STM32F429Discovery board
Step 2: Boot sequence, clock system, memory and serial interfaceThe typical embedded Linux boot sequence is executed as follows:
1) The bootloader firmware (U-Boot in the sample project) runs on the built-in flash memory of the target MCU (no external memory is required), and after power-on/reset, it performs all the necessary initialization work, including setting the serial port and using the external memory (RAM) The memory controller that is accessed.
2) U-Boot can transfer the Linux image from external Flash to external RAM, and transfer control to the kernel entry point in RAM. Linux images can be compressed to save flash memory space, at the cost of decompression time at startup.
3) Linux boots and installs the RAM-based file system (initramfs) as the root file system. When the project is built, Initramfs is filled with the required files and directories, and then simply linked to the kernel.
4) Under the Linux kernel, execute /sbin/init. The /sbin/init program initializes the system according to the description of the configuration file in /etc/inittab.
5) Once the initialization process completes run-level execution and commands in /sbin/init, it will start a login process.
6) The execution of the shell initialization file /etc/profile marks the completion of the startup process.
Enabling in-place execution (ExecuteInPlace-XIP) can significantly shorten the startup time and improve overall performance. XIP is a method of executing code from flash memory. Usually, Linux code is loaded from flash memory to external memory, and then executed from the external memory. By executing from the flash memory, there is no need to copy this step, so less memory is needed, and the read-only memory no longer occupies the program space.
The sample project in this article is based on STM32F429MCU. In fact, users may find that initializing the peripherals of STM32F4 series MCUs is not easy to grasp at the beginning. Fortunately, STMicroelectronics has developed some tools to help solve this problem. The STM32CubeMX initialization code generator (part number UM1718) is the latest. The tool includes every detail of peripheral initialization. When configuring the peripheral, it will display warnings and errors, and warn of hardware conflicts.
For small embedded Linux projects, STM32F429MCU internal flash memory is sufficient. It is important to remember that multiple binary images (bootloader, Linux kernel, and root file system) are used in embedded Linux projects: these all require flash sector boundary alignment. This avoids the risk that when one image is loaded, another image is partially deleted or damaged.
Step 3: Install Linux on the hostTo build an embedded Linux project, a Linux host is required. For WindowsPC, it is best to install OracleVirtualBox to create "a" new virtual machine with 512MbyteRAM and 16Gbyte hard disk.
There are many Linux versions available; according to the author's experience, Debian is the one that matches the VirtualBox environment. This Linux host must be able to access the Internet in order to download the GNU cross-compilation tool for this ARMCortex-M target MCU. The designer will create a tree structure similar to the one shown in Figure 1 and save the cross-build tool to the /tools folder.
At this point, it is necessary to create an ACTIVATE.sh script. Just use the following code to achieve. (<...> is the path of the extracted GNU tool folder):
exportINSTALL_ROOT=<.......>
exportPATH=$INSTALL_ROOT/bin:$PATH
exportCROSS_COMPILE=arm-uclinuxeabiexport
CROSS_COMPILE_APPS=arm-uclinuxeabiexport
MCU=STMDISCO
exportARCH=arm
Install GNU tools in a clean Linux system, but its use is not self-sufficient, and it actually requires the cooperation of other systems. Its operation actually depends on a number of other system components (such as the host C/C++ compiler, standard C library header files, and some system tools). One way to obtain these necessary components is to install the Eclipse Integrated Development Environment (IDE) for C. In addition to solving this imminent problem, EclipseIDE can also help in many other aspects of the development process. Of course, it is not the purpose of this article to detail the features of EclipseIDE.
Now, it's time to enable the Linux terminal tool: click on "Applications", then "Accessories" and "Terminal" (see Figure 2).
Figure 2: The "Terminal" tool and "Files" included in Linux, a graphical tool similar to Windows Explorer.
The terminal is the main tool used to configure the Linux host and build embedded Linux applications. Type the following commands to install Eclipse and other required tools:
su[Enter root user password]
apt-getinstalleclipse-cdt
apt-getinstallgenromfs
apt-getinstalllibncurses5-dev
apt-getinstallgit
apt-getinstallmc
The final step in preparing the Linux project is to download STM32F429DiscoveryBuildroot and unzip it to the /uclinux folder.
Step 4: Build μClinux with BuildrootIt is now necessary to close the terminal that previously used the root user profile and start a new terminal. Enter "mc" in the command line and use the navigator to navigate to "Documents", then enter the "uClinux" command. Press Ctrl+O and activate the development part of LinuxARMCortex-M, and run the ".ACTIVATE.sh" command. Press Ctrl+O again and enter the "stm32f429-linux-builder-master" folder.
The user now has two options. If you use the sample project in VirtualBox, please follow the "makeclean" and "makeall" command sequence. To prepare a brand new environment, use the "make" command. After about 30 minutes, the new μClinux image will be available as shown below:
out\uboot\u-boot.bin
out\kernel\arch\arm\boot\xipuImage.bin
outomfs.bin
Write these new images to flash memory. If you use Windows and ST-LINK tools, the following code will work:
ST-LINK_CLI.exe-ME
ST-LINK_CLI.exe-P "u-boot.bin" 0x08000000
ST-LINK_CLI.exe-P "xipuImage.bin" 0x08020000
ST-LINK_CLI.exe-P "romfs.bin" 0x08120000
Connect the serial debugger (serialconsole) to the target circuit board (external RX=>PC10, external TX=>PC11, 115200bits/s, 8 data bits, no parity, 1 stop bit mode), and then press Reset button, the μClinux project will start running. The boot output will be displayed on the serial debugger, and the Linux penguin logo will appear on the display.
Step 5: Create the "Hello, World" applicationNow, follow the code example and the instructions below to add a user application to the μClinux project.
Create: "stm32f429-linux-builder-master/user/src/hello.c" file:
#include
intmain(){
printf("Hello,world");
return0;
}
If necessary, use the Tab key to create: "stm32f429-linux-builder-master/user/Makefile" file:
CC=$(CROSS_COMPILE)gcc
LDFLAGS?=$(CFLAGS)
target_out?=out
all:checkdirs
[Tab]$(CC)$(LDFLAGS)src/hello/hello.co$(target_out)/bin/
hello$(LDLIBS)
[Tab]-rm-rf$(target_out)/bin/*.gdb
checkdirs:
[Tab]mkdir-p$(target_out)/bin
clean:
[Tab]-rm-rf$(target_out)
Use the activate.sh script to test the "Hello, world" application on the host without activating the cross-compilation environment.
In the /user folder, enter:
makeall
./out/bin/hello
To embed hello.c into the script in LinuxBuildroot, modify the mk/rootf.mak file and use the Tab key if necessary. (Bold text indicates the beginning of a new line):
...
user_hello:
[Tab]make-C$(user_dir)CROSS_COMPILE=$(CROSS_
COMPILE)CFLAGS=$(ROOTFS_CFLAGS)target_
out=$(target_out_user)
$(rootfs_target):$(rootfs_dir)$(target_out_busybox)/.config
user_hello
[Tab]cp-af$(rootfs_dir)/*$(target_out_romfs)
[Tab]cp-f$(target_out_kernel)/fs/ext2/ext2.ko$(target_out_romfs)/lib/modules
[Tab]cp-f$(target_out_kernel)/fs/mbcache.ko$(target_out_romfs)/lib/modules
[Tab]cp-f$(target_out_user)/bin/*$(target_out_romfs)/usr/bin
…
The mk/defs.mak file needs to be modified last. Add the following lines:
...
user_dir:=$(root_dir)/user
target_out_user:=$(target_out)/user
user_dir:=$(root_dir)/user
target_out_user:=$(target_out)/user
Once the image is built, downloaded and run on the target MCU, the application and other existing applications can be found in the /usr/bin directory. Type "hello[enter]" on the terminal connected to the Discovery board to test the application.
About Bare Wire |
|
Application: Suitable for manufacturing electric motors, windings of electrical equipment, automobile electrical rotors, installation and distribution equipment and other electrical fields.
Name
Conductor
Copper
Dimension(mm)
Rectangular: Thickness(a): 0.90 ~ 5.60
Width(b): 3.15 ~ 16.00
Standard
GB;
Packing
160 kg~180 kg ply-wood spool(250*500; 250*600)
Application
Suitable for manufacturing electric motors, windings of electrical equipment, automobile electrical rotors, installation and distribution equipment and other electrical fields.
Bare wire includes Copper Bar and Aluminium bar
Bare Wire,Bare Copper Wire For Motor,Flexible Bare Copper Wire,Electrical Bare Copper Wire
HENAN HUAYANG ELECTRICAL TECHNOLOGY GROUP CO.,LTD , https://www.huaonwire.com