Wiznet makers

ronpang

Published May 16, 2026 ©

185 UCC

93 WCC

34 VAR

0 Contests

1 Followers

0 Following

Original Link

How to Resolve DNS with WIZnet W5500 on STM32F10x?

This STM32F10x maker project shows how to add DNS resolution to a WIZnet W5500 Ethernet application using WIZnet ioLibrary.

COMPONENTS
PROJECT DESCRIPTION

How to Resolve DNS with WIZnet W5500 on STM32F10x?

Summary

This STM32F10x maker project shows how to add DNS resolution to a WIZnet W5500 Ethernet application using WIZnet ioLibrary. The STM32 configures the W5500 over SPI, applies static network information, starts the DNS client on W5500 socket 0, resolves a domain name, and prints the returned IPv4 address through UART.

What the Project Does

The project is a DNS client example for an STM32F10x microcontroller connected to a WIZnet W5500 Ethernet controller. DNS is used to translate a human-readable domain name into an IP address, which is a required building block before maker projects can move from local LAN demos to HTTP clients, SNTP clients, MQTT clients, or other internet-facing applications.

The example follows a clear startup sequence: initialize the STM32 delay system, interrupt priority, UART, LED, timer, SPI1, W5500 reset pin, and W5500 interrupt pin; register W5500 SPI callbacks; reset the W5500; check the chip version register; wait for the PHY link; write static network settings; open socket 0; then call the DNS routine to resolve the configured domain name.

The article’s network configuration uses MAC 00:08:DC:11:11:11, local IP 192.168.1.199, subnet 255.255.255.0, gateway 192.168.1.1, DNS server 180.76.76.76, static IP mode, local port 4000, and the domain name www.baidu.com. The resolved IP is stored in domain_ip[4].

Where WIZnet Fits

The exact WIZnet product is W5500. In this architecture, W5500 is the Ethernet controller and socket engine between the STM32F10x firmware and the wired network. The STM32 does not implement the Ethernet MAC, PHY, or full TCP/IP stack by itself. Instead, it talks to W5500 through SPI and uses WIZnet ioLibrary functions for socket access, network configuration, and DNS handling.

W5500 is a hardwired TCP/IP stack internet controller with SPI access up to 80 MHz, embedded 10/100 Ethernet MAC and PHY, support for TCP, UDP, IPv4, ARP, ICMP, IGMP, and PPPoE, 8 independent sockets, and 32 KB internal Tx/Rx buffer memory. WIZnet also documents ioLibrary as an MCU-independent driver library that supports services including DHCP, DNS, MQTT, SNTP, TFTP, and HTTP Server.

For a maker build, this separation is useful. The STM32 firmware can stay focused on board bring-up and application flow, while W5500 handles the Ethernet-side transport and socket buffering. DNS then becomes a reusable block: once the board can resolve a domain name, the same platform can be extended into HTTP, SNTP, MQTT, or cloud-connected experiments.

Implementation Notes

File: wiz_platform.c
What it configures: W5500 SPI chip-select, single-byte SPI transfer, burst SPI transfer, reset, and DNS timing.
Why it matters: WIZnet ioLibrary is platform-independent, so the STM32-specific SPI and timing functions must be connected before the DNS client can use W5500 socket communication.

 
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 same platform layer configures TIM2 as a 1 ms interrupt source and calls DNS_time_handler() every 1000 ms. That timing path is important because DNS retry and timeout handling depend on a periodic timer.

File: Test_DNS.c
What it configures: W5500 socket 0 as the DNS client socket and runs domain-name resolution.
Why it matters: The DNS client needs a socket, a working DNS server IP, a query domain, a destination buffer for the resolved address, and retry handling.

 
DNS_init(0, buf);
wizchip_getnetinfo(&net_info);

switch (DNS_run(net_info.dns, domain_name, domain_ip))
{
    case DNS_RET_SUCCESS:
        printf("> Translated %s to %d.%d.%d.%d\r\n",
               domain_name, domain_ip[0], domain_ip[1],
               domain_ip[2], domain_ip[3]);
        break;
}
 

The article’s do_dns() routine initializes DNS on socket 0, reads the W5500 network information, calls DNS_run(), retries up to DNS_RETRY, and prints either the resolved IP address or a DNS failure message.

Practical Tips / Pitfalls

  • Verify SPI before DNS. The repository troubleshooting notes recommend checking whether SPI read/write works and whether the W5500 version register can be read correctly. 
  • Wait for PHY link before running DNS. The example polls CW_GET_PHYLINK and prints 10/100 Mbps and duplex information after link-up. 
  • Make sure the DNS server is reachable from the configured subnet. The article uses static IP mode, so local IP, gateway, subnet mask, and DNS server must match the actual LAN.
  • Keep one W5500 socket available for DNS. This example uses socket 0 for DNS resolution.
  • Call the DNS timer handler periodically. In this project, TIM2 calls DNS_time_handler() once per second.
  • Use UART logs during bring-up. The example prints reset, network configuration, PHY state, DNS success, and DNS failure messages.
  • Confirm the domain name buffer and output IP buffer are valid. The example stores the query in domain_name[] and the resolved address in domain_ip[4].

FAQ

Q: Why use WIZnet W5500 for DNS on STM32F10x?
A: W5500 provides the wired Ethernet interface, hardwired TCP/IP engine, socket resources, and internal buffers needed for UDP-based DNS traffic. The STM32 can run a small application flow around ioLibrary instead of maintaining the full Ethernet and TCP/IP stack in firmware.

Q: How does W5500 connect to STM32F10x in this project?
A: The example uses SPI1. PA5 is SCK, PA6 is MISO, PA7 is MOSI, PA4 is chip select, PC5 is W5500 reset, and PC4 is W5500 interrupt input.

Q: What role does W5500 play in this DNS project?
A: W5500 stores the local network configuration, maintains the wired Ethernet link, provides socket 0 for DNS communication, sends the DNS query to the configured DNS server, and returns the resolved IP address through the ioLibrary DNS routine.

Q: Can beginners follow this maker project?
A: Yes, if they already understand basic STM32 firmware, SPI wiring, UART debugging, and IPv4 settings. The example is maker-friendly because each layer is visible: hardware initialization, W5500 verification, PHY link check, static IP setup, DNS socket setup, and final domain resolution.

Q: What should be checked first if DNS resolution fails?
A: Check W5500 version-register access, PHY link status, static IP/subnet/gateway/DNS values, LAN cable, router reachability, socket allocation, and whether DNS_time_handler() is being called every second.

Source

Original article: CSDN, “测试W5500的第6步_使用ioLibrary库创建DNS,” 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. The repository describes 7.DNS as a DNS example and provides the STM32F10x W5500 example set.

WIZnet product reference: W5500 documentation and ioLibrary Driver documentation.

Tags

#W5500 #WIZnet #STM32F10x #STM32F103 #DNS #ioLibrary #Ethernet #SPI #EmbeddedC #Maker #NetworkStack #TCPIP

 

STM32F10x에서 WIZnet W5500으로 DNS를 해석하는 방법은?

요약

이 STM32F10x 메이커 프로젝트는 WIZnet W5500 이더넷 애플리케이션에 WIZnet ioLibrary를 사용해 DNS 해석 기능을 추가하는 예제입니다. STM32는 SPI로 W5500을 설정하고, 고정 네트워크 정보를 적용한 뒤, W5500 소켓 0에서 DNS 클라이언트를 시작합니다. 이후 도메인 이름을 해석하고 반환된 IPv4 주소를 UART로 출력합니다.

프로젝트가 하는 일

이 프로젝트는 WIZnet W5500 이더넷 컨트롤러가 연결된 STM32F10x 마이크로컨트롤러에서 DNS 클라이언트를 구현하는 예제입니다. DNS는 사람이 읽기 쉬운 도메인 이름을 IP 주소로 변환하는 기능입니다. 로컬 LAN 데모를 넘어 HTTP 클라이언트, SNTP 클라이언트, MQTT 클라이언트, 인터넷 연결형 메이커 프로젝트로 확장하려면 필요한 기본 구성 요소입니다.

예제의 시작 흐름은 명확합니다. STM32 지연 시스템, 인터럽트 우선순위, UART, LED, 타이머, SPI1, W5500 리셋 핀, W5500 인터럽트 핀을 초기화합니다. 이후 W5500 SPI 콜백을 등록하고, W5500을 리셋하며, 칩 버전 레지스터를 확인합니다. PHY 링크가 연결될 때까지 대기한 뒤 고정 네트워크 정보를 기록하고, 소켓 0을 열어 DNS 루틴으로 설정된 도메인 이름을 해석합니다.

원문 예제의 네트워크 설정은 MAC 00:08:DC:11:11:11, 로컬 IP 192.168.1.199, 서브넷 255.255.255.0, 게이트웨이 192.168.1.1, DNS 서버 180.76.76.76, 고정 IP 모드, 로컬 포트 4000, 도메인 이름 www.baidu.com을 사용합니다. 해석된 IP 주소는 domain_ip[4]에 저장됩니다.

WIZnet이 들어가는 위치

이 프로젝트에서 사용되는 WIZnet 제품은 W5500입니다. 이 구조에서 W5500은 STM32F10x 펌웨어와 유선 네트워크 사이에 위치하는 이더넷 컨트롤러이자 소켓 엔진입니다. STM32가 Ethernet MAC, PHY, 전체 TCP/IP 스택을 직접 구현하지 않고, SPI를 통해 W5500과 통신하며 WIZnet ioLibrary 함수로 소켓 접근, 네트워크 설정, DNS 처리를 수행합니다.

W5500은 하드웨어 TCP/IP 스택 기반 인터넷 컨트롤러이며, 최대 80 MHz SPI 접근, 내장 10/100 Ethernet MAC 및 PHY, TCP, UDP, IPv4, ARP, ICMP, IGMP, PPPoE 지원, 8개 독립 소켓, 32 KB 내부 Tx/Rx 버퍼를 제공합니다. WIZnet ioLibrary는 MCU 독립형 드라이버 라이브러리이며 DHCP, DNS, MQTT, SNTP, TFTP, HTTP Server 등의 서비스를 지원합니다.

메이커 프로젝트에서는 이 분리가 유용합니다. STM32 펌웨어는 보드 초기화와 애플리케이션 흐름에 집중하고, W5500은 이더넷 전송과 소켓 버퍼링을 담당합니다. DNS는 재사용 가능한 네트워크 구성 요소가 됩니다. 보드가 도메인 이름을 해석할 수 있으면 같은 플랫폼을 HTTP, SNTP, MQTT, 클라우드 연결 실험으로 확장할 수 있습니다.

구현 참고 사항

파일: wiz_platform.c
설정 내용: W5500 SPI 칩 셀렉트, 단일 바이트 SPI 전송, 버스트 SPI 전송, 리셋, DNS 타이밍
중요한 이유: WIZnet ioLibrary는 플랫폼 독립 구조이므로, DNS 클라이언트가 W5500 소켓 통신을 사용하기 전에 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);
}
 

같은 플랫폼 계층은 TIM2를 1 ms 인터럽트 소스로 설정하고, 1000 ms마다 DNS_time_handler()를 호출합니다. 이 타이밍 경로는 DNS 재시도와 타임아웃 처리에 필요합니다.

파일: Test_DNS.c
설정 내용: W5500 소켓 0을 DNS 클라이언트 소켓으로 설정하고 도메인 이름 해석 실행
중요한 이유: DNS 클라이언트는 소켓, 동작 가능한 DNS 서버 IP, 질의할 도메인, 해석 결과를 저장할 버퍼, 재시도 처리가 필요합니다.

 
DNS_init(0, buf);
wizchip_getnetinfo(&net_info);

switch (DNS_run(net_info.dns, domain_name, domain_ip))
{
    case DNS_RET_SUCCESS:
        printf("> Translated %s to %d.%d.%d.%d\r\n",
               domain_name, domain_ip[0], domain_ip[1],
               domain_ip[2], domain_ip[3]);
        break;
}
 

원문 글의 do_dns() 루틴은 소켓 0에서 DNS를 초기화하고, W5500 네트워크 정보를 읽은 뒤 DNS_run()을 호출합니다. 이후 DNS_RETRY 횟수까지 재시도하며, 성공하면 해석된 IP 주소를 출력하고 실패하면 DNS 실패 메시지를 출력합니다.

실무 팁 / 주의점

  • DNS를 확인하기 전에 SPI부터 검증해야 합니다. SPI 읽기/쓰기가 정상이고 W5500 버전 레지스터를 올바르게 읽을 수 있어야 합니다.
  • DNS 실행 전에 PHY 링크가 연결될 때까지 기다려야 합니다. 예제는 CW_GET_PHYLINK를 폴링하고 링크 연결 후 10/100 Mbps 및 듀플렉스 정보를 출력합니다.
  • DNS 서버가 설정된 서브넷에서 접근 가능한지 확인해야 합니다. 이 예제는 고정 IP 모드를 사용하므로 로컬 IP, 게이트웨이, 서브넷 마스크, DNS 서버가 실제 LAN 환경과 맞아야 합니다.
  • DNS용 W5500 소켓 하나를 확보해야 합니다. 이 예제는 DNS 해석에 소켓 0을 사용합니다.
  • DNS 타이머 핸들러를 주기적으로 호출해야 합니다. 이 프로젝트에서는 TIM2가 1초마다 DNS_time_handler()를 호출합니다.
  • 초기 bring-up 단계에서는 UART 로그를 사용하는 것이 좋습니다. 예제는 리셋, 네트워크 설정, PHY 상태, DNS 성공, DNS 실패 메시지를 출력합니다.
  • 도메인 이름 버퍼와 출력 IP 버퍼가 유효한지 확인해야 합니다. 예제는 질의 도메인을 domain_name[]에 저장하고, 해석된 주소를 domain_ip[4]에 저장합니다.

FAQ

Q: STM32F10x에서 DNS를 구현할 때 왜 WIZnet W5500을 사용하나요?
A: W5500은 UDP 기반 DNS 트래픽에 필요한 유선 이더넷 인터페이스, 하드웨어 TCP/IP 엔진, 소켓 자원, 내부 버퍼를 제공합니다. STM32는 전체 Ethernet 및 TCP/IP 스택을 펌웨어에서 유지하지 않고 ioLibrary 중심의 작은 애플리케이션 흐름을 구성할 수 있습니다.

Q: 이 프로젝트에서 W5500은 STM32F10x에 어떻게 연결되나요?
A: 예제는 SPI1을 사용합니다. PA5는 SCK, PA6은 MISO, PA7은 MOSI, PA4는 칩 셀렉트, PC5는 W5500 리셋, PC4는 W5500 인터럽트 입력으로 사용됩니다.

Q: 이 DNS 프로젝트에서 W5500은 어떤 역할을 하나요?
A: W5500은 로컬 네트워크 설정을 저장하고, 유선 이더넷 링크를 유지하며, DNS 통신을 위한 소켓 0을 제공합니다. 설정된 DNS 서버로 DNS 질의를 보내고, ioLibrary DNS 루틴을 통해 해석된 IP 주소를 반환합니다.

Q: 초보자도 이 메이커 프로젝트를 따라할 수 있나요?
A: 가능합니다. 다만 기본 STM32 펌웨어, SPI 배선, UART 디버깅, IPv4 설정을 이해하고 있으면 더 수월합니다. 이 예제는 하드웨어 초기화, W5500 확인, PHY 링크 확인, 고정 IP 설정, DNS 소켓 설정, 최종 도메인 해석까지 각 계층이 명확히 드러나 있어 메이커 프로젝트에 적합합니다.

Q: DNS 해석이 실패할 때 무엇을 먼저 확인해야 하나요?
A: W5500 버전 레지스터 접근, PHY 링크 상태, 고정 IP·서브넷·게이트웨이·DNS 값, LAN 케이블, 라우터 접근성, 소켓 할당, DNS_time_handler()가 1초마다 호출되는지 여부를 먼저 확인해야 합니다.

출처

Original article: CSDN, “测试W5500的第6步_使用ioLibrary库创建DNS,” 2025-05-23 게시, CC BY-SA 4.0로 표시됨.
https://blog.csdn.net/weixin_42550185/article/details/148168191?spm=1001.2014.3001.5502

Source repository referenced by the article: WIZnet HK, STM32F10x_W5500_Examples, Mulan PSL v2 라이선스. 저장소는 7.DNS를 DNS 예제로 설명하며 STM32F10x W5500 예제 세트를 제공합니다.
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 #DNS #ioLibrary #Ethernet #SPI #EmbeddedC #Maker #NetworkStack #TCPIP

 
 
 
Documents
Comments Write