How to Build a Static-IP TCP Server with W5500 on STC32G12K128?
This STC32G12K128 project uses the WIZnet W5500 Ethernet controller to expose a small local TCP server that can be accessed from a web browser.
How to Build a Static-IP TCP Server with W5500 on STC32G12K128?
Summary
This STC32G12K128 project uses the WIZnet W5500 Ethernet controller to expose a small local TCP server that can be accessed from a web browser. The MCU controls W5500 through software SPI and GPIO, while W5500 provides the wired Ethernet interface, hardware TCP/IP stack, socket engine, and buffering needed to receive a browser HTTP GET request and return HTML content.
What the Project Does
The project shows how an STC32G12K128-based board can behave like a small local web server. The article compares the idea to a router’s local administration page: a user enters the device’s local IP address and port in a browser, the browser sends an HTTP GET request, and the MCU returns HTML content to be rendered by the browser. The article explicitly states that one W5500 socket is configured as the server and that a static IP address is used.
The accessible part of the article begins a do_tcp_server() function and describes it as a TCP server loopback demonstration, but the full implementation is behind a CSDN paid-column gate. Because of that, the verified architecture is clear, but the complete socket-state code cannot be quoted from the public page.
Where WIZnet Fits
The WIZnet product used is W5500. In this design, W5500 sits between the STC32G12K128 firmware and the wired Ethernet network. The MCU handles software SPI, reset control, interrupt input, static network configuration, and application-level HTML response logic. W5500 handles the Ethernet MAC/PHY, TCP/IP processing, socket interface, and packet buffering.
This is a practical fit for Industrial IoT because many local device-configuration pages do not need a full Linux web stack. A small MCU can expose a maintenance page, status page, commissioning page, or local parameter interface through a deterministic wired Ethernet link. W5500 provides an integrated TCP/IP stack, SPI host interface up to 80 MHz, 10/100 Ethernet MAC/PHY, 8 sockets, and internal Tx/Rx buffer memory, which reduces the amount of network-stack firmware that must run on the STC32G12K128.
Implementation Notes
The public article does not expose the complete TCP server source, so this section uses a verified architecture explanation rather than hidden code. The confirmed flow is:
- Configure the STC32G12K128 GPIO pins used for W5500 software SPI, reset, interrupt, and chip select.
- Reset W5500 and verify basic register access.
- Apply a static IP address to W5500.
- Open one W5500 socket in TCP server mode.
- Listen on the configured local port.
- Wait for a browser connection.
- Receive the browser’s HTTP
GETrequest. - Send an HTTP response containing HTML content.
- Close or recycle the socket after the browser transaction completes.
Conceptual integration example based on WIZnet ioLibrary
// Conceptual only: the public CSDN page does not expose the full source.
void tcp_web_server_loop(uint8_t sn, uint16_t port, uint8_t *buf)
{
switch (getSn_SR(sn)) {
case SOCK_CLOSED:
socket(sn, Sn_MR_TCP, port, 0);
break;
case SOCK_INIT:
listen(sn);
break;
case SOCK_ESTABLISHED:
if (getSn_RX_RSR(sn) > 0) {
recv(sn, buf, 2048);
send(sn, (uint8_t *)
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/html\r\n\r\n"
"<html><body><h1>W5500 Local Server</h1></body></html>",
105);
}
break;
case SOCK_CLOSE_WAIT:
disconnect(sn);
break;
}
}This example reflects the architecture described by the article: one W5500 socket acts as a TCP server, the browser sends a GET request to the device’s static IP and port, and the MCU returns HTML. It should not be treated as copied source code from the gated article.
Practical Tips / Pitfalls
- Use a fixed static IP only inside a controlled LAN plan. In Industrial IoT deployments, document the subnet, gateway, and reserved address range to avoid duplicate IP conflicts.
- Verify software SPI before debugging the browser flow. If W5500 register reads are unreliable, HTTP symptoms will be misleading.
- Keep the first HTML response small. W5500 has internal socket buffers, but small responses are easier to validate during bring-up.
- Send a valid HTTP header before the HTML body. Many browsers tolerate minimal responses, but deterministic testing is easier with
HTTP/1.1 200 OKandContent-Type: text/html. - Treat the browser as a TCP client, not just an HTTP viewer. The embedded server must handle connection open, receive, send, and close states correctly.
- Add authentication or physical network isolation before using this pattern for real equipment configuration. A local web page on an industrial LAN can become a control surface.
- Include link-loss and socket-recovery logic. A production device should recover if the Ethernet cable is unplugged, the switch reboots, or the browser closes the connection mid-transfer.
FAQ
Q: Why use W5500 for a local TCP server on STC32G12K128?
A: W5500 provides a hardware TCP/IP socket interface over SPI, so the STC32G12K128 does not need to implement the full Ethernet, IP, and TCP stack in firmware. That makes it practical to build a small local configuration server on a constrained MCU.
Q: How does W5500 connect to the STC32G12K128 in this project?
A: The previous article in the same STC32G12K128 series confirms that this W5500 setup uses software SPI and GPIO-level reset/interrupt control. For this TCP server article, the browser-facing behavior is built on top of that W5500 interface.
Q: What role does W5500 play in the browser HTTP GET flow?
A: W5500 owns the TCP socket used by the local server. The browser connects to the W5500-backed IP address and port, sends an HTTP GET request, and the STC32 application sends HTML back through the W5500 socket.
Q: Can beginners follow this project?
A: It is approachable for developers who already understand GPIO, software SPI, IP addressing, TCP server states, and basic HTTP. The browser test is easy to observe, but the socket-state handling still needs careful debugging.
Q: Why is there no comparison section?
A: The requested scope is focused on W5500, not alternative network chips or wireless modules. The main engineering point is how W5500 allows a small STC32G12K128 device to host a local browser-accessible TCP server through a static-IP Ethernet socket.
Source
Original article: CSDN, “<STC32G12K128入门第十四步>STC32G+TCP_Server进行浏览器访问本地服务器.” The public page verifies the static-IP local server concept, W5500 socket-as-server model, browser GET request flow, and HTML response concept. Full code access is gated.
Product reference: WIZnet W5500 official product page for integrated TCP/IP stack, SPI interface, Ethernet MAC/PHY, sockets, and buffer features.
License: not clearly visible in the accessible public article text.
Tags
#W5500 #WIZnet #STC32G12K128 #STC32 #TCPServer #SoftwareSPI #StaticIP #LocalWebServer #EmbeddedEthernet #IndustrialIoT #HTTP #GPIO
STC32G12K128에서 W5500으로 정적 IP TCP 서버를 구축하는 방법
요약
이 STC32G12K128 프로젝트는 WIZnet W5500 이더넷 컨트롤러를 사용해 웹 브라우저에서 접속 가능한 소형 로컬 TCP 서버를 구현합니다. MCU는 소프트웨어 SPI와 GPIO로 W5500을 제어하고, W5500은 브라우저의 HTTP GET 요청을 수신하고 HTML 콘텐츠를 반환하는 데 필요한 유선 이더넷 인터페이스, 하드웨어 TCP/IP 스택, 소켓 엔진, 버퍼 역할을 담당합니다.
프로젝트가 하는 일
이 프로젝트는 STC32G12K128 기반 보드가 작은 로컬 웹 서버처럼 동작하는 방법을 보여줍니다. 원문은 이 구조를 공유기 내부 관리 페이지와 비교합니다. 사용자가 브라우저에 장치의 로컬 IP 주소와 포트 번호를 입력하면, 브라우저가 HTTP GET 요청을 보내고, MCU가 HTML 코드를 반환해 브라우저에 페이지가 표시되는 방식입니다. 원문은 W5500의 소켓 하나를 서버로 설정하고 정적 IP를 사용한다고 설명합니다.
공개된 원문은 do_tcp_server() 함수의 시작부와 TCP 서버 loopback 데모 설명까지만 보여주며, 전체 구현은 CSDN 유료 칼럼 뒤에 있습니다. 따라서 검증 가능한 구조는 명확하지만, 전체 소켓 상태 코드는 공개 페이지에서 인용할 수 없습니다.
WIZnet이 들어가는 위치
이 프로젝트에서 사용된 WIZnet 제품은 W5500입니다. 이 설계에서 W5500은 STC32G12K128 펌웨어와 유선 이더넷 네트워크 사이에 위치합니다. MCU는 소프트웨어 SPI, reset 제어, interrupt 입력, 정적 네트워크 설정, 애플리케이션 수준의 HTML 응답 로직을 담당합니다. W5500은 Ethernet MAC/PHY, TCP/IP 처리, 소켓 인터페이스, 패킷 버퍼링을 담당합니다.
이 구조는 Industrial IoT에 실용적입니다. 많은 로컬 장치 설정 페이지는 Linux 기반 웹 서버 전체를 필요로 하지 않습니다. 소형 MCU만으로 유지보수 페이지, 상태 페이지, 시운전 페이지, 로컬 파라미터 설정 화면을 결정적인 유선 이더넷 링크로 제공할 수 있습니다. W5500은 통합 TCP/IP 스택, 최대 80 MHz SPI 호스트 인터페이스, 10/100 Ethernet MAC/PHY, 8개 소켓, 내부 Tx/Rx 버퍼 메모리를 제공하므로 STC32G12K128에서 직접 운용해야 하는 네트워크 스택 펌웨어 부담을 줄여줍니다.
구현 참고 사항
공개 원문은 전체 TCP 서버 소스를 노출하지 않으므로, 이 섹션은 숨겨진 코드를 재구성하지 않고 검증된 구조 설명을 기준으로 합니다. 확인 가능한 흐름은 다음과 같습니다.
- W5500 소프트웨어 SPI, reset, interrupt, chip select에 사용할 STC32G12K128 GPIO를 설정합니다.
- W5500을 reset하고 기본 레지스터 접근을 확인합니다.
- W5500에 정적 IP 주소를 적용합니다.
- W5500 소켓 하나를 TCP 서버 모드로 엽니다.
- 설정된 로컬 포트에서 listen 상태로 대기합니다.
- 브라우저 연결을 기다립니다.
- 브라우저의 HTTP
GET요청을 수신합니다. - HTML 콘텐츠가 포함된 HTTP 응답을 전송합니다.
- 브라우저 트랜잭션이 끝나면 소켓을 닫거나 재사용합니다.
WIZnet ioLibrary 기반 개념적 통합 예시
// Conceptual only: the public CSDN page does not expose the full source.
void tcp_web_server_loop(uint8_t sn, uint16_t port, uint8_t *buf)
{
switch (getSn_SR(sn)) {
case SOCK_CLOSED:
socket(sn, Sn_MR_TCP, port, 0);
break;
case SOCK_INIT:
listen(sn);
break;
case SOCK_ESTABLISHED:
if (getSn_RX_RSR(sn) > 0) {
recv(sn, buf, 2048);
send(sn, (uint8_t *)
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/html\r\n\r\n"
"<html><body><h1>W5500 Local Server</h1></body></html>",
105);
}
break;
case SOCK_CLOSE_WAIT:
disconnect(sn);
break;
}
}이 예시는 원문이 설명한 구조를 반영합니다. W5500 소켓 하나가 TCP 서버로 동작하고, 브라우저가 장치의 정적 IP와 포트로 GET 요청을 보내며, MCU가 W5500 소켓을 통해 HTML을 반환합니다. 이 코드는 유료 영역의 원문 소스에서 복사한 코드가 아닙니다.
실전 팁과 주의할 점
- 정적 IP는 관리되는 LAN 계획 안에서만 사용해야 합니다. Industrial IoT 배포에서는 서브넷, 게이트웨이, 예약 주소 범위를 문서화해 IP 충돌을 피해야 합니다.
- 브라우저 흐름을 디버깅하기 전에 소프트웨어 SPI를 먼저 검증해야 합니다. W5500 레지스터 읽기가 불안정하면 HTTP 증상은 모두 잘못 해석될 수 있습니다.
- 첫 HTML 응답은 작게 유지하는 것이 좋습니다. W5500에는 내부 소켓 버퍼가 있지만, bring-up 단계에서는 작은 응답이 검증하기 쉽습니다.
- HTML 본문 앞에 유효한 HTTP 헤더를 보내야 합니다. 많은 브라우저가 최소 응답을 허용하지만, 결정적인 테스트를 위해서는
HTTP/1.1 200 OK와Content-Type: text/html을 포함하는 편이 좋습니다. - 브라우저를 단순한 화면 출력기가 아니라 TCP 클라이언트로 취급해야 합니다. 임베디드 서버는 연결 open, receive, send, close 상태를 올바르게 처리해야 합니다.
- 실제 장비 설정에 이 구조를 사용하기 전에 인증 또는 물리적 네트워크 격리를 추가해야 합니다. 산업용 LAN의 로컬 웹 페이지는 장치 제어 표면이 될 수 있습니다.
- 링크 손실과 소켓 복구 로직을 포함해야 합니다. 생산 장치는 이더넷 케이블 분리, 스위치 재부팅, 브라우저의 중간 연결 종료 상황에서 복구할 수 있어야 합니다.
FAQ
Q: STC32G12K128 로컬 TCP 서버에 왜 W5500을 사용하나요?
A: W5500은 SPI를 통해 하드웨어 TCP/IP 소켓 인터페이스를 제공합니다. 따라서 STC32G12K128은 Ethernet, IP, TCP 스택 전체를 펌웨어로 직접 구현하지 않고도 작은 로컬 설정 서버를 만들 수 있습니다.
Q: 이 프로젝트에서 W5500은 STC32G12K128에 어떻게 연결되나요?
A: 같은 STC32G12K128 시리즈의 이전 글에서 이 W5500 구성은 소프트웨어 SPI와 GPIO 기반 reset/interrupt 제어를 사용한다고 확인됩니다. 이 TCP 서버 글의 브라우저 접속 동작은 그 W5500 인터페이스 위에 구현됩니다.
Q: 브라우저 HTTP GET 흐름에서 W5500은 어떤 역할을 하나요?
A: W5500은 로컬 서버가 사용하는 TCP 소켓을 담당합니다. 브라우저는 W5500 기반 IP 주소와 포트에 접속해 HTTP GET 요청을 보내고, STC32 애플리케이션은 W5500 소켓을 통해 HTML을 다시 전송합니다.
Q: 초보자도 따라할 수 있나요?
A: GPIO, 소프트웨어 SPI, IP 주소, TCP 서버 상태, 기본 HTTP를 이해하고 있다면 접근할 수 있습니다. 브라우저 테스트는 결과를 관찰하기 쉽지만, 소켓 상태 처리는 신중하게 디버깅해야 합니다.
Q: 비교 섹션을 넣지 않은 이유는 무엇인가요?
A: 요청 범위가 대체 네트워크 칩이나 무선 모듈 비교가 아니라 W5500 사용에 집중되어 있기 때문입니다. 핵심은 W5500이 소형 STC32G12K128 장치에서 정적 IP 기반 브라우저 접속 TCP 서버를 구현하게 해준다는 점입니다.
출처
Original article: CSDN, “<STC32G12K128入门第十四步>STC32G+TCP_Server进行浏览器访问本地服务器.” 공개 페이지에서 정적 IP 로컬 서버 개념, W5500 socket-as-server 모델, 브라우저 GET 요청 흐름, HTML 응답 개념을 확인할 수 있습니다. 전체 코드는 유료 영역에 있습니다.
Product reference: WIZnet W5500 공식 제품 페이지. 통합 TCP/IP 스택, SPI 인터페이스, Ethernet MAC/PHY, 소켓, 버퍼 기능 확인에 사용했습니다.
License: 접근 가능한 공개 원문 텍스트에서는 명확히 확인되지 않습니다.
Tags
#W5500 #WIZnet #STC32G12K128 #STC32 #TCPServer #SoftwareSPI #StaticIP #LocalWebServer #EmbeddedEthernet #IndustrialIoT #HTTP #GPIO
