Olimex Support Forum

Microcontrollers => ESP32 => Topic started by: leodashevskiy on December 22, 2021, 09:52:18 AM

Title: ESP32-Gateway - cannot run sample code
Post by: leodashevskiy on December 22, 2021, 09:52:18 AM
I got ESP32-Gateway board (revision G) and when I try to run sample code (found here: https://github.com/espressif/arduino-esp32/tree/2.0.1/libraries/Ethernet/examples/ETH_LAN8720 ) I got following error:
E (1012) esp.emac: emac_esp32_init(354): reset timeout
E (1012) esp_eth: esp_eth_driver_install(222): init mac failed

I tried to reassign some values which I found here on forum like this:
#define ETH_CLK_MODE    ETH_CLOCK_GPIO17_OUT
// Pin# of the enable signal for the external crystal oscillator (-1 to disable for internal APLL source)
#define ETH_POWER_PIN   -1
// Type of the Ethernet PHY (LAN8720 or TLK110)
#define ETH_TYPE        ETH_PHY_LAN8720
// I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)
#define ETH_ADDR        0
// Pin# of the I²C clock signal for the Ethernet PHY
#define ETH_MDC_PIN     23
// Pin# of the I²C IO signal for the Ethernet PHY
#define ETH_MDIO_PIN    18

and I got same result.
I am using USB only as a power source, no POE.
Please help!
Title: Re: ESP32-Gateway - cannot run sample code
Post by: leodashevskiy on December 22, 2021, 10:03:04 PM
Forgot to mention: I added 2 seconds delay before initializing Ethernet.
here is a code:

void setup()
{
  Serial.begin(115200);
  delay (2000);
  WiFi.onEvent(WiFiEvent);
  ETH.begin();
}

Title: Re: ESP32-Gateway - cannot run sample code
Post by: olimex on December 23, 2021, 09:48:09 AM
I would suggest you to run the demo code from the product web page.

https://www.olimex.com/Products/IoT/ESP32/ESP32-GATEWAY/open-source-hardware

Title: Re: ESP32-Gateway - cannot run sample code
Post by: leodashevskiy on December 23, 2021, 04:42:34 PM
I run code found here: https://github.com/espressif/arduino-esp32/blob/master/libraries/Ethernet/examples/ETH_LAN8720/ETH_LAN8720.ino
I added 5 seconds delay like this:

void setup()
{
  Serial.begin(115200);
  delay(5000);
  WiFi.onEvent(WiFiEvent);
  ETH.begin();
}

and it still gives me same error:
E (6012) esp.emac: emac_esp32_init(354): reset timeout
E (6012) esp_eth: esp_eth_driver_install(222): init mac failed

Please help!
Title: Re: ESP32-Gateway - cannot run sample code
Post by: leodashevskiy on December 23, 2021, 06:16:32 PM
I installed Developer release of board manager
(https://dl.espressif.com/dl/package_esp32_dev_index.json)
as listed here: https://www.olimex.com/Products/IoT/ESP32/_resources/Arudino-ESP32.txt
and now I cannot even compile sample code found here:https://github.com/espressif/arduino-esp32/blob/1.0.3/libraries/WiFi/examples/ETH_LAN8720/ETH_LAN8720.ino (this link is on same page of instruction).
What did I do wrong?
Title: Re: ESP32-Gateway - cannot run sample code
Post by: JohnS on December 24, 2021, 09:43:04 AM
The developer release has changed so maybe that's a clue.

John
Title: Re: ESP32-Gateway - cannot run sample code
Post by: leodashevskiy on December 27, 2021, 07:00:12 PM
John, could be but unfortunately, it does not help me.. I still have no clue what to do. :(
Title: Re: ESP32-Gateway - cannot run sample code
Post by: leodashevskiy on December 27, 2021, 08:43:22 PM
Problem solved - by accident I choose ESP32-PoE board in board manager, recompiled code and all the sudden ESP32-Gateway board started working! Interesting!
Title: Re: ESP32-Gateway - cannot run sample code
Post by: LubOlimex on January 11, 2022, 12:51:22 PM
It is probably because older hardware revisions of ESP32-GATEWAY had different way of handling Ethernet clock and start up, the design was closer to ESP32-EVB. In newer revisions of ESP32-GATEWAY, tho, this part of the design is similar to ESP32-POE.

Also if you are using latest versions of everything, then you can select what revision of ESP32-GATEWAY you are using and such problem should not appear.
Title: Re: ESP32-Gateway - cannot run sample code
Post by: babos on January 13, 2022, 07:13:10 PM
Same problem:
Arduino ESP32 Library board :  2.0.2
OLIMEX B08NWMWSG9 REV.G
Example Test: ETH_LAN8270.ino

solved by selecting ESP-POE board.

is it possible to normalize?

The device now is detected on the network but events and more are not working. The debug messages do not appear on the serial.
Title: Re: ESP32-Gateway - cannot run sample code
Post by: McAleerElk on November 25, 2022, 05:26:37 PM
Quote from: LubOlimex on January 11, 2022, 12:51:22 PMIt is probably because older hardware revisions of ESP32-GATEWAY had different way of handling Ethernet clock and start up, the design was closer to ESP32-EVB. In newer revisions of ESP32-GATEWAY, tho, this part of the design is similar to ESP32-POE.

Also if you are using latest versions of everything, then you can select what revision of ESP32-GATEWAY you are using and such problem should not appear.


Hi. I've spend 48 hours in this exact same problem. Not only have I had problem with the eth examples (All examples I've tried and messed around with (EVEN ESP-IDF, which I'm quite unfamiliar with)), I have also not managed to have any functioning code using the SD-card.

I have not yet tried the "change board to ESP32-POE"-solution. I will do that right away, and perhaps I will let my tears out if it actually works!

You say: "Also if you are using latest versions of everything..."

Please be elaborate when you say "EVERYTHING"... Cause it's hard enough getting into this...
I've seen you mention that in board selectors, you should be able to see ESP32-Gateway revisions. Even though I went through:

1 Updating [ESP32 version] in arduino Boards manager
2 Update the link in Board Manager URL to https://dl.espressif.com/dl/package_esp32_dev_index.json  as per https://www.olimex.com/Products/IoT/ESP32/_resources/Arudino-ESP32.txt

Then I can still not see and select such revisions. What am I missing? Updating my Arduino IDE?

Actually I prefer a lot PlatformIO. I may have subsequent questions on doing this in PlatformIO in Visual Studio.
Title: Re: ESP32-Gateway - cannot run sample code
Post by: LubOlimex on November 28, 2022, 09:37:56 AM
1. Install the Arduino package as per these instructions:

https://espressif-docs.readthedocs-hosted.com/projects/arduino-esp32/en/latest/installing.html


2. Select Olimex ESP32-GATWAY with proper revision settings.

3. Load the demo Ethernet example from File -> Examples -> Ethernet -> ETH_LAN8720 compile, upload and test.
Title: Re: ESP32-Gateway - cannot run sample code
Post by: mirzaon on January 05, 2023, 11:24:56 AM
For those who struggled to bring up ESP32-PoE on ESP-IDF v5.0, here is what worked for me

void ethernet_initialize(void)
{
    ESP_ERROR_CHECK(esp_netif_init());
    ESP_ERROR_CHECK(esp_event_loop_create_default());

    /* Create new default instance of esp-netif for Ethernet */
    esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
    esp_netif_t *eth_netif = esp_netif_new(&cfg);

    /* Init MAC and PHY configs to default */
    eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
    eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();

    phy_config.phy_addr = ETHERNET_PHY_ADDRESS;
    phy_config.reset_gpio_num = ETHERNET_GPIO_PHY_POWER;
    phy_config.reset_timeout_ms = 1000;
    eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG();
    esp32_emac_config.smi_mdc_gpio_num = ETHERNET_GPIO_MDC;
    esp32_emac_config.smi_mdio_gpio_num = ETHERNET_GPIO_MDIO;
    esp32_emac_config.clock_config.rmii.clock_mode = EMAC_CLK_OUT;
    esp32_emac_config.clock_config.rmii.clock_gpio = EMAC_CLK_OUT_180_GPIO;
    mac_config.sw_reset_timeout_ms = 1000;
    esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config);
    esp_eth_phy_t *phy = esp_eth_phy_new_lan87xx(&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));
    /* attach Ethernet driver to TCP/IP stack */
    ESP_ERROR_CHECK(esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)));

    /* Register callbacks */
    ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &eth_event_handler, NULL));
    ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL));

    /* Start Ethernet driver state machine */
    ESP_ERROR_CHECK(esp_eth_start(eth_handle));

}
Title: Re: ESP32-Gateway - cannot run sample code
Post by: relaisstation.net on April 19, 2023, 09:43:29 PM
Hello all,

I have the same problem as the previous speakers.
With the Arduino IDE 2.1.0

The board manager URL:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

I also get the error messages with the OLIMEX Gateway:
E (1012) esp.emac: emac_esp32_init(354): reset timeout
E (1012) esp_eth: esp_eth_driver_install(222): init mac failed

Quote from: LubOlimex on November 28, 2022, 09:37:56 AM3.

Unfortunately, there is currently only version F to choose from, but I have revision G here.

If I use the ESP32-PoE as board the Ethernet Example works.


Best regards!

Quote from: LubOlimex on November 28, 2022, 09:37:56 AM3.
Title: Re: ESP32-Gateway - cannot run sample code
Post by: LubOlimex on April 20, 2023, 12:59:49 PM
QuoteUnfortunately, there is currently only version F to choose from, but I have revision G here.

That is fine, selecting revision F is suitable for newer revisions too. So you get the error when you select ESP32-GATEWAY and revision F?
Title: Re: ESP32-Gateway - cannot run sample code
Post by: tohox on April 25, 2023, 02:57:15 AM
Same here with rev G board.

Selecting ESP32-Gateway board and specifying rev F results in the error mentioned above but compiling with ESP32-POE board instead works OK.
Title: Re: ESP32-Gateway - cannot run sample code
Post by: LubOlimex on April 25, 2023, 01:02:49 PM
Oh, I think there were some changes to board configurations, please add at top of the demo these lines (before the header include):

#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT
#define ETH_PHY_POWER 5
#include <ETH.h>

It was explained here:

https://www.olimex.com/forum/index.php?topic=8638.0
Title: Re: ESP32-Gateway - cannot run sample code
Post by: LubOlimex on April 25, 2023, 03:07:39 PM
This is a Arduino IDE bug that affects all boards with menus, check these two entries here:

https://github.com/arduino/arduino-ide/issues/1030

https://github.com/arduino/arduino-ide/issues/591