μClinux embedded system external hardware devices quick debugging
Source: Internet
Author: User
Article Title: Fast debugging of external hardware devices embedded in the μC Linux system. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Abstract: In order to speed up the development and debugging of external hardware devices in the μC LINUX embedded system, the access method of devices with direct physical addresses is adopted to achieve fast access of external hardware devices in the μC embedded system. The address image is used to mirror the registers of the device to the memory space of the processor for unified addressing. The address operation function defined by the pointer is used to access the external device. This method can be used to quickly debug hardware external devices in the hardware environment of embedded systems supported by the μC Linux operating system, this avoids the delay of external hardware debugging due to waiting for the preparation of external hardware device drivers, thus speeding up the debugging of external hardware devices and improving the efficiency of hardware development and debugging.
Keywords: Method μ Clinux hardware debugging fast
A Linux-based embedded operating system is used in sensor network nodes. The key to developing an embedded microprocessor application system based on the Linux operating system is that Linux can access external devices with extended connections on the embedded processor. Once you can access the connected external chip device, you can flexibly run access control applications on the external devices of the embedded system on Linux.
The device driver framework of Linux on a personal PC is introduced. This article introduces the framework of the device driver that accesses external devices of the embedded system in μClinux. However, the implementation of the operation functions of the device driver is related to the specific external device hardware, and there is no specific unified solution. Device drivers use generic file access methods to operate devices, which facilitates Program Design for high-level users who do not know the underlying hardware. However, for the hardware design and debugging personnel, they cannot access the device without understanding the operation of the underlying hardware. The hardware designer must implement the specific operation process of the access function to test and flexibly control access to external extended devices. That is to say, you must complete the device driver before you can perform the next hardware device debugging.
To write and implement a device driver, you must first understand and implement access to the underlying device. This is a complex process. First, you need to know how the processor can address external devices and how to configure external devices. Then, you need to implement the underlying address access function. Then, you need to write the implementation function of the device driver, and then write the device driver; compile the driver into the Linux kernel. Finally, access the external device through standard device access in the Linux system.
It takes a lot of time to adopt the device driver method, thus delaying the hardware design and debugging process. On the other hand, because embedded Linux does not support dynamic loading of device driver modules, you can only compile the device modules into Linux, that is, you need to re-compile the device driver into the embedded Linux kernel. Therefore, the kernel code is added to the driver mode.
In the μClinux operating system, you can use a direct physical address to access external extended devices. You can perform read/write operations on the address unit of the device register to directly access the hardware, in addition, it is easy to understand the operation of the device from the bottom layer, and directly engage with the hardware. It is also easy to understand the working methods of the device from the bottom layer, speeding up the development and debugging of the product. This method only modifies a small amount of code and uses direct address access to quickly test access to external devices. Compared with the device driver method, the kernel code is slightly increased after re-compilation. In μClinux, if you want to access an external device with a direct physical address, you need to modify the startup code and create a device access function. This requires some skills. Taking Motorola's ColdFire MCF5272 embedded microprocessor platform as an example, this article describes how to quickly access external devices in μClinux.
1. Bucket addressing
For μClinux, it is designed for processors without MMU (Memory Manage Unit), that is, μClinux cannot use the virtual Memory management technology of the processor, and μClinux uses paging Management of Memory, the system paging the actual memory at startup. The program is loaded by page when the application is loaded. However, due to the absence of MMU management, μClinux uses the real-memory management policy.
The memory access of the Μ Clinux system is direct, and its access to the address does not need to go through MMU, but is directly sent to the online address for output. The addresses accessed in all programs are actually physical addresses. The operating system does not protect the memory space. Each process actually shares a runtime space.
Μ Clinux uses the real-memory mode. Each internal segment is continuous in the physical memory (no virtual memory) layer, and its memory space address image 1.
Based on whether the memory space is independent, I/O space configurations can be divided into two types: I/O space and memory space are independent of each other, in this way, dedicated I/O functions such as inb and outb are required for access to the I/O space. Intel CPU uses this method. The other is to use the I/O register as a part of the memory, that is, the I/O register and the memory are unified addressing, so that ordinary memory access statements can be used to read and write the I/O register. The Motorola 68K processor adopts this architecture, and the MCF5272 processor is also integrated. That is to say, its RAM, FLASH, and peripheral I/O are all centrally addressing, without address conversion and memory protection.
2. Fast Device Access
In C, pointers can be used to directly access memory address units. Therefore, pointers can be used to quickly operate external devices.
2.1 address Image
In order to access external devices, we should first map the peripheral registers to the memory of MCF5272, which is consistent with the memory. Therefore, you need to modify the corresponding code.
The embedded μClinux startup code for COLDFIRE MCF5272 consists of two parts:
μ Clinux/linux/arch/m68knommu/platform/5272/sysinit. c
Crt0_rom.S is written in assembly to complete CPU initialization settings. This is the code entry for the initial execution of the entire software system. Once the CPU is powered on, it will be executed here; sysinit. c is the c language code, complete the initialization settings of the MCF5272 integration module SIM (such as serial port, clock, General I/O, etc.), SDRAM, FLASH and other peripheral interfaces, chip selection, etc.
MCF5272 slice selection CS0 ~ CSBR0 ~ CSBR7 and CSOR0 ~ CSOR7 can map the address of the external device register to the internal storage space, so that access to the memory space can be used to access the external device. The register CSBR specifies the image memory start address, image memory capacity, and bus width. The register CSOR is used to configure access control. The Slice CS0 is used to start the memory ROM (FLASH ).
Modify the code in the c language file sysinit. c to implement the register image function of the peripherals. The sample code for CS2 is as follows:
Imm represents the Register address in the MCF5272 system integration module (SIM.
2.2 implement access functions
After the startup code is modified and the Register Unit of the external device is mapped to the memory unit, you can use macros and pointers that access the memory to quickly access the registers of the external device. There are two types of functions for fast Device Access.
2.2.1 use macro definition
(1) implement this function read_register () for the device
The read memory address unit content and write DATA to the memory address unit respectively. The base address of the address unit is IMM, And the OFFSET address is OFFSET. SIZE indicates the data level of each read/write operation. The value can be 8, 16, or 32, indicating the 8-bit, 16-bit, and 32-bit bus data of each operation.
2.2.2 direct definition using pointers
(1) Implement the read functions inb (), inw (), and inl () of the device.
The write functions are 8-bit, 16-bit, and 32-Bit Data Bus respectively.
3. Application lab
In the sensor network node of the author (SEE), the external device chip uses W99200F and contains more than 100 registers. After the chip is powered on and reset, the initial reset value of the chip register is known in the manual. According to the access method, it contains three types of registers: Read-only, write-only, and read/write. Table 1 shows the offset addresses of some registers of the W99200F chip and Their reset initialization values.
Table 1 some registers and their initialization values in the W99200F Chip
Data width reset value of register name offset Address Access Mode
Vint_source 0x0d read-only 8 0x40
Vbv_initial 0x18 read and write 8 0x13
Vquality 0x19 read/write 8 0x08
Vin_cntl 0x21 read and write 8 0x0c
Vsize_h 0x24 read/write 8 0x2c
Modify the startup code and implement the access function. The register CSBR2 specifies the memory start address of the image, the memory capacity of the image, and the bus width. Re-compile the μClinux kernel, burn the generated download files to FLASH, and re-power them on to run the kernel (or mount the host hard disk to manually start the μClinux kernel ), compile a C Language Test Procedure
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service