Design and Implementation of a Network Communication Method Based on an Embedded Debugger
2026-04-06 05:03:40··#1
Abstract: This paper introduces how to perform embedded software debugging via Ethernet port in an embedded debugger, realizing network communication between the host and the development board. For the specific embedded development board S3C4510B, the network port driver and network protocol were studied, and redundant parts of the network port driver and network protocol were removed. This ensures that the debugger can perform remote debugging via Ethernet while meeting the resource requirements of the embedded system. Keywords: Embedded development board; Network protocol; Embedded debugger 0. Introduction With the widespread application of embedded systems, embedded software development has become increasingly important. Embedded software development differs from desktop software development. Its significant characteristic is that the software development debugging process adopts a host/target machine model. The cross-debugger is divided into host and target machine parts, therefore, communication between the host and target machine is required during software debugging. Currently, there are three main communication methods between the host and target machines: serial port, Ethernet interface, and USB interface. Serial communication is simple to implement, stable, and reliable, making it a widely used method. However, serial communication suffers from drawbacks such as slow speed and limited communication distance. Ethernet interface overcomes these shortcomings, providing stable and reliable data transmission, and offering significantly faster and more efficient transmission speeds and distances than serial communication. Network communication protocols are now quite mature. The Internet Engineering Task Force (IETF) and its governing body, the IESG, have clearly defined the specifications for the Internet protocol suite in their RFC documents, which have become a standard widely used in the Internet. This paper discusses how to implement Ethernet interface communication in an embedded debugger based on this specification, presenting a network communication method based on an embedded debugger. 1. Hardware Structure The S3C4510B is a 16/32-bit RISC embedded processor developed by Samsung. The chip integrates a 10Mbps/100Mvps Ethernet controller, and the network interface card (NIC) uses the RTL8201. The Ethernet controller is mainly divided into two parts: the BDMA controller and the MAC sublayer. This controller operates at the MAC layer, is compatible with the IEEE 802.3 protocol standard, supports half-duplex or full-duplex modes, and communicates with the network card chip using a Media Independent Interface (MII). 2. Communication Protocols In embedded debugger communication, the host sends commands to the target machine, the target machine receives and executes the commands, and returns the results to the host. Network communication is primarily for data and string transmission; therefore, IP, ARP, and UDP protocols are mainly used. To debug the target machine over the network, setting the target machine's IP address is essential. Therefore, the target machine also needs to implement the BOOTP protocol to request its own IP address from the host and complete the IP address configuration. BOOTP, or Bootstrap Protocol, is a UDP/IP-based protocol mainly used by the client to obtain its own IP address, the server's IP address, and other configuration information, such as the local subnet mask, from the server. UDP, or User Datagram Protocol, is a simple datagram-oriented transport protocol. Unlike TCP, UDP does not provide reliable mechanisms, flow control, or error recovery functions for the IP protocol, making it simpler to implement and not affecting transmission speed, making it suitable for embedded systems. IP, or Internet Protocol, is the foundation for data transmission over a network. All TCP and UDP data is transmitted in IP datagram format. This protocol provides an efficient but unreliable connectionless transmission method. ARP, or Address Resolution Protocol, provides a mapping between IP addresses and their corresponding physical addresses. 3. Network Communication Program Implementation The specific program implementation mainly includes two parts: the network port driver and the communication protocol. The network port driver initializes the S3C4510B hardware, mainly setting up the Ethernet controller and transmit/receive buffers; the network protocol implementation mainly completes data transmission and reception, ensuring the target board is connected to the Ethernet. The program implementation flowchart is shown in Figure 1. Figure 1 Program Implementation Flowchart 3.1 Network Port Driver Implementation The implementation of the network port driver mainly involves hardware initialization for the specific development board, configuring the hardware operating environment. 3.1.1 Managing the Network Interface Card (NIC) Chip: In the S3C4510 development board, the MAC layer's state management controller reads and sets the NIC's operating status through the MII interface. The physical device address and its internal register address are stored in the Station Management Control and Address Register (STACON), while the data to be set or read is placed in the Station Management Data Register (STADATA). In practical applications, the NIC's MAC address can be read from the ICC EEPROM or set manually, as long as the address is unique within the same local area network. 3.1.2 Initializing the Ethernet Controller: ① Disable MAC and BDMA transmit/receive interrupts to ensure smooth initialization. ② Configure the MAC and BDMA interrupt vector tables. The S3C4510B has 21 interrupt sources, with MAC and BDMA transmit/receive interrupts occupying interrupt numbers 16-19. ③ Set the initial values for the MAC and BDMA controllers, i.e., initialize the BDMA receive/transmit control register and the MAC receive/control register, detailing transmit and receive operations. ④ Configure the Ethernet transmit/receive buffers. The starting addresses of the frame descriptors for transmitted and received frames are stored in registers BDMATXPTR and BDMARXPTR, respectively. During BDMA operation, these are updated to the address of the next frame. The frame descriptor is defined as a structure type, and its members describe the frame information. ⑤ Enable BDMA receive interrupt and MAC transmit interrupt. Clear the corresponding bits in the interrupt mask register INTMSK to respond to BDMA and MAC interrupt requests. 3.1.3 Sending and Receiving Ethernet Data Frames ① Sending Ethernet Data Frames: Call the send function DrvEthWrite(), obtain the send frame address from BDMATXPTR, assign a value to the send frame buffer, and transfer control of the data frame to the BDMA controller. The Ethernet controller automatically adds synchronization bits, delimiter bits, parity bits, and padding fields to the transmitted data and sends the Ethernet frame. ② Receiving Ethernet Data Frames: A BDMA receive interrupt is generated during reception. The interrupt handler function BDMA_Rx_isr() completes the data reception and performs related processing, such as clearing the interrupt flag, checking ownership of the data frame, and obtaining the pointer to the next unprocessed frame structure. The main procedures are as follows: /* Configure physical device */ MIIWrite(0x0, 0x2, 1<<13|1<<8); /* Set physical device status */ status = MIIRead(0x1, 0x0); /* Read physical device status */ /* Configure MAC address */ GetMyMacAddr(): /* Disable transmit and receive interrupts */ Disable_Int(nMAC_RX_INT); Disable_Int(nMAC_TX_INT); Disable_Int(nBDMA_RX_INT); Disable_Int(nBDMA_TX_INT); /* Set MAC transmit interrupt and BDMA receive interrupt vectors */ SetInterrupt(nMAC_TX_INT, MAC_Tx_isr); SetInterrupt(nBDMA_RX_INT, BDMA_Rx_isr); /* Initialize MAC and BDMA controllers */ BDMARXCON = BRxRS; /* Set BDMA receive control register */ BDMATXCON = BTxRS; /* Set BDMA transmit control register */ MACCON = Reset; /* Reset MAC control register */ BDMARXLSZ = MaxRxFrameSize+40; /* Maximum size of received frames */ MACON = gMacCon; /* Set to full-duplex mode */ /* Configure Ethernet transmit and receive buffers */ TxFDInitialize(); RxFDInitialize(); /* Enable BDMA receive interrupt and MAC transmit interrupt */ Enable_Int(nBDMA_RX_INT); Enable_Int(nMAC_TX_INT); 3.2 Communication Protocol Implementation This paper uses structure type to define data structures bootphdr, Udphdr, ip and arphdr, which are used to record various information of BOOTP, UDP, IP and ARP protocol datagram headers respectively. 3.2.1 Configuring the Target Machine's IP Address The target machine first sends a BOOTP request to the host. The host, running the DHCP service, assigns an IP address to the target machine and sends a BOOTP response packet to it. After receiving the response packet, the target machine obtains the IP addresses of the host and itself, as well as other relevant information, according to the protocol format. ① Generating a BOOTP Request. Initialize the values of each structure member in bootphdr. Set the client IP address and host IP address to 0.0.0.0 and 255.255.255.255 respectively. 0.0.0.0 is a valid IP address during system boot. When the target machine does not know the IP address of the destination host, it can use the broadcast address 255.255.255.255 to send the BOOTP request via broadcast. The MAC address has been obtained during initialization and stored in the global variable MyMacSrcAddr. Other member variables can be set according to the protocol format. ② Sending the BOOTP Request. BOOTP requests must be encapsulated in UDP datagrams for transmission. The BOOTP server and client ports use well-known ports 67 and 68, respectively. The UDP checksum is calculated using the function `udpChksum()`. The IP header members are set according to the IP datagram format, with the source and destination IP addresses being 0.0.0.0 and 255.255.255.255, respectively. The IP checksum is calculated using the function `ipChksum()`. The local MAC address is used as the source MAC address, and the broadcast MAC address (0xffffffff) is used as the destination MAC address. These are encapsulated into an Ethernet data frame and sent using the write function `DrvEthWrite()`. The transmit interrupt handler `MAC_Tx_isr()` is called to update the current frame structure descriptor pointer and reset the MAC controller. ③ Receive BOOTP response packets to obtain the host and local IP addresses. BOOTP response packets are received using interrupt mode. The interrupt handler function BDMA_Rx_isr() stores the received packet in the receive frame descriptor RxFDBaseAddr, extracts the valid data and puts it into the BOOTP receive buffer BOOTP_REC_BUF, and resets the corresponding BDMA control register channels and interrupt control bits. ③ It extracts data from BOOTP_REC_BUF according to the protocol's datagram format and records the local and host IP addresses. 3.2.2 Data Transmission and Reception Data transmission and reception mainly involve three important protocols: IP, UDP, and ARP. In the specific implementation, targeted reductions were made according to the characteristics of the embedded system, ensuring the normal operation of the network port while saving embedded system resources. ① When an Ethernet packet arrives, it is first judged. If it is an ARP request, an ARP reply is sent; if it is an ARP reply, the sender's IP address and Ethernet address are recorded; if it is an IP packet, data reception begins. ② Receiving data: When an IP packet arrives, the interrupt handler function puts the packet in the receive frame descriptor RxFDBaseAddr and extracts the IP packet into the receive buffer IP_REC_BUF. Valid data is extracted from IP_REC_BUF and passed to the debugger for processing. ③ Sending data: The data to be sent is encapsulated in UDP datagrams. The target machine IP address and host IP address are recorded in the global variables MyIpAddr and HostIpAddr, respectively. UDP headers and IP headers are added to the data according to the datagram formats of UDP and IP protocols. Using the local MAC address as the source physical address and the host physical address obtained from the ARP reply as the destination address, it is encapsulated into an Ethernet data frame and sent by calling the write function DrvEthWrite(). The interrupt handling function MAC_Tx_isr() handles the transmission interrupt. The main communication procedures are as follows: SendBootpRequest(bootp_id); /* Send a BOOTP request, where bootp_id is a randomly assigned identifier for the request */ /* Wait for the BOOTP response packet */ /* When the BOOTP response packet arrives, extract data from the receive buffer BOOTP_REC_BUF */ memcpy(MyIpAddr, bhdr->your_ip, 4); /* Extract the target board's IP address and store it in the global variable MyIpAddr */ memcpy(HostIpAddr, bhdr->server_ip, 4); /* Extract the host IP address and store it in the global variable HostIpAddr */ /* Check incoming packets */ if (pro_type == ETHERTYPE_IP) IpProcess(IP_REC_BUF); /* Process the incoming IP packet */ if (pro_type == ETHERTYPE_ARP) ArpProcess(IP_REC_BUF, 42); /* Process the incoming ARP packet */ 4. Conclusion The C language program code has been debugged and successfully applied to the embedded debugger. This functional module, designed for a specific development board, features a streamlined network interface driver and protocol stack, eliminating redundant functionalities. This satisfies the resource requirements of the embedded system while ensuring accurate and lossless data transmission. Tests demonstrate that for batch data transmission, the network interface speed is significantly faster than the serial port, effectively achieving debugging communication between the host and target machines, and possessing practical significance. The author's innovation lies in designing and implementing an Ethernet interface communication method for the embedded debugger, streamlining the network interface driver and protocol stack for the specific development board, thus meeting the resource requirements of the embedded system while ensuring efficient data transmission. References: [1] Qiao Rong, Peng Sipeng, Bai Guizhi. Design and implementation of embedded software source code level cross debugger. Ship Electronic Engineering. 2004, 24(3): 56-59. [2] Pang Jiyong, Li Weiying, Wang Jing. Design of network port driver for network communication processor S3C4510B. Microcontroller and Embedded System Application. 2004, (4): 26-28. [3] Hu Debin. Design and implementation of embedded network server based on ucOSⅡ operating system. Microcomputer Information. 2005, 21(8-2): 24-26. [4] Kou Xianghui, Chen Lixue, Tian Jialin. Design and analysis of embedded Ethernet based on S3C44BOX+ucLinux. 2005, (35): [5] Dai Yong, Li Changxi. Data acquisition and processing system based on embedded Ethernet interface. Microcomputer Development. 2005, 15(5): 125-127. [6] ADAM DUNKELS. "uIP-A Free Small TCP/IP Stack". Sweden: Swedish Institute of Computer Science, 2003