Skip to content

Documentation: ESP32 + Ethernet LAN8720A with External Crystal Clock? #11420

Open
@Arcitec

Description

@Arcitec

Board

ESP32

Device Description

LAN8720A

Hardware Configuration

No.

Version

v3.2.0

IDE Name

VSCode with PlatformIO

Operating System

Linux

Flash frequency

80MHz

PSRAM enabled

yes

Upload speed

921600

Description

Hi! :) Because of the ESP32 hardware PLL bug, I need to stop using the ESP32 PLL, and will instead connect an external 25 MHz crystal directly to the LAN8720A, as described on Page 29 of their datasheet under "3.7.4.2 REF_CLK Out Mode".

Now I need to tell ESP32 SDK's ETH.begin() call how to talk to the LAN8720A chip in that configuration.

Can you please provide an example with all the correct values for "ETH.begin" when the ESP32 is connected to a LAN8720A that uses an external 25 MHz crystal on its XTAL1/XTAL2 pins?

PS: It would also be greatly appreciated if someone knows how the ESP32 is able to control/synchronize with the LAN8720A when the crystal is external? Do I need to do something special? Keep in mind that my crystal is only wired to the LAN8720A. It isn't wired to the ESP32. So they are not sharing the same clock. Does anyone know if I need to do something special to turn on/off the crystal via the ESP32 in this configuration, or if the LAN8720A handles it?

What I've researched...

The Ethernet API for the ESP32 SDK is not documented. It only pulls in some example source code, but it doesn't actually explain the APIs or the available constant values:

So I am looking directly at the source code to try to figure out the APIs here:

But I don't understand what I should do.

The ETH.h contains the following values in an enum:

typedef enum {
ETH_CLOCK_GPIO0_IN,
ETH_CLOCK_GPIO0_OUT,
ETH_CLOCK_GPIO16_OUT,
ETH_CLOCK_GPIO17_OUT
} eth_clock_mode_t;

I can't find any file where those values (such as ETH_CLOCK_GPIO0_IN) are defined.

But more importantly, I don't see any way to define an external clock? All those "modes" are only about using GPIO 0/16/17 for PLL clock outputs, which I don't want to do...

I need a way to tell "ETH.begin" that my clock is external.

Then I found this file:

mac_config.clock_config.rmii.clock_mode = (clock_mode) ? EMAC_CLK_OUT : EMAC_CLK_EXT_IN;
mac_config.clock_config.rmii.clock_gpio = (1 == clock_mode) ? EMAC_APPL_CLK_OUT_GPIO
: (2 == clock_mode) ? EMAC_CLK_OUT_GPIO
: (3 == clock_mode) ? EMAC_CLK_OUT_180_GPIO
: EMAC_CLK_IN_GPIO;

It reveals that there's two secret values: EMAC_CLK_OUT : EMAC_CLK_EXT_IN;

But which value is correct? Why is there an "OUT" and "EXT IN"? None of this seems to be documented anywhere.

Sketch

...

Debug Message

...

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions