FPGA Tutorial Ethernet 1: Simple TCP Server
Last updated
Last updated
Ethernet is a widely used networking technology that facilitates communication over local area networks (LANs). It operates using a protocol to manage how data packets are transmitted over physical cables, typically twisted pair cables or fiber optics, within a specific geographical area. Ethernet protocols also define how data collisions are handled, ensuring that the network runs smoothly even when multiple devices attempt to send data simultaneously.
The Zynq FPGA (Field-Programmable Gate Array) is a family of programmable devices from Xilinx that combines a traditional FPGA with a powerful ARM-based processing system on a single chip. This hybrid architecture allows for high-performance parallel processing through the FPGA’s configurable logic, while the ARM processors handle complex software tasks, enabling efficient processing of both hardware and software components.
Ethernet in the Zynq FPGA with Linux simplifies the process of connecting embedded systems to networks by leveraging the power of the ARM processor and the flexibility of the FPGA, all while utilizing the standard Ethernet driver support available in Linux. With this combination, users can easily interface with Ethernet without worrying about low-level driver development, as Linux provides built-in support for Ethernet controllers, including the ones on the Zynq platform. This enables developers to quickly configure and use Ethernet for network communication, such as TCP/IP or UDP, directly from user-space applications.
The Linux kernel includes support for a wide variety of Ethernet chipsets, with many network drivers available to support different Ethernet hardware. These drivers are typically developed and maintained by both the open-source community and hardware manufacturers, enabling Linux to work with a broad spectrum of network devices.
PYNQ (Python for Zynq) is an open-source framework developed by Xilinx (now part of AMD) to simplify the use of Zynq-based systems for data processing, machine learning, and embedded computing. PYNQ allows users to access and control (The Python is not used to design the RTL) the programmable logic (FPGA) on Zynq devices using high-level Python programming.
PYNQ comes with a pre-built Linux OS image that is specifically designed for Zynq-based platforms (like the ZCU104, ZCU111, and PYNQ-Z1 boards). This image is a customized version of Ubuntu Linux, which includes the necessary drivers, libraries, and tools to interact with both the ARM processor and the FPGA fabric of the Zynq device.
Many FPGA boards support PYNQ, making it easier to work with Zynq-based devices and accelerate applications through high-level Python programming. PYNQ is primarily designed for Xilinx Zynq-based systems.
Check this link for the full list of supported FPGAs for the PYNQ framework. Other than the FPGA listed on the website, there may be other FPGAs that are unofficially supported. For example:
Assuming you already have an FPGA board that is already able to boot PYNQ Linux. Then, you can connect the board to the host PC via USB serial to display the Linux console. To do that, you can use the serial terminal program. I use the MobaXTerm program. Why? because it has many features, not only serial but also SSH, FTP, and a text editor, all in one program that later will also be used.
Connect the USB cable to your board, then turn on the board to boot into Linux.
From MobaXTerm, go to Session and create Serial session.
Select the COM port according to your board. Configure the baud rate to 115200.
After it is connected, you can try any Linux command, for example, ifconfig
. The default IP address for my board is 192.168.2.99
.
Plug an Ethernet cable into your board and your host PC. It can be a direct connection or via a router.
Configure your host PC's Ethernet IP address to 192.168.2.1
. Then, you can ping from the host PC to your board.
You can also login to the board via Ethernet connection (SSH). To do that, you can use the SSH session in MobaXTerm. With an Ethernet connection, you can transfer files between the host PC and the board.
From MobaXTerm, go to Session and create SSH session.
Enter the IP address of your board and username: xilinx.
So, in this example, we are going to create a simple TCP server. Here is the block diagram of the system. The complete communication system consists of an FPGA board and a PC connected with an Ethernet cable. The TCP server runs on the board, while the TCP client runs on the PC. The TCP client on the PC can send data to the server, and the server will send back the data to the client.
On the Zynq FPGA platform, the Ethernet port is typically connected to the ARM Processing System (PS). The Ethernet MAC are built into the PS part. The PHY is a separate chip outside the Zynq chip. When running Linux, the TCP/IP stack is typically handled by the Linux kernel. Linux includes a full-featured, well-established TCP/IP stack that is widely used for network communication, including Ethernet.
The TCP server is coded in Python using the socket and threading libraries. Here is the code.
You can create Python code through the MobaXTerm SSH connection, then run it from the command line. Then, we can connect to the server from the PC client using a TCP client program, such as Hercules.
In this tutorial, we have learned how to use Ethernet on a Zynq FPGA running PYNQ. The PHY chip is off-chip, and the MAC is in the PS of the Zynq chip. The TCP/IP stack is in the Linux kernel. In the user space, we use the Python socket library for TCP communication. A simple test is performed from a laptop acting as the TCP client, sending the text "Hello." The text is received by the board and sent back to the laptop.