Hardwired TCP/IP Chapter 20: W55MH32 WOL Example
Hardwired TCP/IP Chapter 20: W55MH32 WOL Example

Hardwired TCP/IP Chapter 20: W55MH32 WOL Example
In this article, we will provide a detailed explanation on how to implement the Wake-on-LAN function on the W55MH32 chip.
Other network protocols used in this routine, such as DHCP, please refer to the relevant sections. Regarding the initialization process of the W55MH32, please also refer to the Network Install section. We will not elaborate on it here.
1 WOL Introduction
WOL, or Wake-on-LAN, is a network standard protocol used to remotely wake up computers via the network. It enables the activation of devices that are in a dormant or powered-off state by sending specific network packets (known as "magic packets").
2 WOL Features
- Simplicity: The core of WOL is the Magic Packet, whose format is very simple and fixed. The Magic Packet consists of 102 bytes, with the first 6 bytes being fixed as 0xFF, and the following part being the MAC address of the target device repeated 16 times.
- Device Standby Wakeup: WOL allows devices to enter a low-power state when not in use, such as standby, sleep, or shutdown. When there is a remote wake-up requirement, the device can quickly recover to the normal operating state by receiving the Magic Packet, meeting the user's usage needs.
- Broadcast Mechanism: The Magic Packet is usually sent in the form of UDP broadcast. Even if the device's IP address is unknown or there are multiple devices, the target device can be found through the broadcast packet.
- High Security: The WOL protocol identifies the target device based on the MAC address. Only when the MAC address in the Magic Packet matches the MAC address of the network card itself, will the device be awakened.
3 WOL application scenarios
Next, let's take a look at what operations and applications can be accomplished using the WOL protocol on the W55MH32?
- Remote waking up of embedded devices: The devices can be awakened from standby mode via the network to resume their working state, such as industrial equipment and smart home devices.
- Smart gateway and home automation: Smart home gateway devices can be awakened by magic packets to achieve control and management.
- Batch waking up of network devices: Administrators can wake up multiple devices for maintenance and upgrades through WOL technology.
- Waking up of low-power IoT devices: IoT devices are awakened in low-power mode to perform tasks, thereby extending battery life.
- Remote management of embedded systems: Devices can be awakened in a remote environment for configuration, management, or troubleshooting. If the target device matches, that device will perform the waking-up operation and return to the active state.
4 The basic workflow of the WOL protocol
1. Enable WOL function: The awakened device needs to enable the WOL function in the BIOS or enable this function in the operating system to ensure that the network interface card supports and enables WOL.
2. Enable UDP Socket: The awakened device usually needs to enable a UDP Socket to listen on a port for receiving magic packets (Magic Packet) from the network.
3. Receive Magic Packet: When the device receives a standard magic packet, the packet contains the MAC address of the target device. The device compares the MAC address to determine whether it should be awakened.
4. Wake-up Operation: If the MAC address in the magic packet matches that of the target device, the device will perform the wake-up operation and return to the active state.
5 The implementation process
Next, we conduct the WOL remote wake-up test on W55MH32.
Note: The test instance requires that the PC and W55MH32 be in the same network segment.
The wol_run() function is used to handle operations related to the UDP Socket, to listen for and process the network wake-up magic packets. This function needs to be called in the main loop, as shown below:
1. while (1)
2. {
3. wol_run(SOCKET_ID, ethernet_buf, local_port);
4. }
The content of the wol_run() function is as follows:
1. void wol_run(uint8_t sn, uint8_t *buf, uint16_t local_port)
2. { switoh (getSn_SR(sn))
3. {
4. case SOCK_UDP;
5. if(get Sn_IR(sn)& Sn_ IR_ RECV)
6. {
7. setSn_IR(sn, Sn_IR RECV);
8. }
9. if(getIR()& 0x10)// Received WOL Magic packet based on UDP
10. {
11. printf("get wake on line\r\n");
12. setIR(0x10);
13. }
14. break;
15. case SOCK_CLOSED;
16. socket (sn, Sn_IR_UDP, local_port, 0);
17. setTIR(II_IR4);//Oper WOL nagic pack interrupt
18. setIR(IR_WOL);//Receive WOL packets
19. printf("%d:Opened, UDP WOL, port [Xd]\r\n", an, local_port);
20. break;
21. }
22. }
The wol_run function requires three parameters to be passed in, namely the socket number, socket cache, and source port number.
The wol_run() function continuously checks the status of the socket. When the socket is in the SOCK_CLOSED state, it will create a UDP mode socket, enable the WOL function and interrupt. When the socket is in the SOCK_UDP mode, it only needs to continuously monitor the interrupt register. When the W55MH32 receives the magic packet, the MP bit (0x10) in the IR register takes effect, and at this point, the wake-up operation can be performed.
6 Run results
After the burning routine is executed, the PHY link is first detected, then the network information is set through DHCP, and the magic packet is sent through the network debugging assistant to achieve remote wake-up. When using the sockettest network assistant to send hex format data, the "Enable $# command" option needs to be checked and a $ symbol should be added before each data, without any spaces. Spaces will be converted to 0X20.
Note: (If using other network debugging assistants to send HEX format is acceptable) As shown in the figure below:
7 Summary
This article explains how to implement the Network Wake-Up (WOL) function on the W55MH32 chip. Through practical examples, it demonstrates the complete process of setting up a UDP Socket to listen for magic packets, receiving and processing the magic packets to achieve device wake-up. The article details the concept, features, application scenarios, and basic workflow of WOL, helping readers understand its practical application value in remote device management and energy conservation.
The next article will focus on the Low Power mode, analyzing methods for adjusting the PHY rate, and adjusting different PHY rates according to the scenario to achieve the goal of low power consumption. 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).