How to Build a TCP Server with W5500 on STM32H750?
This project connects an STM32H750 to a WIZnet W5500 to implement an Ethernet TCP server with automatic IP configuration.
How to Build a TCP Server with W5500 on STM32H750?
Summary
This project connects an STM32H750 to a WIZnet W5500 to implement an Ethernet TCP server with automatic IP configuration. It compares two MCU-to-W5500 transfer methods: conventional SPI polling and SPI with DMA. W5500 provides the Ethernet MAC/PHY and hardwired TCP/IP processing, while STM32H750 handles initialization, socket control, DHCP timing, and the application loop. The measured results also show how the MCU-side SPI implementation can significantly affect real application throughput.
What the Project Does
The source project is intended as a fast W5500 bring-up example rather than a detailed driver tutorial. Its stated goal is to configure W5500 as a server, obtain an IP address automatically, and test network communication first with SPI polling and then with SPI+DMA.
The firmware includes the W5500 driver, socket support, DHCP logic, and a TCP demonstration layer:
#include "w5500.h"
#include "W5500_conf.h"
#include "socket.h"
#include "utility.h"
#include "dhcp.h"
#include "tcp_demo.h"
The application flow is straightforward:
STM32H750 initialization → SPI setup → W5500 initialization → DHCP configuration → TCP server loop
The author first tests the system using polling-based SPI and reports an echo-test transfer rate of 35.5 KB/s. The project is then modified to use SPI+DMA. In that configuration, the article reports that receive performance remains relatively slow, while transmission toward the host reaches more than 200 KB/s. These are measurements from this particular implementation, not maximum W5500 throughput figures.
The useful engineering lesson is that the network controller is only one part of the data path. MCU-side SPI handling, buffer movement, polling overhead, and application structure can all limit the observed transfer rate.
Where WIZnet Fits
The W5500 sits between STM32H750 and the Ethernet network.
W5500 integrates a hardwired TCP/IP engine, 10/100 Ethernet MAC and PHY, eight independent hardware sockets, 32 KB of internal TX/RX buffer memory, and an SPI host interface supporting up to 80 MHz. It handles protocols including TCP, UDP, IPv4, ICMP, ARP, IGMP, and PPPoE internally.
The resulting architecture is:
STM32H750 application
→ SPI
→ W5500 socket interface
→ hardwired TCP/IP
→ Ethernet
This means the STM32 application does not need to implement the TCP state machine itself. Instead, it configures W5500, manages socket state, reads or writes socket buffers, and runs the higher-level application.
That division is visible in the source project: after initializing STM32 peripherals, the code performs W5500-specific setup and then repeatedly calls the TCP server routine.
Implementation Notes
W5500 Initialization
File: main.c
The following code is taken directly from the source article:
gpio_for_w5500_config();
reset_w5500();
set_w5500_mac();
socket_buf_init(txsize, rxsize);
IP_AutoSet(3500);
The sequence appears after GPIO, SPI1, TIM6, and USART1 initialization.
Each call has a specific role:
gpio_for_w5500_config() prepares the MCU-side W5500 control signals.
reset_w5500() performs a hardware reset.
set_w5500_mac() configures the Ethernet MAC address.
socket_buf_init() initializes transmit and receive memory allocation for the eight W5500 sockets.
IP_AutoSet(3500) starts the project's automatic network configuration process.
The article also configures a timer callback for DHCP operation, showing that IP assignment requires periodic timing support in addition to the SPI driver.
TCP Server Loop
File: main.c
while (1)
{
do_tcp_server();
}
This is the application's main networking loop.
The MCU repeatedly services the TCP server while W5500 performs the lower-level Ethernet and TCP/IP processing. This separation is one of the practical advantages of using a hardware socket controller.
SPI Polling versus SPI+DMA
The first version communicates with W5500 using polling-based SPI.
The second version keeps the overall application structure but modifies the SPI transfer path to use DMA. According to the article, the DMA version improves the transmit side substantially, increasing host-bound transmission from the initial 35.5 KB/s-class test to more than 200 KB/s, while the receive path remains comparatively slow.
The result suggests that the original limitation was not simply Ethernet link speed. The way bytes are transferred between STM32H750 and W5500 materially affects application throughput.
Practical Tips / Pitfalls
Bring up W5500 with polling before adding DMA. The source project follows this progression, making it easier to separate basic SPI or socket problems from DMA-specific issues.
Treat DMA as a transfer optimization, not a replacement for socket logic. TCP server behavior, DHCP processing, and W5500 socket management still need to run correctly around the DMA transactions.
Check both TX and RX performance. The source shows that improving transmission does not automatically improve reception by the same amount.
Verify GPIO electrical configuration. The author specifically notes using internal pull-ups where the tested board did not provide hardware pull-up resistors.
Tune socket and MCU buffer sizes together. W5500 provides 32 KB of internal TX/RX memory divided among eight sockets, so buffer allocation affects how each connection can absorb network traffic.
Measure complete application throughput. SPI clock alone is not a sufficient performance metric; software loops, memory copies, DMA handling, socket state checks, and peer behavior also affect results.
Keep reset and network recovery explicit. The source performs a hardware reset before W5500 configuration, which provides a deterministic starting state for network initialization.
FAQ
Q: Why does this STM32H750 project use W5500?
W5500 provides the Ethernet MAC/PHY and hardwired TCP/IP engine externally to the MCU. STM32H750 can therefore operate through hardware sockets over SPI instead of implementing TCP, UDP, ARP, and other network protocols in its application firmware. W5500 also provides eight sockets and 32 KB of internal TX/RX memory.
Q: How does W5500 connect to STM32H750?
The project uses SPI with STM32H750 as the host controller. The article first implements normal polling-based SPI and then modifies the same project to use SPI+DMA. W5500 supports SPI Mode 0 and Mode 3 and a maximum SPI clock of 80 MHz.
Q: What role does W5500 play in this project?
It acts as the TCP/IP and Ethernet endpoint for the TCP server. STM32H750 initializes W5500, configures network information and socket buffers, and services the TCP application, while W5500 handles the hardwired Ethernet and TCP/IP functions.
Q: Can beginners reproduce this project?
It is suitable for developers who already understand STM32CubeMX, SPI, GPIO, timers, and basic TCP server behavior. The polling version provides a simpler starting point; DMA adds another layer involving transfer completion and buffer management. The source intentionally focuses on rapid integration rather than explaining the complete W5500 driver.
Q: How is W5500 different from running a software TCP/IP stack on STM32H750?
W5500 executes the supported TCP/IP protocols in dedicated hardware and exposes socket-oriented control through SPI. A software stack such as lwIP executes the network stack on the MCU and provides raw, sequential, or socket APIs. The hardware-offload approach reduces the amount of TCP/IP protocol processing performed by the STM32 application, while a software stack gives the MCU deeper control over the protocol implementation.
Source
Original Project: 10、STM32H750驱动W5500
CSDN, originally published March 16, 2023. The article demonstrates W5500 TCP-server operation on STM32H750 using SPI polling and SPI+DMA, including DHCP-based network configuration and measured echo-test results.
License: CC BY-SA 4.0.
WIZnet Reference: W5500 official documentation covering its hardwired TCP/IP architecture, eight hardware sockets, 32 KB socket memory, integrated 10/100 Ethernet MAC/PHY, and SPI interface.
Tags
#W5500 #STM32H750 #STM32H7 #Ethernet #TCPServer #SPI #DMA #DHCP #EmbeddedNetworking #WIZnet
STM32H750에서 W5500으로 TCP 서버를 구현하는 방법은?
요약
이 프로젝트는 STM32H750과 WIZnet W5500을 연결하여 자동 IP 설정 기능을 갖춘 Ethernet TCP 서버를 구현합니다. MCU와 W5500 사이의 데이터 전송 방식으로 일반적인 SPI Polling 방식과 SPI+DMA 방식을 비교합니다. W5500은 Ethernet MAC/PHY와 하드웨어 TCP/IP 처리를 담당하고, STM32H750은 초기화, Socket 제어, DHCP Timing, Application Loop를 담당합니다. 실제 측정 결과를 통해 MCU 측 SPI 구현 방식이 실제 Application Throughput에 상당한 영향을 줄 수 있다는 점도 확인할 수 있습니다.
프로젝트가 하는 일
원본 프로젝트는 W5500 Driver 자체를 상세하게 설명하기보다는 W5500을 빠르게 동작시키기 위한 실습형 예제입니다. 프로젝트의 주요 목표는 W5500을 TCP Server로 설정하고, Network Configuration을 자동으로 획득하며, 일반 SPI Polling 방식과 SPI+DMA 방식을 각각 테스트하는 것입니다.
Firmware에는 W5500 Driver, Socket 지원, DHCP Logic, TCP Demo Layer가 포함되어 있습니다.
#include "w5500.h"
#include "W5500_conf.h"
#include "socket.h"
#include "utility.h"
#include "dhcp.h"
#include "tcp_demo.h"
전체 Application Flow는 다음과 같습니다.
STM32H750 초기화 → SPI 설정 → W5500 초기화 → DHCP 설정 → TCP Server Loop
작성자는 먼저 Polling 기반 SPI 방식으로 시스템을 테스트하고, Echo Test에서 약 35.5 KB/s의 전송 속도를 보고했습니다.
이후 동일한 프로젝트를 SPI+DMA 방식으로 변경했습니다. 이 구성에서는 수신 성능은 상대적으로 느린 상태를 유지했지만, PC 방향 송신 성능은 200 KB/s 이상까지 증가했다고 설명합니다.
이 수치는 W5500 자체의 최대 성능을 의미하는 것이 아니라 해당 Firmware와 Test Configuration에서 측정된 결과입니다.
이 프로젝트에서 얻을 수 있는 중요한 Engineering Point는 Network Controller만이 전체 성능을 결정하는 것은 아니라는 점입니다.
다음 요소들도 실제 Throughput을 제한할 수 있습니다.
MCU 측 SPI 처리 방식
Buffer 이동
Polling Overhead
Application Loop 구조
Socket 처리 방식
WIZnet이 들어가는 위치
이 프로젝트에서 W5500은 STM32H750과 Ethernet Network 사이에 위치합니다.
W5500은 다음 기능을 통합합니다.
Hardwired TCP/IP Engine
10/100 Ethernet MAC
10/100 Ethernet PHY
8개의 독립 Hardware Socket
총 32 KB의 Internal TX/RX Buffer Memory
최대 80 MHz SPI Host Interface
W5500은 TCP, UDP, IPv4, ICMP, ARP, IGMP, PPPoE 등의 Protocol을 내부 Hardware에서 처리합니다.
따라서 전체 구조는 다음과 같습니다.
STM32H750 Application
→ SPI
→ W5500 Socket Interface
→ Hardwired TCP/IP
→ Ethernet
STM32 Application이 TCP State Machine 자체를 구현할 필요는 없습니다.
대신 MCU는 다음 작업을 수행합니다.
W5500 초기화
Network Information 설정
Socket 상태 관리
Socket TX/RX Buffer 접근
Application Logic 실행
원본 프로젝트에서도 STM32 Peripheral 초기화 이후 W5500 관련 설정을 수행하고, 이후 TCP Server Routine을 반복적으로 호출하는 구조를 사용합니다.
구현 참고 사항
W5500 초기화
File: main.c
원본 프로젝트에 실제로 포함된 초기화 코드는 다음과 같습니다.
gpio_for_w5500_config();
reset_w5500();
set_w5500_mac();
socket_buf_init(txsize, rxsize);
IP_AutoSet(3500);
이 코드는 GPIO, SPI1, TIM6, USART1 초기화 이후 실행됩니다.
각 함수의 역할은 다음과 같습니다.
gpio_for_w5500_config()
MCU 측 W5500 Control Signal을 설정합니다.
reset_w5500()
W5500 Hardware Reset을 수행합니다.
set_w5500_mac()
Ethernet MAC Address를 설정합니다.
socket_buf_init()
W5500의 8개 Socket에 사용할 TX/RX Memory를 구성합니다.
IP_AutoSet(3500)
프로젝트에서 사용하는 자동 Network Configuration을 시작합니다.
원문에서는 DHCP 처리를 위해 Timer Callback도 설정합니다.
즉 DHCP 기반 IP 설정은 단순히 SPI Driver만으로 동작하는 것이 아니라 주기적인 Timing 처리가 필요합니다.
TCP Server Loop
File: main.c
while (1)
{
do_tcp_server();
}
이 부분이 Application의 Main Network Loop입니다.
STM32는 지속적으로 TCP Server를 Service하고, W5500은 실제 Ethernet 및 TCP/IP Processing을 수행합니다.
이 구조가 Hardware Socket Controller를 사용하는 핵심적인 특징입니다.
SPI Polling과 SPI+DMA 비교
첫 번째 구현에서는 Polling 기반 SPI를 사용합니다.
두 번째 구현에서는 전체 Application 구조를 유지하면서 SPI Transfer 부분을 DMA 방식으로 변경합니다.
원문에 따르면 DMA 방식으로 변경한 후 송신 측 성능이 크게 향상되었습니다.
초기 약 35.5 KB/s 수준의 Test와 비교해 PC 방향 Transmission은 200 KB/s 이상으로 증가했습니다.
반면 Receive Path는 여전히 상대적으로 느렸습니다.
이 결과는 병목이 단순히 Ethernet Link Speed 때문이 아니라 STM32H750과 W5500 사이에서 Byte를 이동하는 방식에도 영향을 받는다는 점을 보여줍니다.
실무 팁 / 주의점
처음에는 Polling 방식으로 W5500을 Bring-up하는 것이 좋습니다. 원본 프로젝트도 이 순서를 사용하며, 기본 SPI 또는 Socket 문제와 DMA 문제를 분리해서 Debug할 수 있습니다.
DMA는 Socket Logic을 대체하는 기능이 아닙니다. TCP Server, DHCP, W5500 Socket State Management는 DMA Transfer와 별도로 정상적으로 동작해야 합니다.
TX와 RX 성능을 각각 측정해야 합니다. 원본 프로젝트에서도 Transmission은 크게 개선되었지만 Reception은 같은 비율로 개선되지 않았습니다.
GPIO Electrical Configuration을 확인해야 합니다. 작성자는 Test Board에 External Pull-up이 없는 부분에서 Internal Pull-up을 사용했다고 설명합니다.
Socket Buffer와 MCU Buffer를 함께 조정해야 합니다. W5500은 총 32 KB의 TX/RX Memory를 8개 Socket 사이에서 나누어 사용합니다.
전체 Application Throughput을 측정해야 합니다. SPI Clock만으로 Network Performance를 판단할 수 없습니다. Memory Copy, DMA Handling, Socket State Check, Application Loop, Peer Behavior도 영향을 줍니다.
Reset과 Network Recovery를 명확하게 구현하는 것이 좋습니다. 원본 프로젝트처럼 Configuration 전에 Hardware Reset을 수행하면 Network Controller를 항상 일정한 상태에서 초기화할 수 있습니다.
FAQ
Q: 이 STM32H750 프로젝트에서 왜 W5500을 사용하나요?
W5500은 Ethernet MAC/PHY와 Hardwired TCP/IP Engine을 MCU 외부에 제공합니다. 따라서 STM32H750은 TCP, UDP, ARP 등의 Network Protocol을 Application Firmware에서 직접 구현하지 않고 SPI를 통해 Hardware Socket을 제어할 수 있습니다. W5500은 8개의 Hardware Socket과 총 32 KB의 TX/RX Memory를 제공합니다.
Q: W5500은 STM32H750과 어떻게 연결되나요?
이 프로젝트에서는 SPI를 사용합니다. STM32H750이 Host 역할을 하며, 첫 번째 구현에서는 일반 Polling 기반 SPI를 사용하고 이후 SPI+DMA 방식으로 변경합니다. W5500은 SPI Mode 0과 Mode 3을 지원하며 최대 80 MHz SPI Clock을 지원합니다.
Q: 이 프로젝트에서 W5500은 어떤 역할을 하나요?
W5500은 TCP Server의 TCP/IP 및 Ethernet Endpoint 역할을 합니다. STM32H750은 W5500을 초기화하고 Network Information과 Socket Buffer를 설정하며 TCP Application을 실행합니다. 실제 Ethernet 및 TCP/IP Protocol Processing은 W5500이 담당합니다.
Q: 초보자도 이 프로젝트를 따라할 수 있나요?
STM32CubeMX, SPI, GPIO, Timer, 기본 TCP Server 동작을 이해하고 있는 개발자에게 적합합니다. Polling 방식부터 시작하면 비교적 단순하게 접근할 수 있으며, DMA 버전에서는 Transfer Completion과 Buffer Management에 대한 추가 이해가 필요합니다. 원본 자료는 전체 W5500 Driver를 처음부터 설명하기보다 빠른 Integration을 목표로 합니다.
Q: W5500과 STM32H750에서 Software TCP/IP Stack을 사용하는 방식은 어떻게 다른가요?
W5500은 지원하는 TCP/IP Protocol을 전용 Hardware에서 실행하고 SPI를 통해 Socket Interface를 제공합니다. 반면 lwIP와 같은 Software Stack은 MCU에서 TCP/IP Processing을 실행합니다. W5500 방식은 STM32 Application이 수행해야 하는 TCP/IP Protocol Processing을 줄여주고, Software Stack은 Network Protocol 동작을 MCU Software에서 더 세밀하게 제어할 수 있습니다.
출처
Original Project: 10、STM32H750驱动W5500
2023년 3월 16일 공개된 CSDN 프로젝트로, STM32H750에서 W5500 TCP Server를 구현하고 SPI Polling과 SPI+DMA 방식, DHCP 기반 Network Configuration, Echo Test 결과를 다룹니다.
License: CC BY-SA 4.0
WIZnet Reference: W5500 공식 문서
W5500의 Hardwired TCP/IP Architecture, 8개의 Hardware Socket, 32 KB Socket Memory, Integrated 10/100 Ethernet MAC/PHY, SPI Interface 관련 정보를 제공합니다.
태그
#W5500 #STM32H750 #STM32H7 #Ethernet #TCPServer #SPI #DMA #DHCP #EmbeddedNetworking #WIZnet
