Wiznet makers

chen

Published May 16, 2026 ©

105 UCC

1 WCC

27 VAR

0 Contests

0 Followers

0 Following

Original Link

How to Test ICMP Ping with WIZnet W5500 on STM32F10x?

This STM32F10x education project demonstrates ICMP ping testing with the WIZnet W5500 Ethernet controller.

COMPONENTS
PROJECT DESCRIPTION

How to Test ICMP Ping with WIZnet W5500 on STM32F10x?

Summary

This STM32F10x education project demonstrates ICMP ping testing with the WIZnet W5500 Ethernet controller. The STM32 configures W5500 through SPI, applies static IPv4 settings, opens W5500 socket 0 in IPRAW mode, sends ICMP Echo Request packets to a PC, receives Echo Reply packets, and can also respond when the PC pings the W5500 device. W5500 provides the wired Ethernet interface, hardware TCP/IP engine, socket registers, and packet buffer used to expose ICMP behavior clearly for network-stack learning.

What the Project Does

The project is a ping diagnostic example for an STM32F10x microcontroller connected to a WIZnet W5500 Ethernet controller. It explains ping as a way to verify whether two hosts can exchange packets, using ICMP Echo packets and replies. The article also distinguishes IPRAW from TCP and UDP: IPRAW operates at the IP layer, below TCP and UDP, which makes it suitable for building an ICMP ping example directly on top of W5500 socket access.

The data flow has two directions. First, the STM32 sends ICMP Echo Request packets from W5500 to a target PC address. Second, the firmware listens for ICMP Echo Request packets from the PC and sends Echo Reply packets back. This makes the example useful for education because students can test both outbound and inbound diagnostic traffic rather than only verifying a single application protocol.

The example uses static network information: MAC 00:08:DC:11:11:11, local IP 192.168.1.199, subnet 255.255.255.0, gateway 192.168.1.1, DNS 8.8.8.8, local port 4000, and destination PC IP 192.168.1.190. The W5500 example repository identifies 16.PING as the routine for pinging devices in IPRAW mode.

Where WIZnet Fits

The exact WIZnet product is W5500. In this architecture, W5500 is the wired Ethernet controller and hardware network engine between the STM32F10x firmware and the LAN. The STM32 handles board initialization, SPI access, packet construction, checksum validation, UART logging, and ping state flow. W5500 handles the Ethernet MAC/PHY path, socket mode, receive buffer state, transmit path, and network register interface.

W5500 is a hardwired TCP/IP stack internet controller that connects to an external MCU through SPI up to 80 MHz. It includes an embedded 10/100 Ethernet MAC and PHY, supports TCP, UDP, ICMP, IPv4, ARP, IGMP, and PPPoE, provides 8 independent sockets, and includes 32 KB of internal Tx/Rx buffer memory.

For an education project, this is useful because the ICMP path can be observed without hiding everything inside a larger software stack. Students can see how the firmware writes the ICMP protocol number into the socket protocol register, opens IPRAW mode, checks socket state, reads the receive-size register, validates checksums, and prints packet status over UART. That makes W5500 a practical teaching device for separating link bring-up, IP-layer diagnostics, socket state, and packet parsing.

Implementation Notes

File: W5500_Variable.c
What it configures: static IPv4 identity, local port, Ethernet buffer, and target PC address.
Why it matters: ping testing only makes sense after the local W5500 address and the remote host address are deterministic and in the same reachable network environment.

 
wiz_NetInfo net_info = {
    {0x00, 0x08, 0xdc,0x11, 0x11, 0x11},
    {192, 168, 1, 199},
    {255,255,255,0},
    {192, 168, 1, 1},
    {8,8,8,8},
    NETINFO_STATIC};

uint16_t Local_Port=4000;
uint8_t dest_ip[4] = {192, 168, 1, 190};
 

This code exists because the W5500 must have a fixed network identity before the STM32 can test ICMP reachability against a known PC. The target address 192.168.1.190 is the PC used in the ping test.

File: Test_Ping.c
What it configures: W5500 socket 0 for ICMP over IPRAW mode.
Why it matters: ICMP ping is not a TCP or UDP application. The firmware writes IPPROTO_ICMP into the socket protocol register, opens the socket in Sn_MR_IPRAW, then waits until the socket state becomes SOCK_IPRAW.

 
void Ping_Init(uint8_t s)
{
    close(s);
    IINCHIP_WRITE(Sn_PROTO(s), IPPROTO_ICMP);
    socket(s, Sn_MR_IPRAW, Local_Port, 0);

    while (getSn_SR(s) != SOCK_IPRAW)
    {
        ;
    }
}
 

The ping request routine fills an ICMP packet with type PING_REQUEST, code CODE_ZERO, ID 0x1000, sequence number, payload data, and checksum, then sends it with sendto(). The receive path uses recvfrom(), checks whether the first byte is PING_REPLY, reconstructs ICMP fields, recalculates the checksum, and prints the reply source, ID, sequence number, and byte count.

File: main.c
What it configures: board bring-up, W5500 initialization, network setup, PC ping test, and PC-to-W5500 ping response test.
Why it matters: this shows the whole architecture from hardware initialization to network diagnosis.

 
wizchip_initialize();
TCP_network_init(ethernet_buf, &net_info);

W5500_Ping_RemoteComputer(TCP_SOCKET0, dest_ip, ethernet_buf);
delay_ms(1000);
RemoteComputer_Ping_W5500(TCP_SOCKET0, dest_ip, ethernet_buf);
 

The same main flow initializes delay, UART, LED, timer, SPI1, W5500 reset and interrupt pins, registers W5500 access functions through wizchip_initialize(), checks chip version and PHY status, applies network settings, then runs both ping directions.

Practical Tips / Pitfalls

  • Verify SPI access before testing ICMP. The repository troubleshooting notes recommend confirming SPI read/write and W5500 chip-version access first. 
  • Confirm PHY status before blaming ping code. The initialization comments describe checking W5500 PHY bits for link, speed, and duplex state. 
  • Keep the PC and W5500 on the same subnet for the first lab test. The example uses 192.168.1.199 for W5500 and 192.168.1.190 for the PC.
  • Disable or adjust the PC firewall during testing. The repository notes that ping can fail in the same network if the firewall blocks traffic or if there is a static IP conflict. 
  • Do not confuse the macro name TCP_SOCKET0 with the active socket mode. In the ping routine, socket 0 is reopened as Sn_MR_IPRAW.
  • Validate checksum handling carefully. The example recalculates ICMP checksums and treats 0xffff as the valid result.
  • Use UART output as a teaching tool. Reply count, lost count, remote IP, ID, sequence number, and checksum messages make the network-stack flow visible.

FAQ

Q: Why use WIZnet W5500 for ICMP ping on STM32F10x?
A: W5500 provides the Ethernet MAC/PHY, hardware TCP/IP engine, ICMP-capable IPRAW socket mode, and internal packet buffers. This lets STM32F10x firmware focus on ICMP packet construction, checksum checking, and state flow instead of building the whole Ethernet/IP path in software.

Q: How does W5500 connect to the STM32F10x platform?
A: The project follows the same W5500 platform structure used across the STM32F10x example set: initialize SPI1, configure the W5500 reset and interrupt pins, register chip-select and SPI access callbacks, reset W5500, read the chip version, and check PHY link before running protocol examples.

Q: What role does W5500 play in this ping project?
A: W5500 provides the IPRAW socket used to transmit and receive ICMP packets. The STM32 prepares the ICMP Echo Request and Echo Reply data, while W5500 moves the packets through the wired Ethernet interface and exposes receive data length through socket registers such as Sn_RX_RSR.

Q: Can beginners follow this education project?
A: Yes, if they already understand basic STM32 initialization, SPI, UART logging, IPv4 addressing, and the purpose of ping. It is a good classroom exercise because students can observe the difference between link status, IP configuration, ICMP packet format, checksum validation, and packet loss.

Q: How does W5500 compare with an LwIP-based ping example?
A: With W5500, the Ethernet MAC/PHY, socket resources, and packet buffering are handled by the controller, so the STM32 mainly drives SPI and ICMP application logic. With LwIP, the STM32 typically owns more of the Ethernet driver integration, memory pools, packet buffers, protocol timers, and ICMP processing path; that is flexible, but it adds more network-stack material before students can focus on ping behavior.

Source

Original article: CSDN, “测试W5500的第10步_使用W5500去PING计算机,” first published on 2025-06-04 and marked as CC 4.0 BY-SA.

Source repository referenced by the article: WIZnet HK, STM32F10x_W5500_Examples, licensed under Mulan PSL v2. The repository describes 16.PING as the example for pinging devices in IPRAW mode.

WIZnet product reference: W5500 documentation and ioLibrary Driver documentation.

Tags

#W5500 #WIZnet #STM32F10x #STM32F103 #ICMP #Ping #IPRAW #Ethernet #SPI #ioLibrary #EmbeddedC #Education #NetworkStack

 

STM32F10x에서 WIZnet W5500으로 ICMP Ping을 테스트하는 방법은?

요약

이 STM32F10x 교육용 프로젝트는 WIZnet W5500 이더넷 컨트롤러를 사용해 ICMP Ping 테스트를 구현합니다. STM32는 SPI로 W5500을 설정하고, 고정 IPv4 정보를 적용한 뒤, W5500 소켓 0을 IPRAW 모드로 열어 PC로 ICMP Echo Request 패킷을 전송합니다. 또한 PC에서 W5500 장치로 Ping을 보냈을 때 Echo Reply로 응답할 수도 있습니다. W5500은 네트워크 스택 학습에 필요한 유선 이더넷 인터페이스, 하드웨어 TCP/IP 엔진, 소켓 레지스터, 패킷 버퍼를 제공합니다.

프로젝트가 하는 일

이 프로젝트는 WIZnet W5500 이더넷 컨트롤러가 연결된 STM32F10x 마이크로컨트롤러에서 Ping 진단 기능을 구현하는 예제입니다. Ping은 두 호스트가 패킷을 주고받을 수 있는지 확인하는 기본 네트워크 진단 방법이며, ICMP Echo Request와 Echo Reply 패킷을 사용합니다.

원문은 IPRAW가 TCP 및 UDP와 어떻게 다른지도 설명합니다. IPRAW는 TCP나 UDP보다 아래 계층인 IP 계층에서 동작합니다. 따라서 W5500의 소켓 접근 기능 위에서 ICMP Ping 예제를 직접 구성하기에 적합합니다.

데이터 흐름은 두 방향으로 구성됩니다. 첫 번째는 STM32가 W5500을 통해 대상 PC 주소로 ICMP Echo Request 패킷을 보내는 흐름입니다. 두 번째는 PC가 W5500 장치로 ICMP Echo Request를 보냈을 때, 펌웨어가 Echo Reply 패킷을 다시 보내는 흐름입니다. 이 구조는 단순한 애플리케이션 프로토콜 테스트가 아니라 송신과 수신 양쪽의 진단 트래픽을 모두 확인할 수 있어 교육용으로 적합합니다.

예제는 고정 네트워크 정보를 사용합니다. MAC 주소는 00:08:DC:11:11:11, 로컬 IP는 192.168.1.199, 서브넷은 255.255.255.0, 게이트웨이는 192.168.1.1, DNS는 8.8.8.8, 로컬 포트는 4000, 대상 PC IP는 192.168.1.190입니다. W5500 예제 저장소에서는 16.PING을 IPRAW 모드로 장치에 Ping을 보내는 예제로 설명합니다.

WIZnet이 들어가는 위치

이 프로젝트에서 사용되는 WIZnet 제품은 W5500입니다. 이 구조에서 W5500은 STM32F10x 펌웨어와 LAN 사이에 위치하는 유선 이더넷 컨트롤러이자 하드웨어 네트워크 엔진입니다. STM32는 보드 초기화, SPI 접근, 패킷 구성, 체크섬 검증, UART 로그, Ping 상태 흐름을 처리합니다. W5500은 Ethernet MAC/PHY 경로, 소켓 모드, 수신 버퍼 상태, 송신 경로, 네트워크 레지스터 인터페이스를 담당합니다.

W5500은 하드웨어 TCP/IP 스택 기반 인터넷 컨트롤러이며, 외부 MCU와 최대 80 MHz SPI로 연결됩니다. 내장 10/100 Ethernet MAC 및 PHY를 포함하고, TCP, UDP, ICMP, IPv4, ARP, IGMP, PPPoE를 지원합니다. 또한 8개 독립 소켓과 32 KB 내부 Tx/Rx 버퍼 메모리를 제공합니다.

교육용 프로젝트에서는 이 구조가 유용합니다. ICMP 경로가 큰 소프트웨어 스택 내부에 숨겨지지 않기 때문입니다. 학생들은 펌웨어가 소켓 프로토콜 레지스터에 ICMP 프로토콜 번호를 쓰고, IPRAW 모드로 소켓을 열고, 소켓 상태를 확인하고, 수신 크기 레지스터를 읽고, 체크섬을 검증하고, UART로 패킷 상태를 출력하는 과정을 직접 관찰할 수 있습니다. 이를 통해 링크 bring-up, IP 계층 진단, 소켓 상태, 패킷 파싱을 분리해서 이해할 수 있습니다.

구현 참고 사항

파일: W5500_Variable.c
설정 내용: 고정 IPv4 정보, 로컬 포트, 이더넷 버퍼, 대상 PC 주소
중요한 이유: Ping 테스트는 로컬 W5500 주소와 원격 호스트 주소가 명확하고, 같은 네트워크 환경에서 접근 가능할 때 의미가 있습니다.

 
wiz_NetInfo net_info = {
    {0x00, 0x08, 0xdc,0x11, 0x11, 0x11},
    {192, 168, 1, 199},
    {255,255,255,0},
    {192, 168, 1, 1},
    {8,8,8,8},
    NETINFO_STATIC};

uint16_t Local_Port=4000;
uint8_t dest_ip[4] = {192, 168, 1, 190};
 

이 코드는 STM32가 알려진 PC를 대상으로 ICMP 도달성을 테스트하기 전에 W5500이 고정된 네트워크 식별 정보를 가져야 하기 때문에 필요합니다. 대상 주소 192.168.1.190은 Ping 테스트에 사용되는 PC 주소입니다.

파일: Test_Ping.c
설정 내용: W5500 소켓 0을 ICMP용 IPRAW 모드로 설정
중요한 이유: ICMP Ping은 TCP 또는 UDP 애플리케이션이 아닙니다. 펌웨어는 소켓 프로토콜 레지스터에 IPPROTO_ICMP를 쓰고, 소켓을 Sn_MR_IPRAW 모드로 연 뒤, 소켓 상태가 SOCK_IPRAW가 될 때까지 대기합니다.

 
void Ping_Init(uint8_t s)
{
    close(s);
    IINCHIP_WRITE(Sn_PROTO(s), IPPROTO_ICMP);
    socket(s, Sn_MR_IPRAW, Local_Port, 0);

    while (getSn_SR(s) != SOCK_IPRAW)
    {
        ;
    }
}
 

Ping 요청 루틴은 ICMP 패킷에 PING_REQUEST 타입, CODE_ZERO 코드, ID 0x1000, 시퀀스 번호, payload 데이터, 체크섬을 채운 뒤 sendto()로 전송합니다. 수신 경로는 recvfrom()을 사용해 데이터를 읽고, 첫 번째 바이트가 PING_REPLY인지 확인합니다. 이후 ICMP 필드를 재구성하고 체크섬을 다시 계산한 뒤, 응답 출발지, ID, 시퀀스 번호, 바이트 수를 출력합니다.

파일: main.c
설정 내용: 보드 bring-up, W5500 초기화, 네트워크 설정, PC Ping 테스트, PC에서 W5500으로 보내는 Ping 응답 테스트
중요한 이유: 하드웨어 초기화부터 네트워크 진단까지 전체 구조를 보여줍니다.

 
wizchip_initialize();
TCP_network_init(ethernet_buf, &net_info);

W5500_Ping_RemoteComputer(TCP_SOCKET0, dest_ip, ethernet_buf);
delay_ms(1000);
RemoteComputer_Ping_W5500(TCP_SOCKET0, dest_ip, ethernet_buf);
 

같은 main 흐름은 지연 함수, UART, LED, 타이머, SPI1, W5500 리셋 및 인터럽트 핀을 초기화합니다. 이후 wizchip_initialize()를 통해 W5500 접근 함수를 등록하고, 칩 버전과 PHY 상태를 확인한 뒤, 네트워크 설정을 적용하고 양방향 Ping 테스트를 실행합니다.

실무 팁 / 주의점

  • ICMP를 테스트하기 전에 SPI 접근을 먼저 검증해야 합니다. SPI 읽기/쓰기와 W5500 칩 버전 접근이 정상이어야 합니다.
  • Ping 코드 문제로 판단하기 전에 PHY 상태를 확인해야 합니다. 초기화 흐름은 W5500 PHY 비트를 읽어 링크, 속도, 듀플렉스 상태를 확인합니다.
  • 첫 실습에서는 PC와 W5500을 같은 서브넷에 둬야 합니다. 예제는 W5500에 192.168.1.199, PC에 192.168.1.190을 사용합니다.
  • 테스트 중 PC 방화벽을 끄거나 ICMP 허용 규칙을 설정해야 합니다. 같은 네트워크에 있어도 방화벽이 ICMP를 차단하면 Ping이 실패할 수 있습니다.
  • TCP_SOCKET0라는 매크로 이름과 실제 소켓 모드를 혼동하면 안 됩니다. Ping 루틴에서는 소켓 0이 Sn_MR_IPRAW 모드로 다시 열립니다.
  • 체크섬 처리는 정확히 검증해야 합니다. 예제는 ICMP 체크섬을 다시 계산하고 0xffff를 유효한 결과로 처리합니다.
  • UART 출력은 교육용으로 유용합니다. 응답 수, 손실 수, 원격 IP, ID, 시퀀스 번호, 체크섬 메시지를 통해 네트워크 스택 흐름을 눈으로 확인할 수 있습니다.

FAQ

Q: STM32F10x에서 ICMP Ping을 구현할 때 왜 WIZnet W5500을 사용하나요?
A: W5500은 Ethernet MAC/PHY, 하드웨어 TCP/IP 엔진, ICMP 처리가 가능한 IPRAW 소켓 모드, 내부 패킷 버퍼를 제공합니다. STM32F10x 펌웨어는 전체 Ethernet/IP 경로를 소프트웨어로 직접 구성하지 않고, ICMP 패킷 생성, 체크섬 검증, 상태 흐름에 집중할 수 있습니다.

Q: W5500은 STM32F10x 플랫폼에 어떻게 연결되나요?
A: 이 프로젝트는 STM32F10x 예제 세트와 동일한 W5500 플랫폼 구조를 따릅니다. SPI1을 초기화하고, W5500 리셋 및 인터럽트 핀을 설정한 뒤, 칩 셀렉트와 SPI 접근 콜백을 등록합니다. 이후 W5500을 리셋하고, 칩 버전을 읽고, PHY 링크를 확인한 뒤 프로토콜 예제를 실행합니다.

Q: 이 Ping 프로젝트에서 W5500은 어떤 역할을 하나요?
A: W5500은 ICMP 패킷을 송수신하는 IPRAW 소켓을 제공합니다. STM32는 ICMP Echo Request와 Echo Reply 데이터를 준비하고, W5500은 패킷을 유선 이더넷 인터페이스로 전송하며, Sn_RX_RSR 같은 소켓 레지스터를 통해 수신 데이터 길이를 제공합니다.

Q: 초보자도 이 교육용 프로젝트를 따라할 수 있나요?
A: 기본 STM32 초기화, SPI, UART 로그, IPv4 주소 체계, Ping의 목적을 이해하고 있다면 따라갈 수 있습니다. 이 예제는 링크 상태, IP 설정, ICMP 패킷 형식, 체크섬 검증, 패킷 손실의 차이를 관찰할 수 있어 수업용 실습으로 적합합니다.

Q: W5500 방식은 LwIP 기반 Ping 예제와 어떻게 다른가요?
A: W5500을 사용하면 Ethernet MAC/PHY, 소켓 자원, 패킷 버퍼링이 컨트롤러 내부에서 처리되므로 STM32는 주로 SPI와 ICMP 애플리케이션 로직을 구동합니다. LwIP를 사용하면 STM32가 Ethernet 드라이버 통합, 메모리 풀, 패킷 버퍼, 프로토콜 타이머, ICMP 처리 경로를 더 많이 담당합니다. 이 방식은 유연하지만, 학생들이 Ping 동작 자체에 집중하기 전에 더 많은 네트워크 스택 요소를 다뤄야 합니다.

출처

Original article: CSDN, “测试W5500的第10步_使用W5500去PING计算机,” 2025-06-04 게시, CC 4.0 BY-SA로 표시됨.
https://blog.csdn.net/weixin_42550185/article/details/148423303?spm=1001.2014.3001.5502

Source repository referenced by the article: WIZnet HK, STM32F10x_W5500_Examples, Mulan PSL v2 라이선스. 저장소는 16.PING을 IPRAW 모드로 장치에 Ping을 보내는 예제로 설명합니다.
https://gitee.com/wiznet-hk/STM32F10x_W5500_Examples

WIZnet product reference: W5500 documentation and ioLibrary Driver documentation.
https://docs.wiznet.io/Product/Chip/Ethernet/W5500

태그

#W5500 #WIZnet #STM32F10x #STM32F103 #ICMP #Ping #IPRAW #Ethernet #SPI #ioLibrary #EmbeddedC #Education #NetworkStack

Documents
Comments Write