Search code examples
esp32dhcplwipespressif-idf

Not getting IP with IDF ethernet example on WT32_ETH01 board


I am running the ESP-IDF example ethernet-basic on a WT32_ETH01. After setting some options I get the board to connect to the phy. Unfortunately it is not getting a IP address from my router.

To rule out network problems I ran tftpd64 DHCP server on a laptop, first connected another laptop to test the DHCP (it got an IP) and then connected the WT32, it didn't get an IP. When I ran Wireshark to see the traffic I noticed that the WT32 was not sending anything, it only detects messages from the DHCP host.

I've been stuck for days trying to figure out why it is not sending out anything. I am fairly inexperienced with ethernet and DHCP so I'm hoping someone can point me in the right direction, any advice is greatly appreachiated.

From the serial output:

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 starts here, it looks like it keeps trying to send DHCP requests but fails.

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

The src address on the next line comes from the network interface of the laptop running DHCP server. So at least it is receiving data.

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

This goes on forever..

The SDK config was to large for this post so I posted it on pastebin.

EDIT: I changed the question to better represent what the issue actually was to help other people. The suggestion to add esp_err_t retv = esp_netif_dhcpc_start(eth_netif); to the example did not result in any different behavior. Still stuck in DHCP discover, still receiving network packages that are dropped.


Solution

  • Even tho it looked like there was an issue in lwip, the issue was the RMII clock mode which I had set to internal via GPIO0. After setting it to external it works. The basic ethernet example connects and gets an IP without any adjustments to the example.

    For the next one who is having trouble running this example on an WT32-ETH01:

    Internal EMAC: true
    RMII clock mode: external
    Ethernet PHY device: LAN87xx
    smi mdc: 23
    smi mdio: 18
    PHY reset: 16
    PHY addr: 1

    I turned off SPI ethernet and IPv6 stuff, not sure if important.
    For debugging this stuff look for "lwip debug" in the sdk config and enable what u want to debug.