w5500 and be sure module works in any time.

maddogmaycry
Posts: 11
Joined: Sun Apr 17, 2022 6:58 am

w5500 and be sure module works in any time.

Postby maddogmaycry » Sun Apr 24, 2022 8:33 am

How to be sure that the network is available and the network module is functioning properly?

I've tried disconnecting ground or power while the module is running, and in some cases it will just stop working. Events (link up and link down) are not always displayed.

Is there any reliable and always working method to make sure that the network module is available?

1 - First thing is to use this function, but i cant use it directly.

Code: Select all

static esp_err_t w5500_verify_id(emac_w5500_t *emac)
{
    esp_err_t ret = ESP_OK;
    uint8_t version = 0;
    ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_VERSIONR, &version, sizeof(version)), err, TAG, "read VERSIONR failed");
    // W5500 doesn't have chip ID, we just print the version number instead
    ESP_LOGI(TAG, "version=%x", version);

err:
    return ret;
}
So, to prevent from freezing i must some how execute this function and know - module answered me.

2 - Second part - i need get IP, and if ip is 0.0.0.0: restart ethernet driver.
3 - And last one. I can ping some server, and if i get fail for 3 or 5 tryes, do full restart.

Pls help me with first 2 parts.

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 Apr 26, 2022 10:02 am

Could you please elaborate more the real world scenario which causes your concern? Do you have some "stability" issues with the W5500? The reason why I am asking is your questions seems to me bit non-standard to be honest. We usually don't perform any periodical checking of a submodule after it was successfully initialized unless the system under the question is some kind of high integrity system like aircraft flight controls or the subsystem can be disconnected and then reconnected on the go.

ad 1) It would not resolve your problem if you had problems with transient power source. If the power transient occurred (power went down and up again), the W5500 internal registers would be most probably reset. That would cause you were able to verify chip ID but you would't be able to receive any Ethernet frames since the W5500 would not be properly initialized.

ad 2) Does not seem to be right approach since you may connect to a network where there is no DHCP server and so you don't get any address but the W5500 works perfectly. This is perfectly valid scenario and Ethernet driver reset is not valid response to it.

ad 3) This is similar to point 2). You may not be able to ping the server not because there is issue with W5500 but the server may not be responding. And hence again, restarting Ethernet driver is not valid response.

maddogmaycry
Posts: 11
Joined: Sun Apr 17, 2022 6:58 am

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

Postby maddogmaycry » Wed Apr 27, 2022 11:56 am

Hi! Thx for the Reply
ESP_ondrej wrote:
Tue Apr 26, 2022 10:02 am
Could you please elaborate more the real world scenario which causes your concern? Do you have some "stability" issues with the W5500?
I just want to prevent any obvious attempts by the 5500 to hang at the wrong moment.

I think the first thing I need to do is ping the module itself. It must respond to requests from the ESP.
I see that 5500 has no version register. That is, an attempt to request the version will always return 0. And even if it were, I still cannot request the READ function directly, because if my request intersects between the communication session from the driver, the data may be corrupted from boths sides.

Maybe you can tell me which register I could read using the means that are already implemented in the driver to be sure that the module is not frozen?

This moment my plan is:
1 - Check if module answered over SPI.
2 - Does'nt? stoping iface -> reinstalling driver (i saw HW Reset inside of it) then -> reconf iface -> iface up -> attach.

I did implemented ping but i'm understand this works no in any case. Just an option.

Need some method to read REG directly from 5500 to be sure it's bot freezed.
Help =)

maddogmaycry
Posts: 11
Joined: Sun Apr 17, 2022 6:58 am

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

Postby maddogmaycry » Wed Apr 27, 2022 12:02 pm

btw, i tryed something like this

Code: Select all

ESP_LOGE(TAG,"%d",phy_spi->get_link(phy_spi));
but it's seems to nothing changes after i powering 5500 off.

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 » Wed Apr 27, 2022 1:54 pm

I just want to prevent any obvious attempts by the 5500 to hang at the wrong moment.
I'm sorry, I still don't fully understand to your concern. It's still to vague...
I think the first thing I need to do is ping the module itself. It must respond to requests from the ESP.
Yes, this is done by driver during the initialization. It tries to read ID from the W5500.
I see that 5500 has no version register. That is, an attempt to request the version will always return 0.
This is not true. See "Common Register Block" section of W5500 datasheet (offset 0x0039).
I still cannot request the READ function directly, because if my request intersects between the communication session from the driver, the data may be corrupted from boths sides.
Yes, that's right. You would have to use the same W5500 Eth driver instance. You could probably take advantage of `phy_reg_read` and `phy_reg_write` functions in Ethernet driver mediator, see `esp_eth_mediator_s`.

Anyway, if you really want to check the W5500 status periodically for some reason, it's important to understand that checking of one static register value may not ensure that the W5500 is functioning properly in your system. As I mentioned in my previous post, if there was power transient, you can read static register of W5500 but the chip itself is not properly initialized and so you may not receive/transmit any data.

maddogmaycry
Posts: 11
Joined: Sun Apr 17, 2022 6:58 am

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

Postby maddogmaycry » Wed Apr 27, 2022 3:28 pm

ESP_ondrej wrote:
Wed Apr 27, 2022 1:54 pm
Yes, that's right. You would have to use the same W5500 Eth driver instance. You could probably take advantage of `phy_reg_read` and `phy_reg_write` functions in Ethernet driver mediator, see `esp_eth_mediator_s`.
Litle example for LUA users? :D
driver

Code: Select all

ESP_ERROR_CHECK(esp_eth_driver_install(&eth_config_spi, &eth_handle_spi));
try to get mediator

Code: Select all

const esp_eth_mediator_t *mediator = &eth_handle_spi->mediator;
err

Code: Select all

esp_eth_handle_t eth_handle_spi
dereferencing 'void *' pointer
request for member 'mediator' in something not a structure or union

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 » Thu Apr 28, 2022 6:21 am

Here you go...

Code: Select all

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

...

    esp_eth_mediator_t *eth = eth_handle_spi[0];
    uint8_t val = 0;
    eth->phy_reg_read(eth, 0, W5500_REG_PHYCFGR, (uint32_t *) (&val));

    ESP_LOGI(TAG, "W5500_REG_PHYCFGR val = 0x%x", val);
Output:

Code: Select all

I (3467) eth_example: W5500_REG_PHYCFGR val = 0xfa
The only disadvantage is you can read only PHY register by this method. On the other hand, the PHY register holds Link status which can be useful for you.

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 » Thu Apr 28, 2022 6:23 am

Just note that the above code sniped was instrumented in `examples/ethernet/basic` project at master branch.

maddogmaycry
Posts: 11
Joined: Sun Apr 17, 2022 6:58 am

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

Postby maddogmaycry » Thu Apr 28, 2022 7:02 am

ESP_ondrej wrote:
Thu Apr 28, 2022 6:23 am
Just note that the above code sniped was instrumented in `examples/ethernet/basic` project at master branch.
Thank you! I will try it soon =)

maddogmaycry
Posts: 11
Joined: Sun Apr 17, 2022 6:58 am

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

Postby maddogmaycry » Fri Apr 29, 2022 7:58 pm

ESP_ondrej wrote:
Thu Apr 28, 2022 6:21 am
Here you go...

Code: Select all

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

...

    esp_eth_mediator_t *eth = eth_handle_spi[0];
    uint8_t val = 0;
    eth->phy_reg_read(eth, 0, W5500_REG_PHYCFGR, (uint32_t *) (&val));

    ESP_LOGI(TAG, "W5500_REG_PHYCFGR val = 0x%x", val);
Output:

Code: Select all

I (3467) eth_example: W5500_REG_PHYCFGR val = 0xfa
The only disadvantage is you can read only PHY register by this method. On the other hand, the PHY register holds Link status which can be useful for you.
Same err
esp_eth_handle_t eth_handle_spi
dereferencing 'void *' pointer
UPD
Ok, i got it, but after ETH was inizialised i recve 0x00. Only first 2 seconds i have 0xfa

Code: Select all

esp_eth_mediator_t *eth = eth_handle_spi;
uint8_t val = 0;
eth->phy_reg_read(eth, 0, W5500_REG_PHYCFGR, (uint32_t *) (&val));
ESP_LOGI(TAG, "W5500_REG_PHYCFGR val = 0x%x", val);
UPD2
Ok, now it's works. When i switch power off i got 0. So, thank you veary much, it's helps =)

UPD3
For someone, who came with same question to in case with HOT SWAPING or something like this.
Check function:

Code: Select all

uint8_t checkModule(){
    if(eth_handle_spi!=NULL){
        esp_eth_mediator_t *eth = eth_handle_spi;
        uint8_t val = 0;
        eth->phy_reg_read(eth, 0, W5500_REG_PHYCFGR, (uint32_t *) (&val));
        ESP_LOGI(TAG, "W5500_REG_PHYCFGR val = %d", val);
        return val;
    }
    return 0;
}
Usage:

Code: Select all

void taskOne(void * parameter){
    int i = 0;
   //start ethernet
    while(true){
        vTaskDelay(1000 / portTICK_PERIOD_MS);
        if(checkModule()!=255 && i>5){
            //restart ethernet
            i=0;
        }
        i++;
    }
}
Thx again ESP_ondrej! =)

Who is online

Users browsing this forum: ESP_Roland and 119 guests