ESP32 Ethernet basic example + W5500 external by SPI - problem to get IP

pdemianczuk
Posts: 28
Joined: Thu May 30, 2019 12:05 pm

ESP32 Ethernet basic example + W5500 external by SPI - problem to get IP

Postby pdemianczuk » Fri Jan 15, 2021 10:10 am

Hello everyone,

I am working on example Ethernet basic with external chip W5500 by SPI;
I use new posibility cooperate with W5500 by SPI, which hasnt fix description and documentatnion yet, but menuconfig has this option. It was added in November 2020.

I have started example code, but I can't get IP addres. The program is waiting. The program has reaction for LinkDown and LinkUp so its event handler (for ETH events) works. Probably some problem with GOT_IP event exist. I use ESP-IDF 4.3-dev-1901-g178b1222c1
Zrzut ekranu z 2021-01-12 13-02-23.png
Application hold and never get IP addr
Zrzut ekranu z 2021-01-12 13-02-23.png (101.16 KiB) Viewed 13899 times

I dont know why, I tried to run on 2 routers (both with DHCP). Could I need modification some field in mac/phy strutcture which are use to make a object to install driver? Or maybe some timeout is important?

Sometimes (I have noticed 2) the application has connect (pls look into screen), but I don't know why.
And it was happed after really long time. When the ESP32 has IP address, the computer in the same subnet might ping ESP32 but delay is enormous.
Zrzut ekranu z 2021-01-13 14-05-32.png
Sometimes got IP but after long, long time
Zrzut ekranu z 2021-01-13 14-05-32.png (79.74 KiB) Viewed 13899 times

In logs/documentation from example it is show, that (getting IP from DHCP) spent time about 2 seconds.


Do you know how to change code to check static addres?
Do you know is might be problem with my ethernet subnet?
How check it to debuging this problem?
Attachments
Zrzut ekranu z 2021-01-13 14-39-09.png
somtime ping "works" but delay is too long
Zrzut ekranu z 2021-01-13 14-39-09.png (61.85 KiB) Viewed 13899 times

pdemianczuk
Posts: 28
Joined: Thu May 30, 2019 12:05 pm

Re: ESP32 Ethernet basic example + W5500 external by SPI - problem to get IP

Postby pdemianczuk » Fri Jan 15, 2021 10:21 am

update:
I changed loging to higher level and notice some information form esp_netif component.

If I have good know the link is good (fullduplex mode) ane ETH_EVENT 2 -> ETHERNET_EVENT_CONNECTED
Zrzut ekranu z 2021-01-15 11-16-00.png
Log starting program part 1
Zrzut ekranu z 2021-01-15 11-16-00.png (235.8 KiB) Viewed 13887 times
Zrzut ekranu z 2021-01-15 11-16-11.png
Log starting program part 2
Zrzut ekranu z 2021-01-15 11-16-11.png (167.74 KiB) Viewed 13887 times
Could anyone know what might mean:
esp_netif_lwip: if0x3ffbc90c start ip lost tmr: no need start because netif=0x3ffbc98c interval=120 ip=0

felmue
Posts: 69
Joined: Mon Nov 16, 2020 2:55 pm

Re: ESP32 Ethernet basic example + W5500 external by SPI - problem to get IP

Postby felmue » Fri Jan 15, 2021 11:55 am

Hello @pdemianczuk

I can confirm that the 'basic' example works for me. I had to lower the SPI clock speed to 20MHz (was 36MHz by default) and I've set the GPIO for PHY Reset to -1 (not used). The W5500 module I am using did work w/o interrupt line connected when used in an Arduino environment, but with ESP IDF I had to connect the interrupt line else I could not ping the module from the PC.

Some questions:
- What is the reason you are not using the latest available IDF 4.3 version, eg. v4.3-dev-2398-g2bfdd036b? Not sure it matters though.
- Why is there a HTTP_CLIENT in your log? A previous test? Another task running?
- Have you double checked the wiring between ESP32 and W5500 is good?
- Have you double checked the power supply is strong enough?
- Have you double checked the Ethernet cable is good?

The lines I've connected between ESP32 and W5500: 3.3V, GND, SCLK, MOSI, MISO, CS and Interrupt

As reference - maybe helpful - the log from my ESP32 board:

Code: Select all

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x1f (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4
load:0x3fff0034,len:6924
load:0x40078000,len:14332
ho 0 tail 12 room 4
load:0x40080400,len:3672
0x40080400: _init at ??:?

entry 0x40080678
I (30) boot: ESP-IDF v4.3-dev-2398-g2bfdd036b 2nd stage bootloader
I (30) boot: compile time 11:32:57
I (30) boot: chip revision: 1
I (35) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (42) boot.esp32: SPI Speed      : 40MHz
I (46) boot.esp32: SPI Mode       : DIO
I (51) boot.esp32: SPI Flash Size : 2MB
I (55) boot: Enabling RNG early entropy source...
I (61) boot: Partition Table:
I (64) boot: ## Label            Usage          Type ST Offset   Length
I (72) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (79) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (87) boot:  2 factory          factory app      00 00 00010000 00100000
I (94) boot: End of partition table
I (98) boot_comm: chip revision: 1, min. application chip revision: 0
I (105) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=10fech ( 69612) map
I (141) esp_image: segment 1: paddr=00021014 vaddr=3ffb0000 size=02a5ch ( 10844) load
I (145) esp_image: segment 2: paddr=00023a78 vaddr=40080000 size=00404h (  1028) load
I (147) esp_image: segment 3: paddr=00023e84 vaddr=40080404 size=0c194h ( 49556) load
I (177) esp_image: segment 4: paddr=00030020 vaddr=400d0020 size=32058h (204888) map
I (255) esp_image: segment 5: paddr=00062080 vaddr=4008c598 size=00c38h (  3128) load
I (264) boot: Loaded app from partition at offset 0x10000
I (264) boot: Disabling RNG early entropy source...
I (277) cpu_start: Pro cpu up.
I (277) cpu_start: Starting app cpu, entry point is 0x4008122c
0x4008122c: call_start_cpu1 at /Users/fm/esp/esp-idf/components/esp_system/port/cpu_start.c:133

I (0) cpu_start: App cpu up.
I (292) cpu_start: Pro cpu start user code
I (292) cpu_start: cpu freq: 160000000
I (292) cpu_start: Application information:
I (296) cpu_start: Project name:     ethernet_basic
I (302) cpu_start: App version:      1
I (306) cpu_start: Compile time:     Jan 15 2021 12:18:31
I (312) cpu_start: ELF file SHA256:  65c082fc035487c4...
I (318) cpu_start: ESP-IDF:          v4.3-dev-2398-g2bfdd036b
I (325) heap_init: Initializing. RAM available for dynamic allocation:
I (332) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (338) heap_init: At 3FFB4338 len 0002BCC8 (175 KiB): DRAM
I (344) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (351) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (357) heap_init: At 4008D1D0 len 00012E30 (75 KiB): IRAM
I (364) spi_flash: detected chip: generic
I (368) spi_flash: flash io: dio
W (372) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (386) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (396) w5500-mac: version=4
I (416) esp_eth.netif.glue: 02:00:00:12:34:56
I (416) esp_eth.netif.glue: ethernet attached to netif
I (426) eth_example: Ethernet Started
I (2426) eth_example: Ethernet Link Up
I (2426) eth_example: Ethernet HW Addr 02:00:00:12:34:56
I (3396) esp_netif_handlers: eth ip: 192.168.144.116, mask: 255.255.255.0, gw: 192.168.144.1
I (3396) eth_example: Ethernet Got IP Address
I (3396) eth_example: ~~~~~~~~~~~
I (3396) eth_example: ETHIP:192.168.144.116
I (3406) eth_example: ETHMASK:255.255.255.0
I (3406) eth_example: ETHGW:192.168.144.1
I (3416) eth_example: ~~~~~~~~~~~
Thanks
Felix

pdemianczuk
Posts: 28
Joined: Thu May 30, 2019 12:05 pm

Re: ESP32 Ethernet basic example + W5500 external by SPI - problem to get IP

Postby pdemianczuk » Fri Jan 15, 2021 1:14 pm

hello @felmue

indeed about esp-idf version;
I have the latest version but I have compiled only app (not build all project) so in first log I see diffrent version. I fixed this
Zrzut ekranu z 2021-01-15 13-49-20.png
Zrzut ekranu z 2021-01-15 13-49-20.png (23.57 KiB) Viewed 13848 times
According to http_client componetns I have call this from event handler with GOT_IP, so I think it is rather correctly.
But you are right, probably it doesn't make sense.

Code: Select all

/** Event handler for Ethernet events */
static void eth_event_handler(void *arg, esp_event_base_t event_base,
                              int32_t event_id, void *event_data)
{
    uint8_t mac_addr[6] = {0};
    /* we can get the ethernet driver handle from event data */
    esp_eth_handle_t eth_handle = *(esp_eth_handle_t *)event_data;

    switch (event_id) {
    case ETHERNET_EVENT_CONNECTED:
        esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);
        ESP_LOGI(TAG, "Ethernet Link Up");
        ESP_LOGI(TAG, "Ethernet HW Addr %02x:%02x:%02x:%02x:%02x:%02x",
                 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);

        /* get PHY address */
        //int phy_addr = -1;
        //esp_eth_ioctl(eth_handle, ETH_CMD_G_PHY_ADDR, &phy_addr);
//        ESP_LOGI(TAG, "Ethernet PHY Address: %d", phy_addr);
        break;
    case ETHERNET_EVENT_DISCONNECTED:
        ESP_LOGI(TAG, "Ethernet Link Down");
        break;
    case ETHERNET_EVENT_START:
        ESP_LOGI(TAG, "Ethernet Started");
        break;
    case ETHERNET_EVENT_STOP:
        ESP_LOGI(TAG, "Ethernet Stopped");
        break;
    default:
        break;
    }
}

/** Event handler for IP_EVENT_ETH_GOT_IP */
static void got_ip_event_handler(void *arg, esp_event_base_t event_base,
                                 int32_t event_id, void *event_data)
{ESP_LOGI(TAG, "Connected to AP, begin http example");
    ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
    const esp_netif_ip_info_t *ip_info = &event->ip_info;

    ESP_LOGI(TAG, "Ethernet Got IP Address");
    ESP_LOGI(TAG, "~~~~~~~~~~~");
    ESP_LOGI(TAG, "ETHIP:" IPSTR, IP2STR(&ip_info->ip));
    ESP_LOGI(TAG, "ETHMASK:" IPSTR, IP2STR(&ip_info->netmask));
    ESP_LOGI(TAG, "ETHGW:" IPSTR, IP2STR(&ip_info->gw));
    ESP_LOGI(TAG, "~~~~~~~~~~~");

    http_client_test();
}
I checked application when I used a power supply 2A at 5V , the problem is still appear.
When I use the cable of Ethernet to computer , everything is ok

Did you use RST pin?
Maybe, do you rember somthing important to select in menuconfig/sdkconfig what wasnt describe in documentation.

What did you set on PHY Adrress?
Attachments
Zrzut ekranu z 2021-01-15 14-18-32.png
Zrzut ekranu z 2021-01-15 14-18-32.png (20.38 KiB) Viewed 13848 times

felmue
Posts: 69
Joined: Mon Nov 16, 2020 2:55 pm

Re: ESP32 Ethernet basic example + W5500 external by SPI - problem to get IP

Postby felmue » Fri Jan 15, 2021 2:04 pm

Hi @pdemianczuk

I'd test without http_client until the basic connection is properly established and stable and can be pinged consistently.

I noticed that you have the same GPIO18 defined for SCLK and CS - an oversight? That would certainly explain things.

No, I did not use the reset pin. In menuconfig I only made changes in the Example Configuration:
ESP32EthernetBasicSampleSettings_20210115.png
ESP32EthernetBasicSampleSettings_20210115.png (54.53 KiB) Viewed 13839 times
Thanks
Felix

pdemianczuk
Posts: 28
Joined: Thu May 30, 2019 12:05 pm

Re: ESP32 Ethernet basic example + W5500 external by SPI - problem to get IP

Postby pdemianczuk » Fri Jan 15, 2021 2:26 pm

thx @falmue

In reference to your post, I had made next instance of project on example and I did this mistake. Thx for your attention ;)
but the problem with IP is still exist
Zrzut ekranu z 2021-01-15 15-20-25.png
Zrzut ekranu z 2021-01-15 15-20-25.png (124.88 KiB) Viewed 13835 times
Could share your sdk file? maybe some setting is LWIP section is imporatant.

update: it have connected.....after....604 sec....
Zrzut ekranu z 2021-01-15 15-30-40.png
Zrzut ekranu z 2021-01-15 15-30-40.png (51.04 KiB) Viewed 13834 times

pdemianczuk
Posts: 28
Joined: Thu May 30, 2019 12:05 pm

Re: ESP32 Ethernet basic example + W5500 external by SPI - problem to get IP

Postby pdemianczuk » Fri Jan 15, 2021 3:06 pm

Do anyone know what could be interesting in this log?
I see something in DHCP frame with string "espressif"
Zrzut ekranu z 2021-01-15 16-02-22.png
wireshark frames
Zrzut ekranu z 2021-01-15 16-02-22.png (214.83 KiB) Viewed 13824 times

pdemianczuk
Posts: 28
Joined: Thu May 30, 2019 12:05 pm

Re: ESP32 Ethernet basic example + W5500 external by SPI - problem to get IP

Postby pdemianczuk » Wed Feb 17, 2021 1:14 pm

The problem was solved. Probably configuration for PIN Interrupt oraz quality of connection (wires) was a problem.
The topic is to closed.

Who is online

Users browsing this forum: Baidu [Spider], JVKran and 132 guests