Wiznet makers

sophia

Published May 29, 2025 ©

6 UCC

1 VAR

0 Contests

0 Followers

0 Following

Original Link

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.

COMPONENTS Hardware components

STM - STM32F407

x 1


WIZnet - W5500

x 1

Software Apps and online services

ARM - KEIL5

x 1


PROJECT DESCRIPTION

📎 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 W5500

IDE: 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

ModeDescription
TCP ServerListens on port 8080, echoes client data
TCP ClientConnects to a remote server, sends + receives
UDPReceives 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

📘 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...)

 

 

Documents
Comments Write