Wiznet makers

ronpang

Published July 29, 2025 © Apache License 2.0 (Apache-2.0)

130 UCC

63 WCC

32 VAR

0 Contests

1 Followers

0 Following

Hardwired TCP/IP Chapter 6: W55MH32 UDP Multicast Example

Hardwired TCP/IP Chapter 6: W55MH32 UDP Multicast Example

COMPONENTS
PROJECT DESCRIPTION

Hardwired TCP/IP Chapter 6: W55MH32 UDP Multicast Example

In this article, we will provide a detailed explanation on how to implement UDP multicast communication on the W55MH32 chip. Through practical examples, we will also demonstrate how to conduct loopback tests using UDP Multicast.

Other network protocols used in this example, such as DHCP and UDP, can be found in the relevant sections. Regarding the initialization process of the W55MH32, please refer to the Network Install section. We will not go into further details here.

1 UDP Multicast Introduction

UDP multicast is a data transmission method that enables data to be sent from a single source to multiple target devices. Receivers that join the corresponding multicast group can receive the data. This method is highly efficient and is widely used in scenarios where the same data needs to be simultaneously transmitted to multiple recipients, such as video streaming, real-time data distribution, and large-scale software updates. The multicast address range for IPv4 is from 224.0.0.0 to 233.255.255.255.

2 The characteristics of UDP Multicast

Based on the UDP protocol: UDP is a connectionless protocol that provides fast and low-cost data transmission, but does not guarantee data reliability, order, or retransmission. UDP multicast inherits these characteristics, making it suitable for scenarios with high real-time requirements and lower reliability requirements.

Efficient data transmission: The sender only needs to send one copy of the data, and network devices (such as routers and switches) are responsible for replicating and transmitting the data to all multicast members. This method saves bandwidth and is more efficient than unicast.

No guarantee of reliability: Data may be lost, and the receiver needs to handle the problem of packet loss by themselves.

Dynamic member management: Members of the multicast group can join or leave dynamically without notifying the sender.

3 UDP Multicast Application Scenarios

Next, let's explore what operations and applications can be accomplished using UDP Multicast on the W55MH32?

Device discovery and automatic configuration: Enables automatic device discovery and network configuration, such as smart home devices searching for gateways or other devices through multicast.

Real-time data broadcasting: Used for sensor data distribution, industrial control, and efficient transmission of real-time data in the Internet of Vehicles.

Firmware update and configuration distribution: Simultaneously upgrade the firmware of multiple devices or distribute configurations to all devices, reducing network load.

Alarm and event notification: Real-time broadcast of alarm messages to multiple monitoring terminals when a device malfunctions.

Time synchronization: Used for time synchronization of multiple devices within a local area network, improving collaboration efficiency.

Testing and debugging: During the device development stage, use multicast to collect status information and log data.

4 UDP Multicast Loopback Test Workflow

  1. The receiving party joins the multicast group through the IGMP protocol: IGMP (Internet Group Management Protocol) is a network layer protocol used to manage the membership of multicast groups between hosts and routers. When the receiving party wishes to receive data from a certain multicast address, it will send a request to join the multicast group to the router via IGMP.
  2. The sender sends test data: The sender sends data packets using the UDP protocol to the specified multicast address and port. All receiving parties that have joined the multicast group can receive the data packets.
  3. The receiving party sends back a message: After receiving the multicast data, the receiving party actively sends a response message back to the multicast group. The returned message can be used to confirm the successful transmission or to test the integrity of the link.

5 The differences between UDP unicast, multicast and broadcast

The following are the differences between UDP unicast, multicast and broadcast:

Characteristics

Unicast

Multicast

Broadcast

Communication scope

One-on-one

One-to-many (multicast group members)

A pair of all (devices within the local area network)

Efficiency

Point-to-point, efficient

More efficient than unicast, requires multicast support

Wasting bandwidth, high load

Address type

Target device IP address

Multicast IP address (224.0.0.0+)

Broadcast address (subnet broadcast address)

Network configuration

No additional configuration required

The network needs to support multicast.

 

Limited within the subnet, supports broadcasting

Application scenario

Client-server communication

Audio-video streams, multi-device message broadcasting

Local area network device discovery and alarm notification

6 Message parsing

The UDP protocol packets have been explained in the UDP section. For the content related to this part, please refer to the relevant chapters. We will not repeat it here. Now, let's explain the IGMP packets that devices use when joining a multicast group.

The packets sent when a device joins a multicast group are the IGMP Membership Report packets. Their format is as follows:

Byte offset

Field name

len

Description

0

Type

1 Byte

Indicate the type of the IGMP message (such as joining or leaving).

1

(Max Resp Time

1 Byte

Specify the maximum waiting time for the response, and use it only in the query message.

2-3

Checksum

2 Byte

The checksum of the message header is used to detect transmission errors.

4-7

Group Address

4 Byte

The IP address of the multicast group indicating the addition.

Field Explanation

  • Type

The value of 0x16 (IGMPv2 Membership Report) indicates that the host is requesting to join the multicast group.

The value of 0x22 (IGMPv3 Membership Report) is used to support the fine-grained multicast group management of IGMPv3.

  • Checksum

The calculation method is based on the standard IP checksum algorithm.

It is used to ensure the integrity of IGMP messages.

  • Group Address

The IP address of the multicast group (range: 224.0.0.0 - 239.255.255.255).

When joining, it indicates the multicast address of the target.

Message example

|Message Analysis|
Internet Group Management Protocol
    [IGMP Version: 2]
    Type: Membership Report (0x16)      (Type为0x16,Indicates that the host requests to join the multicast group)
    Max Resp Time: 0.0 sec (0x00)          (The maximum response time is 0.)
    Checksum: 0x08f3 [correct]                (Checksum is 0x08f3)
    [Checksum Status: Good]
Multicast Address: 224.1.1.11                 (The group address is 224.1.1.1)

|Original message|
16 00 08 f3 e0 01 01 0b

7 The implementation process

Next, we conduct the UDP multicast loopback test on W55MH32.

Note: The test instance requires that the PC and W55MH32 be on the same network segment, and the connected router must support the IGMP protocol.

UDP communication has already been implemented at the hardware level, so we only need to call the function of the multicast feature of udp_multicast() in the main loop, as shown below:

1.     while (1)

2.     {

3.         udp_multicast(SOCKET_ID, ethernet_buf, Multicast_mac, Multicast_IP, Multicast_port);

4.     }

The udp_multicast function requires five parameters to be passed in, namely the socket number, socket cache, multicast MAC address, multicast IP address, and multicast port number.

The content of the udp_multicast function is as follows:

 1. int32_t udp_multicast(uint8_t sn, uint8_t *buf, uint8_t *multicast_mac, uint8_t *multicast_ip, uint16_t multicast_port)
 2. {
 3.     int32_t  ret;
 4.     uint16_t size, sentsize;
 5.     uint8_t  destip[4];
 6.     uint16_t destport, port = 50000;
 7. 
 8.     switch (getSn_SR(sn))
 9.     {
10.     case SOCK_UDP:
11.         if ((size = getSn_RX_RSR(sn)) > 0)
12.         {
13.             if (size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
14.             ret      = recvfrom(sn, buf, size, destip, (uint16_t *)&destport);
15.             buf[ret] = 0x00;
16.             printf("recv from [%d.%d.%d.%d][%d]: %s\r\n", destip[0], destip[1], destip[2], destip[3], destport, buf);
17.             if (ret <= 0)
18.             {
19. #ifdef _MULTICAST_DEBUG_
20.                 printf("%d: recvfrom error. %ld\r\n", sn, ret);
21. #endif
22.                 return ret;
23.             }
24.             size     = (uint16_t)ret;
25.             sentsize = 0;
26.             while (sentsize != size)
27.             {
28.                 ret = sendto(sn, buf + sentsize, size - sentsize, destip, destport);
29.                 if (ret < 0)
30.                 {
31. #ifdef _MULTICAST_DEBUG_
32.                     printf("%d: sendto error. %ld\r\n", sn, ret);
33. #endif
34.                     return ret;
35.                 }
36.                 sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
37.             }
38.         }
39. 
40.         break;
41.     case SOCK_CLOSED:
42. #ifdef _MULTICAST_DEBUG_
43.         printf("%d:Multicast Loopback start\r\n", sn);
44. #endif
45.         setSn_DIPR(sn, multicast_ip);
46.         setSn_DPORT(sn, multicast_port);
47.         setSn_DHAR(sn, multicast_mac);
48.         if ((ret = socket(sn, Sn_MR_UDP, port, Sn_MR_MULTI)) != sn)
49.             return ret;
50. #ifdef _MULTICAST_DEBUG_
51.         printf("%d:Opened, UDP Multicast Socket\r\n", sn);
52.         printf("%d:Multicast Group IP - %d.%d.%d.%d\r\n", sn, multicast_ip[0], multicast_ip[1], multicast_ip[2], multicast_ip[3]);
53.         printf("%d:Multicast Group Port - %d\r\n", sn, multicast_port);
54. #endif
55.         break;
56.     default:
57.         break;
58.     }
59.     return 1;
60. }

When the program enters the udp_multicast function, it will execute a state machine, performing corresponding operations based on the state of the Socket.

When the Socket is in the SOCK_CLOSED state, the function will initialize the Socket and join the multicast group, then print the state of the Socket and the information of the multicast group.

When the Socket is in the SOCK_UDP state, the function will check if there is any data reception. If there is, it will print the data and send it back to the source address. After the function executes successfully, it returns 1.

8 Run results

After the burning routine was executed, the PHY link was first detected, then the DHCP process was used to obtain the network address result, and finally the UDP Multicast loopback test was conducted, as shown in the following figure:

 

Next, we will open a network debugging tool that supports the addition of UDP multicast functionality. When using this tool, the first step is to complete the necessary configuration operations, which include setting the parameters for listening to multicast and sending messages. After completing the above configuration, we send a message to the multicast group. At this point, you can observe that the serial port will print out the message we sent, and at the same time, a corresponding loopback message will be received in the multicast receiving area of the network debugging tool. The multicast loopback test process can run normally.

Note: If the network debugging tool does not support joining multicast, it will not receive the loopback data. Here, I have chosen an open-source project on gitcode.Link: UDP Multicast Debugging Tool.

9 Summary

This article introduces the principle, application scenarios and loopback testing method of implementing UDP multicast on the W55MH32 chip. It also demonstrates the specific implementation process through practical code. The next article will focus on the DNS routine, explaining its working principle and implementation method, helping you gain a deeper understanding of network communication. Stay tuned!

 

WIZnet is a non-fabrication semiconductor company founded in 1998. Its products include the Internet processor iMCU™, which adopts TOE (TCP/IP Offloading Engine) technology and is based on a unique patented fully hardwired TCP/IP. iMCU™ is designed for embedded Internet devices in various applications.

WIZnet has over 70 distributors worldwide, with offices in Hong Kong, South Korea, and the United States, providing technical support and product marketing.

The region managed by the Hong Kong office includes: Australia, India, Turkey, and Asia (excluding South Korea and Japan).

Documents
Comments Write