Wiznet makers

ronpang

Published June 05, 2026 ©

192 UCC

93 WCC

34 VAR

0 Contests

1 Followers

0 Following

Original Link

How to Implement DHCP Addressing with WIZnet W5500 on AI8051U?

This AI8051U Industrial IoT project uses the WIZnet W5500 Ethernet controller to obtain network configuration automatically through DHCP.

COMPONENTS
PROJECT DESCRIPTION

How to Implement DHCP Addressing with WIZnet W5500 on AI8051U?

Summary

This AI8051U Industrial IoT project uses the WIZnet W5500 Ethernet controller to obtain network configuration automatically through DHCP. The AI8051U firmware controls W5500 over SPI, while W5500 provides the wired Ethernet MAC/PHY, hardwired TCP/IP stack, socket engine, and packet buffers required for DHCP Discover, Offer, Request, and Acknowledgment traffic on a local industrial network. The public CSDN page confirms the learning goals: understanding DHCP IP assignment, learning the DHCP process, and studying the DHCP program.

What the Project Does

The project demonstrates DHCP-based IP provisioning for an AI8051U microcontroller connected to a WIZnet W5500 Ethernet controller. DHCP lets an embedded device receive its IP address and related network information from a DHCP server instead of relying on a hard-coded static address. The article describes DHCP as Dynamic Host Configuration Protocol and explains that a DHCP server assigns IP addresses to network devices.

The network sequence begins with DHCP Discover. The client broadcasts a request from source IP 0.0.0.0 to destination IP 255.255.255.255, using UDP client port 68 and server port 67. The DHCP server then responds with an address offer, and the later DHCP Request and ACK steps complete the lease process.

For Industrial IoT, this solves a practical deployment problem. A controller, sensor node, gateway, or service interface can be connected to a customer LAN without manually assigning IP addresses during installation. That reduces duplicate-IP errors, subnet mismatch, wrong gateway settings, and field-support time when devices are installed in multiple plants or cabinets.

Where WIZnet Fits

The exact WIZnet product is W5500. In this project, W5500 is the wired Ethernet and TCP/IP offload device between the AI8051U firmware and the LAN. The AI8051U handles SPI access, board initialization, DHCP task scheduling, timeout policy, UART diagnostics, and application behavior. W5500 handles Ethernet MAC/PHY operation, UDP/IP packet transport, socket state, and internal packet buffering.

W5500 is suitable for this role because it is a hardwired TCP/IP Ethernet controller with SPI access, embedded 10/100 Ethernet MAC/PHY, 8 independent sockets, and internal Tx/Rx buffer memory. WIZnet also provides ioLibrary, an Internet Offload Library for WIZnet TCP/IP chips including W5500, with Berkeley-style socket APIs and application protocol components such as DHCP.

At the register and firmware boundary, DHCP depends on several W5500-controlled areas: MAC address, socket allocation, UDP send/receive state, PHY link status, and the final network registers for local IP, gateway, subnet mask, and DNS. The official DHCP implementation updates WIZchip network settings after assignment, including local IP, subnet mask, and gateway, and stores assigned DNS information for later use.

Implementation Notes

The accessible CSDN article confirms the W5500 DHCP topic and protocol learning goals, but the full code section is behind subscription access. Therefore, the code below is not copied from the project.

Conceptual integration example based on WIZnet ioLibrary

 
#include "wizchip_conf.h"
#include "socket.h"
#include "dhcp.h"

#define DHCP_SOCKET  0

static uint8_t dhcp_buf[1024];

void w5500_platform_init(void)
{
    uint8_t tx_size[8] = {2,2,2,2,2,2,2,2};
    uint8_t rx_size[8] = {2,2,2,2,2,2,2,2};

    reg_wizchip_cs_cbfunc(w5500_select, w5500_deselect);
    reg_wizchip_spi_cbfunc(w5500_spi_read, w5500_spi_write);

    wizchip_init(tx_size, rx_size);

    DHCP_init(DHCP_SOCKET, dhcp_buf);
}
 

This setup represents the required layering. AI8051U firmware must first provide W5500 chip-select and SPI read/write callbacks, then initialize W5500 socket buffers, then start the DHCP client on a selected socket. WIZnet’s DHCP header defines DHCP_init(), DHCP_run(), DHCP_time_handler(), callback registration, and getter functions for assigned IP, gateway, subnet, DNS, and lease time.

 
void network_task(void)
{
    uint8_t state = DHCP_run();

    if (state == DHCP_IP_LEASED) {
        uint8_t ip[4], gw[4], sn[4], dns[4];

        getIPfromDHCP(ip);
        getGWfromDHCP(gw);
        getSNfromDHCP(sn);
        getDNSfromDHCP(dns);

        /* Store, print, or apply the assigned network parameters here. */
    }
}
 

The firmware must also call DHCP_time_handler() from a 1-second timer. The official ioLibrary DHCP header states that the timer handler should be registered to the system’s 1-second tick, and DHCP_run() is intended to be called from the main task.

Practical Tips / Pitfalls

  • Verify W5500 SPI register access before debugging DHCP. A DHCP failure is meaningless if chip-select timing, SPI mode, or byte transfer is unstable.
  • Check PHY link before starting DHCP. A disconnected cable or inactive switch port will make DHCP appear to fail at the protocol layer.
  • Use a valid MAC address. DHCP servers identify clients using the hardware address, so duplicate or invalid MAC values can create hard-to-reproduce field issues.
  • Reserve one W5500 socket for DHCP during provisioning. DHCP uses UDP ports 67 and 68, so socket allocation must be planned before application sockets are started. 
  • Add a timeout and fallback policy. Industrial firmware should decide whether to retry DHCP, enter service mode, use a stored static IP, or report an installation fault.
  • Log assigned IP, gateway, subnet, DNS, lease state, retry count, and PHY link state. These fields are critical during plant-floor installation and service.
  • Test router reboot, cable removal, duplicate IP, and lease renewal. DHCP success at power-up does not prove long-term network recovery behavior.

FAQ

Q: Why use WIZnet W5500 for DHCP on AI8051U?
A: W5500 provides the wired Ethernet MAC/PHY, hardwired TCP/IP engine, UDP socket path, and packet buffers needed for DHCP traffic. This lets AI8051U firmware focus on DHCP state handling, diagnostics, and device behavior instead of maintaining a full TCP/IP stack in MCU software.

Q: How does W5500 connect to the AI8051U platform?
A: W5500 connects as an SPI peripheral using chip select, SCLK, MOSI, and MISO. A robust industrial design should also connect reset and interrupt pins so firmware can recover the Ethernet controller and respond to socket or link events without constant polling.

Q: What role does W5500 play in this DHCP project?
A: W5500 provides the Ethernet transport for DHCP Discover, Offer, Request, and ACK traffic. The AI8051U runs the DHCP client logic through ioLibrary, while W5500 handles the wired UDP/IP transport and stores the final network configuration used by later application sockets.

Q: Can beginners follow this project?
A: Yes, if they already understand embedded C, SPI, UART logging, IPv4 addressing, and the purpose of DHCP. The project is a good bridge between static-IP W5500 examples and deployable Industrial IoT firmware because it introduces lease assignment, retry handling, timer service, and network diagnostics.

Q: How does W5500 compare with an LwIP-based DHCP design?
A: With W5500, the Ethernet MAC/PHY, TCP/IP processing, sockets, and packet buffers are handled by the Ethernet controller, so the AI8051U mainly drives SPI and DHCP/application state. With LwIP, the MCU runs a software TCP/IP stack and owns more of the packet buffers, timers, network-interface driver, and protocol integration. LwIP gives deeper software control, while W5500 keeps the network-stack boundary simpler for small industrial controllers.

Source

Original article: CSDN, “[AI8051U入门第十五步]W5500实现DHCP自动获取IP.” The accessible page confirms the DHCP learning goals and DHCP Discover details, while the public summary confirms Wireshark-based DHCP packet analysis and code discussion of DHCP state machine, message type, and options. Full implementation code is not publicly visible from the accessible page.

WIZnet product reference: W5500 documentation.

WIZnet driver reference: ioLibrary Driver and DHCP API files.

License: CSDN article license is not clearly visible in the accessible page text. WIZnet ioLibrary DHCP files include a permissive redistribution notice in the source header.

Tags

#W5500 #WIZnet #AI8051U #DHCP #Ethernet #SPI #ioLibrary #IndustrialIoT #NetworkStack #HardwareWiring #Registers #Firmware #Performance #EmbeddedC

AI8051U에서 WIZnet W5500으로 DHCP 주소 할당을 구현하는 방법은?

요약

이 AI8051U Industrial IoT 프로젝트는 WIZnet W5500 이더넷 컨트롤러를 사용해 DHCP로 네트워크 설정을 자동으로 획득합니다. AI8051U 펌웨어는 SPI로 W5500을 제어하고, W5500은 로컬 산업용 네트워크에서 DHCP Discover, Offer, Request, Acknowledgment 트래픽을 처리하는 데 필요한 유선 Ethernet MAC/PHY, 하드웨어 TCP/IP 스택, 소켓 엔진, 패킷 버퍼를 제공합니다. 공개 CSDN 페이지에서는 DHCP IP 할당 이해, DHCP 절차 학습, DHCP 프로그램 학습이 목표임을 확인할 수 있습니다.

프로젝트가 하는 일

이 프로젝트는 WIZnet W5500 이더넷 컨트롤러가 연결된 AI8051U 마이크로컨트롤러에서 DHCP 기반 IP 프로비저닝을 구현합니다. DHCP를 사용하면 임베디드 장치가 고정 IP에 의존하지 않고 DHCP 서버로부터 IP 주소와 관련 네트워크 정보를 받을 수 있습니다. 원문은 DHCP를 Dynamic Host Configuration Protocol로 설명하며, DHCP 서버가 네트워크 장치에 IP 주소를 할당한다고 설명합니다.

네트워크 절차는 DHCP Discover에서 시작됩니다. 클라이언트는 source IP 0.0.0.0에서 destination IP 255.255.255.255로 요청을 브로드캐스트하며, UDP client port 68과 server port 67을 사용합니다. 이후 DHCP 서버가 주소 offer를 응답하고, DHCP Request 및 ACK 단계가 이어지면서 lease 절차가 완료됩니다.

Industrial IoT 환경에서는 이 방식이 실제 설치 문제를 줄입니다. 컨트롤러, 센서 노드, 게이트웨이, 서비스 인터페이스를 고객 LAN에 연결할 때 수동 IP 설정 없이 네트워크에 투입할 수 있습니다. 이로 인해 중복 IP, 서브넷 불일치, 잘못된 게이트웨이 설정, 여러 공장이나 제어반에 장치를 설치할 때 발생하는 현장 지원 시간을 줄일 수 있습니다.

WIZnet이 들어가는 위치

이 프로젝트에서 사용되는 WIZnet 제품은 W5500입니다. W5500은 AI8051U 펌웨어와 LAN 사이에 위치하는 유선 이더넷 및 TCP/IP 오프로딩 장치입니다. AI8051U는 SPI 접근, 보드 초기화, DHCP task scheduling, timeout policy, UART diagnostics, application behavior를 담당합니다. W5500은 Ethernet MAC/PHY 동작, UDP/IP packet transport, socket state, internal packet buffering을 담당합니다.

W5500은 이 역할에 적합합니다. W5500은 SPI 접근, 내장 10/100 Ethernet MAC/PHY, 8개 독립 소켓, 내부 Tx/Rx 버퍼 메모리를 제공하는 하드웨어 TCP/IP 이더넷 컨트롤러입니다. WIZnet은 W5500을 포함한 WIZnet TCP/IP 칩을 위한 Internet Offload Library인 ioLibrary도 제공합니다. 이 라이브러리는 Berkeley-style socket API와 DHCP 같은 애플리케이션 프로토콜 구성 요소를 포함합니다.

레지스터와 펌웨어 경계에서 DHCP는 여러 W5500 제어 영역에 의존합니다. 여기에는 MAC 주소, 소켓 할당, UDP 송수신 상태, PHY 링크 상태, 그리고 최종 local IP, gateway, subnet mask, DNS 네트워크 레지스터가 포함됩니다. 공식 DHCP 구현은 주소 할당 이후 local IP, subnet mask, gateway 같은 WIZchip 네트워크 설정을 갱신하고, 이후 사용을 위해 DNS 정보도 저장합니다.

구현 참고 사항

접근 가능한 CSDN 글에서는 W5500 DHCP 주제와 프로토콜 학습 목표를 확인할 수 있지만, 전체 코드 섹션은 구독 접근 뒤에 있습니다. 따라서 아래 코드는 원문 프로젝트에서 복사한 코드가 아닙니다.

WIZnet ioLibrary 기반 개념적 통합 예제

 
#include "wizchip_conf.h"
#include "socket.h"
#include "dhcp.h"

#define DHCP_SOCKET  0

static uint8_t dhcp_buf[1024];

void w5500_platform_init(void)
{
    uint8_t tx_size[8] = {2,2,2,2,2,2,2,2};
    uint8_t rx_size[8] = {2,2,2,2,2,2,2,2};

    reg_wizchip_cs_cbfunc(w5500_select, w5500_deselect);
    reg_wizchip_spi_cbfunc(w5500_spi_read, w5500_spi_write);

    wizchip_init(tx_size, rx_size);

    DHCP_init(DHCP_SOCKET, dhcp_buf);
}
 

이 설정은 필요한 계층 구조를 보여줍니다. AI8051U 펌웨어는 먼저 W5500 chip-select와 SPI read/write callback을 제공해야 합니다. 이후 W5500 socket buffer를 초기화하고, 선택한 소켓에서 DHCP client를 시작합니다. WIZnet DHCP header는 DHCP_init(), DHCP_run(), DHCP_time_handler(), callback registration, 그리고 할당된 IP, gateway, subnet, DNS, lease time을 읽는 getter 함수를 정의합니다.

 
void network_task(void)
{
    uint8_t state = DHCP_run();

    if (state == DHCP_IP_LEASED) {
        uint8_t ip[4], gw[4], sn[4], dns[4];

        getIPfromDHCP(ip);
        getGWfromDHCP(gw);
        getSNfromDHCP(sn);
        getDNSfromDHCP(dns);

        /* 할당된 네트워크 파라미터를 저장, 출력, 적용한다. */
    }
}
 

펌웨어는 1초 타이머에서 DHCP_time_handler()도 호출해야 합니다. 공식 ioLibrary DHCP header는 timer handler를 시스템의 1초 tick에 등록해야 하며, DHCP_run()은 main task에서 호출하는 구조를 전제로 합니다.

실무 팁 / 주의점

  • DHCP를 디버깅하기 전에 W5500 SPI 레지스터 접근을 먼저 검증해야 합니다. chip-select timing, SPI mode, byte transfer가 불안정하면 DHCP 실패 분석은 의미가 없습니다.
  • DHCP를 시작하기 전에 PHY link를 확인해야 합니다. 케이블이 연결되지 않았거나 switch port가 비활성 상태이면 프로토콜 계층 문제처럼 보일 수 있습니다.
  • 유효한 MAC 주소를 사용해야 합니다. DHCP 서버는 hardware address로 client를 식별하므로, 중복되거나 잘못된 MAC 값은 재현하기 어려운 현장 문제를 만들 수 있습니다.
  • 프로비저닝 중에는 W5500 소켓 하나를 DHCP용으로 예약해야 합니다. DHCP는 UDP port 6768을 사용하므로, 애플리케이션 소켓을 시작하기 전에 소켓 할당을 계획해야 합니다.
  • timeout 및 fallback policy를 추가해야 합니다. 산업용 펌웨어는 DHCP 재시도, service mode 진입, 저장된 static IP 사용, 설치 오류 보고 중 어떤 동작을 할지 결정해야 합니다.
  • 할당된 IP, gateway, subnet, DNS, lease state, retry count, PHY link state를 로그로 남겨야 합니다. 이 값들은 공장 설치 및 서비스 과정에서 중요합니다.
  • router reboot, cable removal, duplicate IP, lease renewal을 테스트해야 합니다. 전원 인가 시 DHCP가 성공했다고 해서 장기적인 네트워크 복구 동작이 검증된 것은 아닙니다.

FAQ

Q: AI8051U에서 DHCP를 구현할 때 왜 WIZnet W5500을 사용하나요?
A: W5500은 DHCP 트래픽에 필요한 유선 Ethernet MAC/PHY, 하드웨어 TCP/IP 엔진, UDP 소켓 경로, 패킷 버퍼를 제공합니다. AI8051U 펌웨어는 전체 TCP/IP 스택을 MCU 소프트웨어로 유지하지 않고 DHCP 상태 처리, 진단, 장치 동작에 집중할 수 있습니다.

Q: W5500은 AI8051U 플랫폼에 어떻게 연결되나요?
A: W5500은 chip select, SCLK, MOSI, MISO를 사용하는 SPI 주변장치로 연결됩니다. 견고한 산업용 설계에서는 reset과 interrupt pin도 연결해 펌웨어가 Ethernet controller를 복구하고 지속적인 polling 없이 socket 또는 link event에 반응할 수 있게 하는 것이 좋습니다.

Q: 이 DHCP 프로젝트에서 W5500은 어떤 역할을 하나요?
A: W5500은 DHCP Discover, Offer, Request, ACK 트래픽을 위한 Ethernet 전송 경로를 제공합니다. AI8051U는 ioLibrary를 통해 DHCP client logic을 실행하고, W5500은 유선 UDP/IP 전송과 이후 애플리케이션 소켓이 사용할 최종 네트워크 설정 저장을 담당합니다.

Q: 초보자도 이 프로젝트를 따라갈 수 있나요?
A: embedded C, SPI, UART logging, IPv4 addressing, DHCP의 목적을 이해하고 있다면 따라갈 수 있습니다. 이 프로젝트는 static-IP W5500 예제와 실제 배포 가능한 Industrial IoT 펌웨어 사이를 연결하는 좋은 단계입니다. lease assignment, retry handling, timer service, network diagnostics를 함께 다루기 때문입니다.

Q: W5500 방식은 LwIP 기반 DHCP 설계와 어떻게 다른가요?
A: W5500을 사용하면 Ethernet MAC/PHY, TCP/IP 처리, 소켓, 패킷 버퍼가 Ethernet controller 내부에서 처리되므로 AI8051U는 주로 SPI와 DHCP/application state를 구동합니다. LwIP를 사용하면 MCU가 software TCP/IP stack을 실행하고, packet buffer, timer, network-interface driver, protocol integration을 더 많이 담당합니다. LwIP는 software control이 더 깊고, W5500은 소형 산업용 컨트롤러에서 network-stack boundary를 더 단순하게 만듭니다.

출처

Original article: CSDN, “[AI8051U入门第十五步]W5500实现DHCP自动获取IP.” 접근 가능한 페이지에서는 DHCP 학습 목표와 DHCP Discover 세부 사항을 확인할 수 있으며, 공개 요약에서는 Wireshark 기반 DHCP packet analysis와 DHCP state machine, message type, options 관련 코드 설명을 확인할 수 있습니다. 전체 구현 코드는 공개 페이지에서 확인할 수 없습니다.
https://blog.csdn.net/sinat_58149788/article/details/149881451

WIZnet product reference: W5500 documentation.
https://docs.wiznet.io/Product/Chip/Ethernet/W5500/datasheet

WIZnet driver reference: ioLibrary Driver and DHCP API files.
https://github.com/Wiznet/ioLibrary_Driver

License: CSDN article license is not clearly visible in the accessible page text. WIZnet ioLibrary DHCP files include a permissive redistribution notice in the source header.

태그

#W5500 #WIZnet #AI8051U #DHCP #Ethernet #SPI #ioLibrary #IndustrialIoT #NetworkStack #HardwareWiring #Registers #Firmware #Performance #EmbeddedC

Documents
Comments Write