LWIP 未在 WT32_ETH01 板上发送 DHCP 请求

问题描述 投票:0回答:1

我正在 WT32_ETH01 上运行 ESP-IDF 示例 ethernet-basic。设置一些选项后,我让板连接到物理层。不幸的是,它没有从我的路由器获取 IP 地址。

为了排除网络问题,我在笔记本电脑上运行 tftpd64 DHCP 服务器,首先连接另一台笔记本电脑来测试 DHCP(它获得了 IP),然后连接 WT32,它没有获得 IP。 当我运行 Wireshark 查看流量时,我注意到 WT32 没有发送任何内容,它只检测来自 DHCP 主机的消息。

我已经被困了好几天了,试图弄清楚为什么它没有发送任何东西。我对以太网和 DHCP 相当缺乏经验,所以我希望有人能给我指出正确的方向,任何建议都非常感激。

从串行输出:

I (31) boot: ESP-IDF v5.1.1-dirty 2nd stage bootloader
I (31) boot: compile time Sep 25 2023 17:17:25        
I (31) boot: Multicore bootloader
I (36) boot: chip revision: v1.1
I (39) boot.esp32: SPI Speed      : 40MHz
I (44) boot.esp32: SPI Mode       : DIO
I (49) boot.esp32: SPI Flash Size : 2MB
I (53) boot: Enabling RNG early entropy source...
I (59) boot: Partition Table:
I (62) boot: ## Label            Usage          Type ST Offset   Length
I (69) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (77) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (84) boot:  2 factory          factory app      00 00 00010000 00100000
I (92) boot: End of partition table
I (96) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=15898h ( 88216) map
I (136) esp_image: segment 1: paddr=000258c0 vaddr=3ffb0000 size=021c8h (  8648) load
I (140) esp_image: segment 2: paddr=00027a90 vaddr=40080000 size=08588h ( 34184) load
I (156) esp_image: segment 3: paddr=00030020 vaddr=400d0020 size=2a230h (172592) map
I (219) esp_image: segment 4: paddr=0005a258 vaddr=40088588 size=04398h ( 17304) load
I (233) boot: Loaded app from partition at offset 0x10000
I (233) boot: Disabling RNG early entropy source...
I (244) cpu_start: Multicore app
I (245) cpu_start: Pro cpu up.
I (245) cpu_start: Starting app cpu, entry point is 0x40081204
0x40081204: call_start_cpu1 at C:/Espressif/frameworks/esp-idf-v5.1.1/components/esp_system/port/cpu_start.c:154

I (0) cpu_start: App cpu up.
I (263) cpu_start: Pro cpu start user code
I (263) cpu_start: cpu freq: 160000000 Hz
I (263) cpu_start: Application information:
I (267) cpu_start: Project name:     ethernet_basic
I (273) cpu_start: App version:      1
I (277) cpu_start: Compile time:     Oct  1 2023 15:10:22
I (284) cpu_start: ELF file SHA256:  ca123a482e4a6baa...
I (290) cpu_start: ESP-IDF:          v5.1.1-dirty
I (295) cpu_start: Min chip rev:     v0.0
I (300) cpu_start: Max chip rev:     v3.99 
I (304) cpu_start: Chip rev:         v1.1
I (309) heap_init: Initializing. RAM available for dynamic allocation:
I (317) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (322) heap_init: At 3FFB2E48 len 0002D1B8 (180 KiB): DRAM
I (329) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (335) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (341) heap_init: At 4008C920 len 000136E0 (77 KiB): IRAM
I (349) spi_flash: detected chip: generic
I (352) spi_flash: flash io: dio
W (356) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (370) app_start: Starting scheduler on CPU0
I (374) app_start: Starting scheduler on CPU1
I (374) main_task: Started on CPU0
I (384) main_task: Calling app_main()
netif: netmask of interface  set to 255.0.0.0
netif: GW address of interface  set to 127.0.0.1
netif_set_ipaddr: netif address being changed
netif: added interface lo IP addr 127.0.0.1 netmask 255.0.0.0 gw 127.0.0.1
dns_init: initializing
I (424) esp_eth.netif.netif_glue: 80:64:6f:e9:ed:57
I (424) esp_eth.netif.netif_glue: ethernet attached to netif
etharp_timer

DHCP 从这里开始,看起来它一直在尝试发送 DHCP 请求,但失败了。

dhcp_coarse_tmr()
etharp_timer
dhcp_coarse_tmr()
netif: added interface en IP addr 0.0.0.0 netmask 0.0.0.0 gw 0.0.0.0I (3334) main_task: Returned from app_main()

I (3334) eth_example: Ethernet Started
netif: setting default interface en
dhcp_start(netif=0x3ffbb73c) en1
dhcp_start(): restarting DHCP configuration
dhcp_start(): starting DHCP configuration
udp_bind(ipaddr = 0.0.0.0, port = 68)
udp_bind: bound to 0.0.0.0, port 68)
udp_connect: connected to 0.0.0.0, port 67)
dhcp_discover()
dhcp_discover(): dhcp state is DISCOVER
dhcp_select: could not allocate DHCP request
pbuf_alloc(length=308)
pbuf_alloc(length=308) == 0x3ffb41fc
transaction id xid(62b99c8b)
dhcp_discover: making request
dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER)
pbuf_add_header: old 0x3ffb4244 new 0x3ffb423c (8)
udp_send: added header in given pbuf 0x3ffb41fc
udp_send: sending datagram of length 316
udp_send: UDP packet length 316
emac_esp32_rx_task() received frame of len: 60
udp_send: UDP checksum 0xcc48
udp_send: ip_output_if (,,,,0x11,)
pbuf_add_header: old 0x3ffb423c new 0x3ffb4228 (20)
pbuf_alloced_custom(length=60)
ip4_output_if: en1
IP header:
+-------------------------------+
| 4 | 5 |  0x00 |       336     | (v, hl, tos, len)
+-------------------------------+
|        0      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |   17  |    0xba9d     | (ttl, proto, chksum)
+-------------------------------+
|    0  |    0  |    0  |    0  | (src)
+-------------------------------+
|  255  |  255  |  255  |  255  | (dest)
+-------------------------------+
ip4_output_if: call netif->output()
pbuf_add_header: old 0x3ffb4228 new 0x3ffb421a (14)
ethernet_output: sending packet 0x3ffb41fc
dhcp_discover: deleting()ing
pbuf_free(0x3ffb41fc)
pbuf_free: deallocating 0x3ffb41fc
dhcp_discover: SELECTING
dhcp_discover(): set request timeout 500 msecs
etharp_timer
I (3484) eth_example: Ethernet Link Up
dhcp_coarse_tmr()
I (3494) eth_example: Ethernet HW Addr 80:64:6f:e9:ed:57

下一行的 src 地址来自运行 DHCP 服务器的笔记本电脑的网络接口。所以至少它正在接收数据。

ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:f0:de:f1:95:fa:52, type:806
pbuf_remove_header: old 0x3ffafbcc new 0x3ffafbda (14)
etharp_update_arp_entry: 0.0.0.0 - f0:de:f1:95:fa:52
etharp_update_arp_entry: will not add non-unicast IP address to ARP cache
etharp_input: incoming ARP request
etharp_input: we are unconfigured, ARP request ignored.
pbuf_free(0x3ffafc0c)
pbuf_free: deallocating 0x3ffafc0c
dhcp_fine_tmr(): request timeout
dhcp_timeout()
dhcp_timeout(): restarting discovery
dhcp_discover()
dhcp_discover(): dhcp state is DISCOVER
dhcp_select: could not allocate DHCP request
pbuf_alloc(length=308)
pbuf_alloc(length=308) == 0x3ffb41fc
transaction id xid(62b99c8b)
dhcp_discover: making request
dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER)
pbuf_add_header: old 0x3ffb4244 new 0x3ffb423c (8)
udp_send: added header in given pbuf 0x3ffb41fc
udp_send: sending datagram of length 316
udp_send: UDP packet length 316
udp_send: UDP checksum 0xcc48
udp_send: ip_output_if (,,,,0x11,)
pbuf_add_header: old 0x3ffb423c new 0x3ffb4228 (20)
ip4_output_if: en1
IP header:
+-------------------------------+
| 4 | 5 |  0x00 |       336     | (v, hl, tos, len)
+-------------------------------+
|        1      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |   17  |    0xba9c     | (ttl, proto, chksum)
+-------------------------------+
|    0  |    0  |    0  |    0  | (src)
+-------------------------------+
|  255  |  255  |  255  |  255  | (dest)
+-------------------------------+
ip4_output_if: call netif->output()
pbuf_add_header: old 0x3ffb4228 new 0x3ffb421a (14)
ethernet_output: sending packet 0x3ffb41fc
dhcp_discover: deleting()ing
pbuf_free(0x3ffb41fc)
pbuf_free: deallocating 0x3ffb41fc
dhcp_discover: SELECTING
dhcp_discover(): set request timeout 1000 msecs
emac_esp32_rx_task() received frame of len: 60
pbuf_alloced_custom(length=60)
ethernet_input: dest:01:80:c2:00:00:0e, src:f0:de:f1:95:fa:52, type:88cc
pbuf_free(0x3ffafcd0)
pbuf_free: deallocating 0x3ffafcd0
emac_esp32_rx_task() received frame of len: 60
pbuf_alloced_custom(length=60)
ethernet_input: dest:ff:ff:ff:ff:ff:ff, src:f0:de:f1:95:fa:52, type:806
pbuf_remove_header: old 0x3ffafc90 new 0x3ffafc9e (14)
etharp_update_arp_entry: 0.0.0.0 - f0:de:f1:95:fa:52
etharp_update_arp_entry: will not add non-unicast IP address to ARP cache
etharp_input: incoming ARP request
etharp_input: we are unconfigured, ARP request ignored.
pbuf_free(0x3ffafcd0)
pbuf_free: deallocating 0x3ffafcd0
etharp_timer
dhcp_coarse_tmr()
dhcp_fine_tmr(): request timeout

这将永远持续下去..

SDK 配置对于这篇文章来说太大了,所以我将其发布在 pastebin 上。

esp32 dhcp lwip espressif-idf
1个回答
0
投票

引用的示例实际上并未设置 DHCP 客户端,仅设置了 MAC、PHY 和 TCP/IP 接口。

调用

esp_event_handler_register(...)
函数来处理以太网和 TCPIP 事件后,您应该在调用
esp_netif_dhcpc_start(eth_netif);
之前调用:
esp_eth_start(eth_handles[i]);
(针对 1 端口示例或多端口示例进行修改)

这会将 DHCP 客户端附加到您的网络接口。它可能会返回错误,例如客户端已启动,但您可以轻松处理这些错误,请参阅API文档

请注意,如果您使用链接示例的多端口部分,则需要将 DHCP 客户端附加到您启动的每个接口。

© www.soinside.com 2019 - 2024. All rights reserved.