-
BoardESP32 Device DescriptionLAN8720A Hardware ConfigurationNo. Versionv3.2.0 IDE NameVSCode with PlatformIO Operating SystemLinux Flash frequency80MHz PSRAM enabledyes Upload speed921600 DescriptionHi! :) 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 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: arduino-esp32/libraries/Ethernet/src/ETH.h Lines 83 to 88 in a6bba43 I can't find any file where those values (such as 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: arduino-esp32/libraries/Ethernet/src/ETH.cpp Lines 222 to 226 in a6bba43 It reveals that there's two secret values: 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 ReproduceNo response I have checked existing issues, online documentation and the Troubleshooting Guide
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
I will suggest that you try to get this going with the IDF team first. Once you have a confirmed working config, we can try and get this working in Arduino as well. Since we do not have boards with your hardware configuration, we have no way of confirming what changes are necessary and if they will indeed work. |
Beta Was this translation helpful? Give feedback.
-
It does work, see this code snipplet https://github.com/arendst/Tasmota/blob/development/tasmota/tasmota_xdrv_driver/xdrv_82_esp32_ethernet.ino |
Beta Was this translation helpful? Give feedback.
-
@Jason2866 Thank you. That's fascinating: #if CONFIG_ETH_USE_ESP32_EMAC
if (WT32_ETH01 == TasmotaGlobal.module_type) {
Settings->eth_address = 1; // EthAddress
Settings->eth_type = ETH_PHY_LAN8720; // EthType 0 = LAN8720
Settings->eth_clk_mode = 0; // EthClockMode 0 = ETH_CLOCK_GPIO0_IN
}
#endif // CONFIG_ETH_USE_ESP32_EMAC If I am reading that correctly:
Is there any mode where the ESP32 is unconnected to the Ethernet clock crystal? I found those weird, undocumented |
Beta Was this translation helpful? Give feedback.
-
Okay I found their design and started analyzing it: https://github.com/TDLOGY/WT32-ETH01-Docs/blob/main/WT32_ETH01_V2.schematic.pdf
Potential issues. Does anyone know the answer?
|
Beta Was this translation helpful? Give feedback.
-
Interesting. I'll have to see what Olimex did here, but it seems to be my ideal setup that I just mentioned. I only had a quick look so far, but it seems like they don't waste any extra GPIOs for the crystal's enable pin. They use a 50 MHz external crystal that seems to always be on by default (power + enable pin are both hooked to the 3.3V line): https://github.com/OLIMEX/ESP32-EVB/blob/master/HARDWARE/REV-K1/ESP32-EVB_Rev_K1.pdf They also use some kind of crystal enable/disable circuitry that's wired to the ESP32's EN pin. Hmm? Looks strange, since EN is held high during both flashing and regular boot modes. And the crystal should only be turned on in regular boot mode. Maybe their schematic is suboptimal. And then they route that clock signal to both GPIO 0 and to the LAN8710A XTAL1/CLKIN pin. But the newer 8720A has the "REFCLKO" pin, so that simplifies routing by just taking it directly from the ethernet chip to GPIO 0 instead. And the 8720A has the ability to use a 25 MHz crystal, and I seem to have found confirmation that it will output 50 MHz on that pin when you do that. So that's a better choice than wiring a 50 MHz crystal directly to the ESP32 GPIO0. They also have a CH340 and are wiring it directly to GPIO 0 too, which is how the flash/regular boot modes are signaled at startup by the CH340. So far I haven't seen exactly how they're solving the issue that ESP32 would go into programming mode at startup if the crystal is running. Their crystal seems to always be running and always going into GPIO 0. It looks like they're doing something with the ESP32 "EN" signal to start the crystal at the same time the ESP32 is being started. But it makes no sense to me because that would mean the crystal starts even in bootloader mode, since "EN" is always high in both Flash and Boot modes. So I have probably missed something. |
Beta Was this translation helpful? Give feedback.
-
So to sum it up so far:
|
Beta Was this translation helpful? Give feedback.
-
Alright after 5 hours of grueling research, here is a summary of the solutions to implement external crystals elegantly: First of all, the LAN8720A startup sequence:
Useful LAN8720A features:
The ESP32 ethernet design law:
How to wire all of this up:
Finally, code: The code running on the ESP32 must then do this startup sequence before talking to Ethernet:
There's just one problem remaining: If I use a GPIO for the Crystal enable, I'll have to patch WLED to add support for a separate "crystal enable" GPIO - unless I can somehow combine crystal enable and something else into one GPIO. Most likely I'll have to rename WLED's So the upside of using a GPIO for crystal ENABLE is that you save cost. The downside is that ESP32 software must be rewritten to handle it. Therefore, the most universal solution (which can run everyone's software unmodified) is to use a startup time-delay circuit for the crystal instead of a GPIO. |
Beta Was this translation helpful? Give feedback.
Alright after 5 hours of grueling research, here is a summary of the solutions to implement external crystals elegantly:
First of all, the LAN8720A startup sequence:
nRST
pin to reset the chip to actually boot it.nRST
without a crystal, it will hang.Useful LAN8720A features: