The big guy will take you deep into the embedded system, how to remotely debug the embedded system

The big guy will take you deep into the embedded system, how to remotely debug the embedded system

With the development of current technology, embedded systems are gradually being integrated into people’s lives. For embedded systems, we should know something. As far as professionals are concerned, they are already familiar with embedded systems. In order to improve everyone’s understanding of embedded systems, this article will introduce the remote debugging of embedded systems. Note that the embedded system remote debugging solution in this article only represents a method and only provides a reference. If you are interested in embedded systems or remote debugging of embedded systems, keep reading.

With the development of current technology, embedded systems are gradually being integrated into people’s lives. For embedded systems, we should know something. As far as professionals are concerned, they are already familiar with embedded systems. In order to improve everyone’s understanding of embedded systems, this article will introduce the remote debugging of embedded systems. Note that the embedded system remote debugging solution in this article only represents a method and only provides a reference. If you are interested in embedded systems or remote debugging of embedded systems, keep reading.

The big guy will take you deep into the embedded system, how to remotely debug the embedded system

1. Basic method

Figure 1(a) shows the traditional embedded debugging method: the host PC is connected to the slave embedded system through the serial port, receives the debugging information sent from the embedded system and sends the debugging instructions to the embedded system, and the host and the slave are connected with each other. Only a few meters or tens of meters away. Figure 1(b) is a popular remote embedded debugging method: the host PC and the slave embedded system are respectively connected to the network through Ethernet, and the host receives debugging information and sends the embedded system through protocols such as Telnet. instruction. The method introduced in this paper is to combine the two, the remote embedded system is connected to its adjacent PC2 through a serial port, the host PC1 and the slave PC2 are each connected to the network through Ethernet, and the host PC1 still uses the Telnet protocol ( Use the “Super Terminal” program that comes with Windows) to communicate with the slave PC2, and run a software Telent2com designed by us on the slave PC2, which converts the Telnet protocol into serial data transmission and reception. In order to better control the remote embedded system, special control commands in the Telnet protocol are also used to complete the embedded system, such as power supply and I/O, through the extra control line of the serial port and certain hardware circuits. The control of the input is shown in Figure 1(c).

The big guy will take you deep into the embedded system, how to remotely debug the embedded system

From the perspective of embedded system, using this method basically does not add any extra circuit and cost, and still uses the serial port to communicate with the outside like the first method. Although an additional PC is added, for those embedded systems that do not need to use the network during normal work, but only need to use the network to debug and update firmware during testing and debugging, this additional PC Can only be counted as a debugging tool.

In addition, because the control of the power supply and I/O input of the embedded system is added through the network, compared with the second method, even if the embedded system crashes for some reason during debugging, it can still be controlled from the remote end. The power supply can make the system power-on reset; and the control of the system I/O input can better complete the interaction simulation between the simulation system and the outside world.

The work of the whole system consists of two parts: ① the PC-side program that converts the communication protocol between Telnet and the serial port; ② the interface circuit that uses the serial port control line to control the power supply and I/O input of the embedded system.

Second, the design of the interface circuit

The interface circuit is mainly to control the power supply or I/O input of the embedded system by the control lines (such as RTS, CTS, etc.) other than the serial port RXD and TXD. In order to prevent the possible impact of the embedded system on the PC serial port, the circuit shown in Figure 2 is used. The electrical isolation between the PC serial port and the embedded system is achieved by using optocouplers, and the power supplies of different voltages and signals of different levels can be controlled by using relays.

The big guy will take you deep into the embedded system, how to remotely debug the embedded system

Three, Telnet to serial port conversion software

Telnet is a basic network application layer protocol, and its communication protocol is defined by RFC0854. It is a protocol built on top of the TCP protocol for transmitting data and control information. By default, it uses TCP port 23. It was originally designed to establish a network-based serial terminal emulation protocol. This is why serial data can be transmitted using the Telnet protocol.

The data transmitted through Telnet is basically filled into the payload area of ​​the TCP message in the original format (if it is 0xFF data, it is represented by two 0xFFs). For control information (such as the command to switch to binary mode, and our custom command to control power and I/O), it is mixed with ordinary data by adding IAC escape character (0xFF) before the control command. This avoids the necessity of using an extra port to transmit control information like FTP protocol, and reduces the complexity of the program.

The Telnet to serial port protocol conversion program (telnet2com) designed here is actually a Telnet server. It accepts the Telnet link request from the host PC1 client in Figure 1(c), and then sends the data received from the serial port to the PC1 client through the Telnet protocol, and sends the received Telnet data to the serial port at the same time.

In the Windows operating system, most of the servers (such as IIS) exist in the system in the form of Windows NT service components (services). Whether there is a link request on the TCP port). As a service component, it is different from general Windows programs in that it must contain an entry function named NtServiceEntry. When Windows starts to run a service component, this entry function is first run instead of the usual main function.

The big guy will take you deep into the embedded system, how to remotely debug the embedded system

In the entry function, a dispatchTable structure must be defined, including the service name sServiceName and the actual main function ServiceMain of the service, and the registration and operation of the service is actually completed through the StartServiceCtrlDispatcher function. Once a service component is started, in addition to constantly listening to a port, it also needs to respond to different requests from the service manager (such as suspending the service). Therefore, the actual function of the service is designed as a sub-process bridgeThread, which is called by the main process of the service, and the main process of the service is specially used to respond to the request of the service manager.

Figure 3 is the flow of the subprocess bridgeThread. First, use Winsock to listen on a specific port. Then, through the message loop, when the event of the link request is received, the serial port is initialized. After that, the message loop continuously responds to the write request from Telnet and the serial port, and sends the data of Telnet to the serial port until it receives a request from Winsock to disconnect the link.

The big guy will take you deep into the embedded system, how to remotely debug the embedded system

After receiving the data from the Telnet client and sending it to the serial port, you must scan the received data for IAC escape characters. If there are, they must be removed, and the relevant operations must be performed for the defined commands such as control power and I/O. Conversely, before the data received from the serial port is sent to the Telnet client, an additional 0xFF must be added before all 0xFF characters. Below is the code for the scanning process of the data received from Telnet.

The big guy will take you deep into the embedded system, how to remotely debug the embedded system

Here, the Winsock API is mainly used to complete the data reading of the Telnet part; the serial port part is completed by virtualizing the serial port into a file and using the file read and write API. In addition, in order to control other control lines of the serial port, two Windows APIs, GetCommState( ) and SetCommState ( ), are used.

In the experiment, using such a remote debugging system, we have conducted joint debugging with a design center far away in South Korea and downloaded the firmware program of the embedded system. Although it is much slower than the local download speed, it is still better than other methods (such as email + manual download) is more convenient and the results are more intuitive.

Using such a software and hardware system to complete the remote debugging of the embedded system not only saves a lot of manpower and material resources, but also saves the development time. In addition, if it is combined with the supporting test software, it can break through the limitation that a computer has only one or two serial ports, and can only test one embedded system at the same time, so that one host can be connected to many embedded systems at the same time to complete automatic testing. and collaborative testing.

The Links:   6MBI25F-120 PM450CS1H060

micohuang