w5500 and be sure module works in any time.

glrtheil
Posts: 61
Joined: Tue Dec 07, 2021 2:48 pm

Re: w5500 and be sure module works in any time.

Postby glrtheil » Fri Jun 09, 2023 4:54 pm

Was led here via an Espressif support rep, but had a lot of issues getting this to work. Even the claim of the code snippet from ESP_ondrej doesn't make sense, as that code doesn't appear anywhere in any example within any version of the IDF that I could find. But even using that code within the example he pointed out (Ethernet basic), that code snippet doesn't work. This is because W5500_REG_PHYCFGR is in a header file that's inaccessible because it's in a src directory within the IDF (4.3.2). After a ton of work, I came up with this, and it works great:

Code: Select all

esp_eth_mac_t *mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
esp_eth_phy_t *phy = esp_eth_phy_new_w5500(&phy_config);

esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
esp_eth_handle_t eth_handle = NULL;
ESP_ERROR_CHECK(esp_eth_driver_install(&config, &eth_handle));

//check PHY register to see if the w5500 exists on SPI bus
uint32_t regPosition = 0x002E << 16 | 0x00 << 3;
esp_eth_mediator_t *ethMediator = (esp_eth_mediator_t *)eth_handle;
uint8_t val = 0;
ethMediator->phy_reg_read(ethMediator, 0, regPosition, (uint32_t *)(&val));
ESP_LOGI(TAG, "W5500_REG_PHYCFGR val = 0x%x, i=%i", val, val);
if (val == 0xff)
{
    //w5500 ethernet does not exist/respond
}

ESP_ondrej
Posts: 211
Joined: Fri May 07, 2021 10:35 am

Re: w5500 and be sure module works in any time.

Postby ESP_ondrej » Tue Jun 13, 2023 8:13 am

I'm glad to hear you were able to resolve your issue. However, I'm bit sad about your negative experience. Therefore, I would like to provide clarification to some topics.
that code doesn't appear anywhere in any example within any version of the IDF that I could find.
Of course it doesn't appear anywhere since this is not standard way how to access the W5500. It's a workaround I came up with to help previous users to solve their problem. It happened to be also applicable to your case. Hence the support team directed you to this thread.
But even using that code within the example he pointed out (Ethernet basic), that code snippet doesn't work.
It works pretty well, I tested it again with the latest and v4.3.2 ethernet/basic example today. Only tiny updates were needed (eth handle name differs). You need to understand that the examples evolve and the forum's goal is to provide a guidance. It's impossible to give full solution for all versions. Some basic knowledge and effort from user's side is always required.
This is because W5500_REG_PHYCFGR is in a header file that's inaccessible because it's in a src directory within the IDF (4.3.2)
Did you include

Code: Select all

#include "../src/w5500.h"

maurizio.scian
Posts: 14
Joined: Mon Jun 26, 2023 8:09 am

Re: w5500 and be sure module works in any time.

Postby maurizio.scian » Tue Nov 05, 2024 12:47 pm

maddogmaycry wrote:
Fri Apr 29, 2022 7:58 pm

Code: Select all

        if(checkModule()!=255 && i>5){
            //restart ethernet
            i=0;
        }
        i++;
    }
}
I have the same problem, some disturbs causes reset of W5500. This solution, adapted in my case, allow to check the module configuration and works well... But how "restart ethernet"? Which method should i invoke?

ESP_ondrej
Posts: 211
Joined: Fri May 07, 2021 10:35 am

Re: w5500 and be sure module works in any time.

Postby ESP_ondrej » Tue Nov 05, 2024 3:53 pm

Just recall me, the issue is the W5500 gets completely unresponsive? If so, it's pretty serious and you need to HW restart it. If you have reset pin already mapped to PHY instance, "just" de-initialize the Ethernet interface and its Netif as demonstrated at https://github.com/espressif/esp-idf/bl ... ain.c#L127 and initialize it again.

maurizio.scian
Posts: 14
Joined: Mon Jun 26, 2023 8:09 am

Re: w5500 and be sure module works in any time.

Postby maurizio.scian » Wed Nov 06, 2024 3:16 pm

Thanks ESP_ondrej, the solution you suggest works! I don't know why I didn't see this example, because I don't only have the Ethernet interface but also the wifi and I had modified the original source a lot.

Only, if I call esp_event_loop_delete_default it is not possible to use esp_eth_new_netif_glue: esp_eth_set_glue_instance_handlers needs s_default_loop allocated to be able to glue the interface to the netif. It is enough not to call esp_event_loop_delete_default and everything reconnects correctly!

Thank you very much!

Who is online

Users browsing this forum: Bing [Bot] and 70 guests