How to Build UDP Multicast with WIZnet W5500 on STM32F10x?
This STM32F10x education project demonstrates UDP multicast using the WIZnet W5500 Ethernet controller and WIZnet ioLibrary.
How to Build UDP Multicast with WIZnet W5500 on STM32F10x?
Summary
This STM32F10x education project demonstrates UDP multicast using the WIZnet W5500 Ethernet controller and WIZnet ioLibrary. The STM32 configures the W5500 over SPI, assigns static network parameters, joins a multicast group, sends an initial UDP multicast message, then continuously receives and echoes multicast traffic through W5500 socket 0.
What the Project Does
The project is a hands-on UDP multicast example for an STM32F10x microcontroller connected to a WIZnet W5500 Ethernet controller. It teaches how a small MCU can join an IPv4 multicast group and exchange datagrams with other devices on the same network segment.
The data flow is simple: the STM32 initializes delay, interrupt priority, UART debug output, LEDs, timer, SPI, and W5500 reset/interrupt pins. It then registers W5500 SPI callbacks, checks the chip version, waits for PHY link, writes static network information, opens a UDP multicast socket, sends "I am W5500_Multicast", and enters a loop that receives multicast frames and sends responses.
The network parameters are fixed in the example: 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, multicast MAC 01:00:5E:01:01:0B, multicast IP 224.1.1.11, and multicast port 6000.
Where WIZnet Fits
The exact WIZnet product is W5500. In this project, W5500 is the Ethernet transport device between the STM32F10x application code and the wired LAN. The STM32 does not implement the Ethernet MAC, PHY, or low-level TCP/IP processing in software; instead, it controls W5500 through SPI and uses WIZnet socket APIs such as socket(), sendto(), and recvfrom().
This is a good educational network-stack example because the layers are visible in separate steps: SPI bus adaptation, W5500 callback registration, chip reset, version check, PHY link check, static IP assignment, multicast socket setup, packet receive, and UDP response. The official WIZnet documentation describes W5500 as a hardwired TCP/IP controller with SPI up to 80 MHz, embedded 10/100 Ethernet MAC and PHY, 8 independent sockets, and 32 KB internal buffer memory.
For a classroom or lab exercise, W5500 keeps the lesson focused on socket behavior and Ethernet troubleshooting rather than on writing a full software TCP/IP stack. Students can inspect register-level link status, socket state, multicast group parameters, and packet buffers while still using a compact MCU.
Implementation Notes
The source is available through the CSDN article and the linked STM32F10x_W5500_Examples repository. The repository describes the examples as STM32F10x standard-library projects for driving W5500 and includes a 6.UDP_Multicast routine for UDP multicast communication.
File: wiz_platform.c
What it configures: W5500 chip-select and SPI read/write callbacks.
Why it matters: ioLibrary is MCU-independent, so the STM32-specific SPI functions must be registered before W5500 socket APIs can access the chip.
void wizchip_spi_cb_reg(void)
{
reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
reg_wizchip_spi_cbfunc(wizchip_read_byte, wizchip_write_byte);
reg_wizchip_spiburst_cbfunc(wizchip_read_buff, wizchip_write_buff);
}The article shows this callback registration after defining byte and burst SPI access functions for W5500.
File: UDP_MULTICAST.c
What it configures: W5500 socket 0 as a UDP multicast socket.
Why it matters: multicast requires the socket destination hardware address, multicast IP, port, and UDP multicast mode to match the group being tested.
void Join_W5500_Multicast(uint8_t sn)
{
setSn_DHAR(sn, Multicast_mac);
setSn_DIPR(sn, Multicast_IP);
setSn_DPORT(sn, Multicast_port);
socket(sn, Sn_MR_UDP, Multicast_port, Sn_MR_MULTI);
}The receive loop checks the socket state, reads pending RX data with recvfrom(), appends the local message prefix, and sends the response with sendto().
Practical Tips / Pitfalls
- Verify SPI first. The repository troubleshooting notes explicitly recommend confirming SPI read/write and checking whether the W5500 version register can be read correctly.
- Check PHY link before testing multicast. The example waits until
CW_GET_PHYLINKreportsPHY_LINK_ON, then prints 10/100 Mbps and duplex status. - Keep the STM32 and PC test tool on the same LAN segment. The project uses local multicast addressing and a static IP, so subnet mismatch or duplicate IP addresses will break the test.
- Match multicast IP, multicast MAC, and port. This example uses
224.1.1.11,01:00:5E:01:01:0B, and port6000. - Use a firewall-aware test setup. The repository notes that ping or local tests may fail if the PC firewall blocks traffic.
- Size the receive buffer deliberately. The example defines
ETHERNET_BUF_MAX_SIZEas1024 * 2, then clamps received data to that size before processing. - Use UART logging during lessons. The example prints network configuration, socket opening status, received sender IP/port, and echoed data, which makes stack behavior easier to observe.
FAQ
Q: Why use WIZnet W5500 in this UDP multicast project?
A: W5500 provides a hardwired TCP/IP engine, embedded Ethernet MAC/PHY, 8 sockets, and internal packet buffer memory. In this project, that lets the STM32F10x focus on multicast logic, socket state, and application behavior instead of implementing low-level Ethernet and IP handling in firmware.
Q: How does W5500 connect to the STM32F10x platform?
A: The example connects W5500 through SPI1. The code configures PA5 as SCK, PA6 as MISO, PA7 as MOSI, PA4 as chip select, PC5 as reset, and PC4 as interrupt input.
Q: What role does W5500 play in this project?
A: W5500 acts as the wired Ethernet socket engine. It stores network parameters, joins the multicast group, opens socket 0 in UDP multicast mode, receives datagrams from the group, and transmits UDP responses through the LAN.
Q: Can beginners follow this project?
A: Yes, but it is best for students who already understand basic C, STM32 GPIO/SPI initialization, and IPv4 addressing. The project is useful for education because it separates platform adaptation, network configuration, PHY checking, socket opening, and UDP message handling into visible steps.
Q: What should students verify first when multicast does not work?
A: Start with the physical and local network checks: W5500 version register, PHY link status, static IP/subnet/gateway values, duplicate IP conflicts, PC firewall rules, and whether the test tool joined the same multicast IP and port.
Source
Original article: CSDN, “测试W5500的第5步_使用ioLibrary库创建UDP组播,” first published on 2025-05-23 and marked as CC BY-SA 4.0.
Source repository referenced by the article: WIZnet HK, STM32F10x_W5500_Examples, licensed under Mulan PSL v2.
WIZnet product reference: W5500 documentation.
Tags
#W5500 #WIZnet #STM32F10x #STM32F103 #UDP #Multicast #ioLibrary #Ethernet #SPI #EmbeddedC #Education #NetworkStack
STM32F10x에서 WIZnet W5500으로 UDP 멀티캐스트를 구축하는 방법은?
요약
이 STM32F10x 교육용 프로젝트는 WIZnet W5500 이더넷 컨트롤러와 WIZnet ioLibrary를 사용해 UDP 멀티캐스트를 구현하는 예제입니다. STM32는 SPI로 W5500을 설정하고, 고정 네트워크 정보를 적용한 뒤 멀티캐스트 그룹에 참여합니다. 이후 초기 UDP 멀티캐스트 메시지를 전송하고, W5500 소켓 0을 통해 멀티캐스트 데이터를 수신하고 응답합니다.
프로젝트가 하는 일
이 프로젝트는 WIZnet W5500 이더넷 컨트롤러가 연결된 STM32F10x 마이크로컨트롤러에서 UDP 멀티캐스트 통신을 실습하는 예제입니다. 작은 MCU가 IPv4 멀티캐스트 그룹에 참여하고, 같은 네트워크 세그먼트에 있는 다른 장치와 UDP 데이터그램을 주고받는 과정을 보여줍니다.
데이터 흐름은 단순합니다. STM32는 지연 함수, 인터럽트 우선순위, UART 디버그 출력, LED, 타이머, SPI, W5500 리셋 및 인터럽트 핀을 초기화합니다. 이후 W5500 SPI 콜백을 등록하고, 칩 버전을 확인하며, PHY 링크가 연결될 때까지 대기합니다. 그 다음 고정 네트워크 정보를 W5500에 기록하고, UDP 멀티캐스트 소켓을 열고, "I am W5500_Multicast" 메시지를 전송한 뒤 수신 루프에 들어갑니다.
예제의 네트워크 파라미터는 고정되어 있습니다. 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입니다. 멀티캐스트 MAC은 01:00:5E:01:01:0B, 멀티캐스트 IP는 224.1.1.11, 멀티캐스트 포트는 6000입니다.
WIZnet이 들어가는 위치
이 프로젝트에서 사용되는 WIZnet 제품은 W5500입니다. W5500은 STM32F10x 애플리케이션 코드와 유선 LAN 사이에 위치하는 이더넷 전송 장치입니다. STM32가 이더넷 MAC, PHY, 저수준 TCP/IP 처리를 직접 구현하는 구조가 아니라, SPI로 W5500을 제어하고 WIZnet 소켓 API인 socket(), sendto(), recvfrom()을 사용합니다.
이 예제는 교육용 네트워크 스택 실습에 적합합니다. SPI 버스 적응, W5500 콜백 등록, 칩 리셋, 버전 확인, PHY 링크 확인, 고정 IP 설정, 멀티캐스트 소켓 설정, 패킷 수신, UDP 응답 전송이 단계별로 분리되어 있기 때문입니다.
W5500은 하드웨어 TCP/IP 컨트롤러이며, SPI 인터페이스, 10/100 Ethernet MAC/PHY, 8개 독립 소켓, 32 KB 내부 버퍼를 제공합니다. 따라서 수업이나 실습에서는 학생들이 전체 TCP/IP 스택 구현보다 소켓 동작, 링크 상태, 멀티캐스트 그룹 설정, 패킷 송수신 흐름을 관찰하는 데 집중할 수 있습니다.
구현 참고 사항
소스는 CSDN 글과 해당 글에서 연결한 STM32F10x_W5500_Examples 저장소를 통해 확인할 수 있습니다. 저장소는 STM32F10x 표준 라이브러리 기반 W5500 예제를 제공하며, 6.UDP_Multicast 예제가 UDP 멀티캐스트 통신을 담당합니다.
파일: wiz_platform.c
설정 내용: W5500 칩 셀렉트 및 SPI 읽기/쓰기 콜백 등록
중요한 이유: ioLibrary는 MCU에 독립적인 구조이므로, W5500 소켓 API가 칩에 접근하려면 STM32에 맞는 SPI 함수가 먼저 등록되어야 합니다.
void wizchip_spi_cb_reg(void)
{
reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
reg_wizchip_spi_cbfunc(wizchip_read_byte, wizchip_write_byte);
reg_wizchip_spiburst_cbfunc(wizchip_read_buff, wizchip_write_buff);
}이 코드는 W5500이 SPI를 통해 정상적으로 읽기/쓰기 동작을 수행하도록 플랫폼 계층을 연결합니다. 이후의 네트워크 설정과 소켓 제어는 이 콜백 등록이 정상적으로 끝난 뒤에 동작합니다.
파일: UDP_MULTICAST.c
설정 내용: W5500 소켓 0을 UDP 멀티캐스트 소켓으로 설정
중요한 이유: 멀티캐스트 통신에서는 목적지 하드웨어 주소, 멀티캐스트 IP, 포트, UDP 멀티캐스트 모드가 테스트 그룹과 일치해야 합니다.
void Join_W5500_Multicast(uint8_t sn)
{
setSn_DHAR(sn, Multicast_mac);
setSn_DIPR(sn, Multicast_IP);
setSn_DPORT(sn, Multicast_port);
socket(sn, Sn_MR_UDP, Multicast_port, Sn_MR_MULTI);
}수신 루프에서는 소켓 상태를 확인하고, 수신된 데이터가 있으면 recvfrom()으로 읽습니다. 이후 로컬 메시지 접두어를 붙이고 sendto()로 응답을 전송합니다.
실무 팁 / 주의점
- SPI부터 확인해야 합니다. W5500 버전 레지스터를 정상적으로 읽을 수 있어야 이후 네트워크 테스트가 의미 있습니다.
- 멀티캐스트 테스트 전에 PHY 링크 상태를 확인해야 합니다. 예제는
CW_GET_PHYLINK가PHY_LINK_ON을 반환할 때까지 대기합니다. - STM32 보드와 PC 테스트 도구는 같은 LAN 세그먼트에 있어야 합니다. 고정 IP를 사용하므로 서브넷 불일치나 IP 충돌이 있으면 통신이 실패합니다.
- 멀티캐스트 IP, 멀티캐스트 MAC, 포트를 정확히 맞춰야 합니다. 이 예제는
224.1.1.11,01:00:5E:01:01:0B, 포트6000을 사용합니다. - PC 방화벽을 확인해야 합니다. 방화벽이 UDP 수신이나 테스트 도구의 네트워크 접근을 차단하면 정상 코드에서도 패킷이 보이지 않을 수 있습니다.
- 수신 버퍼 크기를 의도적으로 정해야 합니다. 예제는
ETHERNET_BUF_MAX_SIZE를1024 * 2로 정의하고, 수신 데이터가 이 크기를 넘지 않도록 처리합니다. - 교육 실습에서는 UART 로그를 켜두는 것이 좋습니다. 네트워크 설정, 소켓 오픈 상태, 송신자 IP/포트, 수신 데이터를 확인할 수 있어 문제 분석이 쉬워집니다.
FAQ
Q: 이 UDP 멀티캐스트 프로젝트에서 왜 WIZnet W5500을 사용하나요?
A: W5500은 하드웨어 TCP/IP 엔진, 내장 Ethernet MAC/PHY, 8개 소켓, 내부 패킷 버퍼를 제공합니다. 이 프로젝트에서는 STM32F10x가 저수준 이더넷 처리보다 멀티캐스트 로직, 소켓 상태, 애플리케이션 동작에 집중할 수 있게 합니다.
Q: W5500은 STM32F10x에 어떻게 연결하나요?
A: 예제는 W5500을 SPI1로 연결합니다. PA5는 SCK, PA6은 MISO, PA7은 MOSI, PA4는 칩 셀렉트, PC5는 리셋, PC4는 인터럽트 입력으로 사용됩니다.
Q: 이 프로젝트에서 W5500은 어떤 역할을 하나요?
A: W5500은 유선 이더넷 소켓 엔진 역할을 합니다. 네트워크 파라미터를 저장하고, 멀티캐스트 그룹에 참여하며, 소켓 0을 UDP 멀티캐스트 모드로 열고, LAN을 통해 UDP 데이터그램을 수신 및 전송합니다.
Q: 초보자도 따라할 수 있나요?
A: 가능합니다. 다만 기본 C 언어, STM32 GPIO/SPI 초기화, IPv4 주소 체계에 대한 기초 지식이 있으면 훨씬 수월합니다. 이 프로젝트는 플랫폼 적응, 네트워크 설정, PHY 확인, 소켓 오픈, UDP 메시지 처리가 단계별로 나뉘어 있어 교육용으로 적합합니다.
Q: 멀티캐스트가 동작하지 않을 때 무엇을 먼저 확인해야 하나요?
A: 먼저 W5500 버전 레지스터, PHY 링크 상태, 고정 IP·서브넷·게이트웨이 값, IP 충돌 여부, PC 방화벽, 테스트 도구가 같은 멀티캐스트 IP와 포트에 참여했는지를 확인해야 합니다.
출처
Original article: CSDN, “测试W5500的第5步_使用ioLibrary库创建UDP组播,” 2025-05-23 게시, CC BY-SA 4.0로 표시됨.
https://blog.csdn.net/weixin_42550185/article/details/148157638?spm=1001.2014.3001.5502
Source repository: WIZnet HK, STM32F10x_W5500_Examples, Mulan PSL v2 라이선스.
https://gitee.com/wiznet-hk/STM32F10x_W5500_Examples
WIZnet product reference: W5500 documentation.
https://docs.wiznet.io/Product/Chip/Ethernet/W5500
태그
#W5500 #WIZnet #STM32F10x #STM32F103 #UDP #Multicast #ioLibrary #Ethernet #SPI #EmbeddedC #Education #NetworkStack
