---
title: "Porting W5500 on STM32 with TCP/UDP/Web Server Support"
url: "https://maker.wiznet.io/sophia/projects/porting-w5500-on-stm32-with-tcp-udp-web-server-support/"
markdown_url: "https://maker.wiznet.io/sophia/projects/porting-w5500-on-stm32-with-tcp-udp-web-server-support/md"
type: "UCC: User Created Content"
author: "星光映梦 (Starlight Dreams)"
author_url: "https://www.cnblogs.com/star-light-glimmer/p/18802872"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "星光映梦 (Starlight Dreams)"
original_url: "https://www.cnblogs.com/star-light-glimmer/p/18802872"
published: "2025-05-29"
language: "en"
hardware: ["STMicroelectronics STM32F407", "WIZnet W5500"]
likes: 0
views: 4065
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Porting W5500 on STM32 with TCP/UDP/Web Server Support

> Ported W5500 on STM32 via SPI. Supports DHCP, TCP/UDP, and a basic web server. Ideal for IoT networking and protocol testing.

Original author: 星光映梦 (Starlight Dreams) (source: https://www.cnblogs.com/star-light-glimmer/p/18802872)

## Components

- **STMicroelectronics STM32F407** x 1
- **WIZnet W5500** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5500))
- Software: **ARM KEIL5** ([docs](https://www2.keil.com/mdk5))

WIZnet parts: W5500 ([Datasheet](https://docs.wiznet.io/Product/Chip/Ethernet/W5500/datasheet?utm_source=maker&utm_medium=project&utm_campaign=w5500), [product hub](https://maker.wiznet.io/products/w5500/))

## Article

## 📎 Introduction

This project demonstrates how to port the WIZnet **W5500** Ethernet controller to an **STM32 MCU** using **SPI**, and implements a full set of features including:

DHCP and static IP configuration

TCP Server / Client communication

UDP data transmission

Embedded **HTTP Web Server** (controlling a GPIO-LED via browser)

The project uses the **WIZnet official ioLibrary** and is suitable for embedded developers looking to learn real-world network stack implementation with W5500.

### 🔧 Hardware & Software Used

**MCU**: STM32F407 series

**Ethernet Chip**: WIZnet **W5500IDE**: STM32CubeMX + Keil MDK5 / STM32 HAL

**Protocols**: SPI, DHCP, TCP, UDP, HTTP

**Libraries**: WIZnet ioLibrary (socket.c/h, wizchip_conf.c/h, w5500.c/h)

**Interface**: SPI (up to 80MHz)

**Additional**: UART, Timer, GPIO, LED

## 📁 Software Structure

### Libraries Imported:

`wizchip_conf.c/h`

`socket.c/h`

`w5500.c/h`

`DHCP.c/h`

`httpServer.c/h`

### Key Files:

`main.c` – System init, DHCP config, TCP/UDP/WebServer loop

`W5500_Init()` – SPI + GPIO init, Registering callback functions

`PrintInfo()` – Real-time IP/MAC info display

`W5500_TCP_Server()/Client()` – TCP communication handlers

`W5500_UDP()` – Lightweight data echo

`W5500_WebServer_Init()/Start()` – Custom HTML control via GET parameters

## 🌐 Network Initialization Logic

**DHCP support** using `DHCP_run()` with retry logic

**Manual static IP** fallback when DHCP fails

Registers used: `setSHAR`, `setSIPR`, `setSUBR`, `setGAR`, `ctlnetwork()`

DHCP callback optional: `reg_dhcp_cbfunc()`

## 📡 TCP / UDP Communication

| Mode | Description |
| --- | --- |
| **TCP Server** | Listens on port 8080, echoes client data |
| **TCP Client** | Connects to a remote server, sends + receives |
| **UDP** | Receives data from any IP/port and echoes it back |

Socket state machines are managed using `getSn_SR()`

`SOCK_CLOSED`, `SOCK_INIT`, `SOCK_ESTABLISHED`, etc.

## 🌍 Embedded Web Server (HTTP)

Supports **GET** requests via browser

Parses `?action=1` and `?action=2` to **turn on/off LED**

HTML file is embedded as a C string and served dynamically

Based on `httpServer_run()` from WIZnet's library

## 🧠 What You Will Learn

How to port and configure WIZnet W5500 in STM32 environment

Practical implementation of DHCP and IP networking

TCP/UDP communication from scratch using low-level socket API

How to build a minimal web server for embedded control

Integration of SPI communication with network stack

## 📦 Resources

📁 [ioLibrary GitHub](https://github.com/Wiznet/ioLibrary_Driver)

📘 W5500 Datasheet

🔗 STM32Cube HAL Reference

## 🧩 Target Audience

Embedded system engineers

IoT developers working with Ethernet

Students learning STM32 and network basics

Makers building smart home or data logger devices

## 📌 Tips

Ensure MAC and IP are unique in LAN environment

Use **socket timeout/retry** logic for robust behavior

Run the WebServer and TCP echo simultaneously by assigning multiple socket indices (0, 1, 2...)

---

Source: https://maker.wiznet.io/sophia/projects/porting-w5500-on-stm32-with-tcp-udp-web-server-support/
