📈
Ween's Lab
UdemyYouTubeTikTok
  • Welcome
  • 📻FPGA Tutorials
    • FPGA Boards: Getting Started
      • Getting Started with PYNQ on Kria KV260 Vision AI Starter Kit
      • Getting Started with PYNQ on Red Pitaya STEMlab 125-14
      • Getting Started with PYNQ on ZYBO
    • FPGA Ethernet Tutorial
      • FPGA Tutorial Ethernet 1: Simple TCP Server
    • PYNQ FPGA Tutorial 101
      • Part 0: Introduction
      • Part 1: GPIO
      • Part 2: Custom IP
      • Part 3: Memory
      • Part 4: ANN Processor
    • PYNQ FPGA Tutorial 102
      • Part 0: Introduction
      • Part 1: Memory Mapped
      • Part 2: Direct Memory Access
      • Part 3: AXI-Lite Multiplier
      • Part 4: AXI-Stream Multiplier with DMA
      • Part 5: AXI-Lite GCD
      • Part 6: AXI-Stream GCD with DMA
      • Part 7: Access to DDR from PL
    • ZYNQ FPGA Tutorial
      • Part 1: Gate-Level Combinational Circuit
      • Part 2: RT-Level Combinational Circuit
      • Part 3: Regular Sequential Circuit
      • Part 4: FSM Sequential Circuit
      • Part 5: ZYNQ Architecture
      • Part 6: ARM CPU and FPGA Module
      • Part 7: FPGA Memory
      • Part 8: Hardware Accelerator for Neural Networks
    • ZYNQ FPGA Linux Kernel Module
      • Cross Compiling Kernel, Kernel Module, and User Program for PYNQ
      • Configure PL to PS Interrupt in Kernel Module
      • Configure AXI DMA in Kernel Module
  • 📟Proyek Arduino
    • Kumpulan Proyek
      • Rangkaian LED
      • LED Berkedip Nyala Api
      • LED Chaser
      • LED Binary Counter
      • OLED 128x4 Bitcoin Ticker
      • Rangkaian Button
      • Button Multifungsi
      • Button Interrupt
      • Button Debouncing
    • Pelatihan Mikrokontroler Arduino ESP32
      • Bab 1 Pengenalan Mikrokontroler
      • Bab 2 Pengenalan Arduino
      • Bab 3 Pengenalan Bahasa C
      • Bab 4 Digital Output
      • Bab 5 Digital Input
      • Bab 6 Serial Communication
      • Bab 7 Analog-to-Digital Conversion
      • Bab 8 Interrupt
      • Bab 9 Timer
      • Bab 10 Pulse-Width Modulation
      • Bab 11 SPI Communication
      • Bab 12 I2C Communication
  • 💰Finance
    • Coding for Finance
      • Build a Bitcoin Price Alert with Google Cloud and Telegram
      • Build a Bitcoin Ticker with ESP32 and Arduino
      • Stock Price Forecasting with LSTM
    • Trading dan Investasi
      • Istilah Ekonomi, Keuangan, Bisnis, Trading, dan Investasi
      • Jalan Menuju Financial Abundance
      • Memahami Korelasi Emas, Oil, Dollar, BTC, Bonds, dan Saham
      • Mindset Trading dan Investasi
      • Rangkuman Buku: Rahasia Analisis Fundamental Saham
      • Rangkuman Buku: The Psychology of Money
      • Rangkuman Kuliah: Introduction to Adaptive Markets
      • Rumus Menjadi Orang Kaya
  • 📝Life
    • Life Quotes
Powered by GitBook
On this page
  • What is Ethernet
  • Zynq FPGA
  • Advantage of Zynq FPGA for Ethernet
  • PYNQ Framework
  • Booting PYNQ FPGA
  • Login to Board via Serial COM port
  • Login to Board via Ethernet (SSH)
  • Simple TCP Server
  • Conclusion
  1. FPGA Tutorials
  2. FPGA Ethernet Tutorial

FPGA Tutorial Ethernet 1: Simple TCP Server

PreviousFPGA Ethernet TutorialNextPYNQ FPGA Tutorial 101

Last updated 2 months ago

What is 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.

Zynq FPGA

Advantage of Zynq FPGA for Ethernet

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.

PYNQ Framework

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.

Booting PYNQ FPGA

Login to Board via Serial COM port

  • 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.

Login to Board via Ethernet (SSH)

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.

Simple TCP Server

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.

import socket
import threading

# Function to handle client connection
def handle_client(client_socket):
    try:
        while True:
            # Receive message from client
            message = client_socket.recv(1024)
            if not message:
                break
            print(f"{message.decode('utf-8')}")
            
            # Echo the message back to the client
            client_socket.send(message)
    except Exception as e:
        print(f"Error handling client: {e}")
    finally:
        # Close the connection
        client_socket.close()

# Function to start the server
def start_server(host, port):
    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    
    # Enable reuse of the address/port
    server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

    server.bind((host, port))
    server.listen(5)
    print(f"Server listening on {host}:{port}")
    
    while True:
        # Accept new connections
        client_socket, client_address = server.accept()
        print(f"Connection from {client_address}")
        
        # Start a new thread to handle the client
        client_thread = threading.Thread(target=handle_client, args=(client_socket,))
        client_thread.start()

if __name__ == "__main__":
    host = '192.168.2.99'
    port = 5000
    
    start_server(host, port)

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.

Conclusion

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.

The (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.

The Linux kernel includes support for a wide variety of , 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.

(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.

Check this 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 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.

📻
Zynq FPGA
Ethernet chipsets
PYNQ
link
ZyBo
Red Pitaya
MobaXTerm
Ethernet
Ethernet port and cable
Zynq FPGA block diagram
Ethernet drivers in the Linux source code
PYNQ framework stack
Create new Serial session
Check IP address of the board
Ping from host PC to the board
Create new SSH session
System block diagram
Hardware-software block diagram
Simple TCP server
fpga-tutorial-ethernet-1-ethernet-cable
fpga-tutorial-ethernet-1-zynq-block
fpga-tutorial-ethernet-1-ethernet-driver-linux
fpga-tutorial-ethernet-1-pynq-stack
fpga-tutorial-ethernet-1-mobaxterm-serial-session
fpga-tutorial-ethernet-1-mobaxterm-serial-ip
fpga-tutorial-ethernet-1-ping-zybo-pynq
fpga-tutorial-ethernet-1-mobaxterm-ssh-session
fpga-tutorial-ethernet-1-system-block
fpga-tutorial-ethernet-1-hardware-software-block
fpga-tutorial-ethernet-1-simple-tcp-server