ESP32 and Ethernet using Olimex POE2

leonardo.zambonelli
Posts: 11
Joined: Thu May 16, 2019 3:13 pm

ESP32 and Ethernet using Olimex POE2

Postby leonardo.zambonelli » Mon Aug 19, 2024 3:51 pm

Hi all,
i'm trying to use the board ESP32 POE2, using native ESP-IDF (ver 4.X).
I'have some problem with the clock connected to GPIO0. When i start Network driver, it stops logging to console.

This is my code:

Code: Select all

#include "esp_eth.h"
#include "esp_event.h"
#include "esp_log.h"

#include "driver/gpio.h"

static const char *TAG = "eth_example";

// Callback per gestire gli eventi Ethernet
static void eth_event_handler(void *arg,
    esp_event_base_t event_base,
    int32_t event_id,
    void *event_data) {
    switch (event_id) {
    case ETHERNET_EVENT_CONNECTED:
        ESP_LOGI(TAG, "Ethernet Connected");
        break;
    case ETHERNET_EVENT_DISCONNECTED:
        ESP_LOGI(TAG, "Ethernet Disconnected");
        break;
    case ETHERNET_EVENT_START:
        ESP_LOGI(TAG, "Ethernet Started");
        break;
    case ETHERNET_EVENT_STOP:
        ESP_LOGI(TAG, "Ethernet Stopped");
        break;
    default:
        ESP_LOGI(TAG, "eth_event_handler. EventID: %d ", event_id);
        break;
    }
}
#define PHY_POWER_PIN 12  // Sostituisci con il pin corretto

void app_main(void) {
    // Inizializzazione del loop degli eventi
    ESP_ERROR_CHECK(esp_event_loop_create_default());

    // Configurazione del pin di alimentazione del PHY
    gpio_pad_select_gpio(PHY_POWER_PIN);
    gpio_set_direction(PHY_POWER_PIN, GPIO_MODE_OUTPUT);
    gpio_set_level(PHY_POWER_PIN, 1); // Imposta il livello logico alto per accendere il PHY
    // Configurazione del MAC e PHY Ethernet
    eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
    eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
   
   
    ESP_LOGI(TAG, "Log 1");

    // Inizializzazione del MAC
    esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config);
   
   
    ESP_LOGI(TAG, "Log 2");

    // Inizializzazione del PHY (LAN8720 è usato come esempio)
    esp_eth_phy_t *phy = esp_eth_phy_new_lan8720(&phy_config);
   
   
    ESP_LOGI(TAG, "Log 3");

    // Configurazione del driver Ethernet
    esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
   
   
    ESP_LOGI(TAG, "Log 4");
   
    // Installazione del driver Ethernet
    esp_eth_handle_t eth_handle = NULL;
    ESP_ERROR_CHECK(esp_eth_driver_install(&config, &eth_handle));

   
    ESP_LOGI(TAG, "Log 5");

    // Registrazione del gestore degli eventi Ethernet
    ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &eth_event_handler, NULL));

    ESP_LOGI(TAG, "Log 6");
    // Avvio dell'Ethernet
    ESP_ERROR_CHECK(esp_eth_start(eth_handle));
   
    ESP_LOGI(TAG, "Log 7");
}
This is the log
I (154) psram: This chip is ESP32-D0WD
I (155) spiram: Found 64MBit SPI RAM device
I (155) spiram: SPI RAM mode: flash 40m sram 40m
I (158) spiram: PSRAM initialized, cache is in low/high (2-core) mode.
I (165) cpu_start: Pro cpu up.
I (169) cpu_start: Starting app cpu, entry point is 0x40081244
I (0) cpu_start: App cpu up.
I (190) cpu_start: Pro cpu start user code
I (190) cpu_start: cpu freq: 240000000
I (190) cpu_start: Application information:
I (195) cpu_start: Project name: MrLightRGB
I (200) cpu_start: App version: cf1d79fb-dirty
I (206) cpu_start: Compile time: Aug 19 2024 15:06:03
I (212) cpu_start: ELF file SHA256: 2d0b2f1861f4ea35...
I (218) cpu_start: ESP-IDF: cf1d79fb-dirty
I (224) heap_init: Initializing. RAM available for dynamic allocation:
I (230) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (237) heap_init: At 3FFB3598 len 0002CA68 (178 KiB): DRAM
I (243) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (249) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (256) heap_init: At 4008E380 len 00011C80 (71 KiB): IRAM
I (262) spiram: Adding pool of 4096K of external SPI memory to heap allocator
I (271) spi_flash: detected chip: gd
I (274) spi_flash: flash io: dio
W (278) spi_flash: Detected size(16384k) larger than the size in the binary image header(8192k). Using the size in the binary image header.
I (292) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (307) spiram: Reserving pool of 32K of internal memory for DMA/internal allocations
I (316) eth_example: Log
And this is the sdkconfig

Code: Select all

#
# Ethernet
#
CONFIG_ETH_ENABLED=y
CONFIG_ETH_USE_ESP32_EMAC=y
CONFIG_ETH_PHY_INTERFACE_RMII=y
# CONFIG_ETH_PHY_INTERFACE_MII is not set
# CONFIG_ETH_RMII_CLK_INPUT is not set
CONFIG_ETH_RMII_CLK_OUTPUT=y
CONFIG_ETH_RMII_CLK_OUTPUT_GPIO0=y
CONFIG_ETH_DMA_BUFFER_SIZE=512
CONFIG_ETH_DMA_RX_BUFFER_NUM=10
CONFIG_ETH_DMA_TX_BUFFER_NUM=10
# CONFIG_ETH_USE_SPI_ETHERNET is not set
# CONFIG_ETH_USE_OPENETH is not set
# end of Ethernet
I have no console output so i don't know what's happening., don't know if it manages to take an ip, cannot log ANYTHING. (so i cannot do ping)
I know the problem is connected to the clock connected to GPIO0, but i don't know how to figure out

Thank to u all!
Leonardo

Who is online

Users browsing this forum: Google [Bot] and 122 guests