Repository navigation
Description
What happened?
During the WLED 0.15.1 testing, I found an extreme slowdown/freezing of the ESP32 CPU when using ESP-NOW based remote controls to control WLED.
- I was using an ESP-NOW-based remote control, which connects directly to the ESP32 via WiFi/Bluetooth (it bypasses the home network). And I noticed that there was extreme freezing/hanging of the ESP32 whenever a remote command was being sent via the ESP-NOW WiFi connection.
- Broken setup: The left light strip is connected to a WiFi + Ethernet board, where the Ethernet cable is plugged in and connected, and ESP-NOW (WiFi remote) is enabled.
- Good setup: The right light bar is connected to a WiFi board, which is connected to home WiFi + ESP-NOW (WiFi remote).
- At 0:02: Pressing "off". The right strip immediately turns off.
- At 0:12: The left strip (Ethernet strip) finally turns off too. 10 seconds after it received the ESP-NOW "lights off" command!
- At 0:16: Pressing "on". The right strip immediately turns on.
- At 0:21: The left strip finally turns on too. 5 seconds later.
- At 0:24: Pressing "off". The right strip immediately turns off.
- At 0:45: The left strip finally turns off too. 21 seconds later!
Video demonstration:
ESP32_Hanging.mp4
Initially, I thought it was just some simple bug in WLED's remote control code. But the true reason turned out to be horrifying. I have now unfortunately found out why ESP-NOW is such a dangerous thing on ESP32 Ethernet boards. There's... a severe ESP32 hardware bug! It was discovered by ESP32 staff in August 2024, and it's way more severe than just ESP-NOW:
- When WiFi is actively transmitting or receiving data for any reason, the ESP32's PLL clock signal becomes unstable and starts outputting random nonsense timings.
- Many ethernet boards use the ESP32's clock output for the Ethernet chip to avoid buying external and possibly broken crystals (which would require extra testing of each board to make sure the external crystal works, etc etc). This ESP32 feature was meant to simplify the board design and end up with a very reliable board (or so we thought). Lots of WLED boards do it, because it was the perfect, "intended purpose" of that ESP32 clock output signal. It's therefore extremely painful and unfortunate that the ESP32 hardware has turned out to be totally broken...
- Why it hangs: When WiFi data is being transmitted, it throws off timing of all the PLL clock signals. The broken timings are then routed into the Ethernet chip. In turn, that chip creates havoc in its decoding of Ethernet data and the operation of the Ethernet chip. The Ethernet data signal becomes unstable, which breaks the communication between the ESP32 and the Ethernet chip, and the ESP32 chip itself can then freeze for a long time as it tries to make sense of the chaos.
- When it happens, there's around 5-25 seconds of freezing in the ESP32 core. Possibly even crashing it in some cases. This ESP32 hanging/slowdown is random, since it only happens if WiFi transmits data at the exact same time that the Ethernet chip is doing something important (such as sending/receiving/transcoding Ethernet data).
- I'll say that again: The freezing is intermittent, because the unstable PLL clock needs to happen at a critical moment where the clock instability then causes cascading failures in the communication between the ESP32 and the Ethernet chip!
So what scenarios will enable WiFi + Ethernet at the same time in WLED and trigger the hardware bug?
- Enabling the ESP-NOW (remote control) feature in WLED. As you can see on Espressif's feature page, that protocol uses WiFi (if it can, it uses a direct connection between the ESP32 and the remote) and Bluetooth (fallback). If it then connects to a remote, the resulting WiFi signal activity breaks the ESP32's PLL clock.
- Connecting to the WLED-AP (WiFi AP) for any reason whatsoever while the Ethernet cable is connected to the ESP32. That WiFi activity definitely breaks the PLL clock.
- ESP-NOW and WLED-AP are both high-impact and will trigger the bug rapidly since they cause lots of WiFi activity.
- Background beacons/pings are constantly being sent or received in the background by the WiFi antenna on the ESP32. The WiFi portion of the ESP32 is always listening, so depending on the size of those beacons/durations, there's a strong likelihood that they will also create enough fluctuations in the PLL clock signal to cause issues on Ethernet boards. This means that even if WLED-AP is unused by clients and ESP-NOW is disabled, there can still be instabilities in the ESP32's PLL clock signal if the WiFi antenna is enabled (since it's passively receiving/sending WiFi network advertisement beacons).
What are the immediate impacts:
- Ethernet boards which use the ESP32 as clock source (for anything) are impacted.
- Ethernet boards which use external crystals are not impacted.
- Boards without an ethernet chip are not impacted.
Hardware documentation:
I found the hardware bug details via the following ESP32 hardware errata page, and there's a discussion where it was originally discovered:
- https://docs.espressif.com/projects/esp-chip-errata/en/latest/esp32/03-errata-description/esp32/clock-rmii-clock-when-using-ethernet-and-wifi.html
- https://esp32.com/viewtopic.php?t=37757
- The ESP32 errata is very clear: You MUST disable the WiFi antenna if your ESP32 board uses the PLL clock output for an Ethernet chip. There are NO workarounds.
So how does this affect WLED:
- In the past, in WLED 0.14.x and earlier, some WLED developer had experienced this exact issue when they were testing ESP-NOW, but they weren't fully sure what was going wrong, so they just added a flag to disable ESP-NOW remotes in all Ethernet builds as a "blanket fix". Their code comment was
-D WLED_DISABLE_ESPNOW ;; ESP-NOW requires wifi, may crash with ethernet only. But that was unfortunately a misunderstand of the true severity of what was happening... - In WLED 0.15.x, someone assumed there was no issue anymore. Most likely because someone tested an Ethernet board that doesn't use the ESP32 as PHY clock, and they didn't see any instability when ESP-NOW and Ethernet were enabled together. So the flag was removed and now every Ethernet build of WLED contains ESP-NOW support.
- But the hardware bug still exists in the latest ESP32 hardware revision. So the issue still exists. It doesn't just impact ESP-NOW. It's triggered by any WiFi activity at all!
How we can improve the situation in WLED's code to minimize the harm:
- Document the quirk for users. So if they see extreme slowdown/loss of Ethernet packages or slowdown of their ESP-NOW-based remote, they know that the hardware has freaked out and will take 5-20 seconds to fix itself and start responding again. It doesn't seem to fully crash the device - but a full crash (which doesn't recover itself) could possibly happen too, since the old WLED comment mentioned crashes as the reason for disabling ESP-NOW on Ethernet boards.
- It may be possible to reduce the impact dynamically in a surgical way:
- WLED's internal list of Ethernet boards already contains a list of which boards use the ESP32's GPIOs as Ethernet clock output.
- Therefore, the WLED code for the ESP-NOW remote checkbox "enable" can check all conditions:
- Is the board Ethernet based, and does it use ESP32's clock GPIOs as PHY clock? Then refuse to enable ESP-NOW in WLED and display a small error to the user which explains that their hardware uses ESP32 for Ethernet clock which is totally incompatible with ESP-NOW due to a hardware flaw in the ESP32.
- Consider following Espressif's new guidelines by adding an advanced feature which lets users completely disable the ESP32 WiFi antenna (WLED-AP) via code when an affected Ethernet board is used. That would be the most powerful and most stable mitigation if the user desires perfect board stability, if it's important for the user that the controller never randomly freezes/crashes. But of course, that mitigation method carries a high risk of users locking themselves out and needing to do a board reset. And if they can't connect via Ethernet due to having messed up their Ethernet board type selection, then they can't get in to fix the board. So this potential mitigation would require careful planning if it's adopted. It's really the only way to actually ensure 100% stable board operation, though.
- Idea for a safe implementation: If the user enables the "Advanced: ESP32 PLL Bug Mitigation" checkbox, WLED does the following at startup:
- Enable WiFi (WLED-AP) immediately if...
- ...the board doesn't have Ethernet at all.
- ...or the WLED Ethernet board type is set to something that doesn't use the ESP32 PLL as Ethernet clock. (Meaning, has an external crystal and isn't affected.)
- If an affected Ethernet board type was selected, then disable the WiFi antenna.
- Analyze the Ethernet port:
- Is a cable connected? Does it have an IP?
- If a cable is connected but it hasn't received an IP in let's say 15 seconds or so, then enable WLED-AP as a safety fallback to prevent total user lockout.
- If the ethernet cable suddenly receives an IP, then WLED-AP should be disabled automatically again. But only if no client is currently connected to WLED-AP (to avoid breaking any in-progress WLED-AP sessions such as OTA firmware updates)! If a client was currently connected, then set a flag to "disable WLED-AP after last WiFi client disconnects".
- Wait until all WiFi clients have disconnected from WLED-AP and then disable WLED-AP again. This can be achieved via an on-disconnect hook in the WLED-AP client handling code. "If 0 connections remain, check the flag to see if WLED-AP should be turned off now since the board owner wanted to use this in Ethernet-only mode."
- If the ethernet cable suddenly receives an IP, then WLED-AP should be disabled automatically again. But only if no client is currently connected to WLED-AP (to avoid breaking any in-progress WLED-AP sessions such as OTA firmware updates)! If a client was currently connected, then set a flag to "disable WLED-AP after last WiFi client disconnects".
- If the cable is not connected at all, then do nothing. Because the user has set their controller to "Ethernet only" mode, so they expect that they will need to plug in a cable to use the controller. Therefore, WiFi should stay totally disabled if no Ethernet cable is connected at startup.
- If a cable is connected but it hasn't received an IP in let's say 15 seconds or so, then enable WLED-AP as a safety fallback to prevent total user lockout.
- Is a cable connected? Does it have an IP?
- Enable WiFi (WLED-AP) immediately if...
- Idea for a safe implementation: If the user enables the "Advanced: ESP32 PLL Bug Mitigation" checkbox, WLED does the following at startup:
- WLED's internal list of Ethernet boards already contains a list of which boards use the ESP32's GPIOs as Ethernet clock output.
I assume that the Espressif SDK provides enough callbacks/events for WiFi and Ethernet connection state changes (on-connect, on-disconnect, physical cable connection status, assigned IP status, etc), which would really simplify the implementation.
"Can't we just unplug the Ethernet cable?"
- If you're wondering whether ESP-NOW is safe and stable if someone owns an Ethernet board, but only uses the WiFi connection, and hasn't plugged in a cable: I don't know, but most likely not. The Ethernet chip is still connected to the hardware and doing its thing, so it will still be receiving a whacky clock signal that breaks the communication between the ESP32 and the Ethernet chip. And when that chip communication breaks, the ESP32 can hang for a while.
- It's not safe to assume that it will be stable if the Ethernet port is disconnected. And I don't want to try testing whether the Ethernet chip is happy with receiving a broken clock signal whenever no cable is attached. Because there could be severe race conditions with specific timings, which means that it could take a very long time to hit the correct conditions for some catastrophic timing failure, such as a total hardware crash that only happens if the clock signal breaks at exactly the worst time during the Ethernet chip's internal processes, etc. It would take way too much time and observation to investigate that possibility.
- The simplest fact is that the ESP32 PLL can never be trusted when WiFi is active on the ESP32. How all the chips on the board handle that fault condition (either freezing, recovering, crashing etc) is too complicated to investigate.
What can users do to mitigate the hardware bug:
- If your board doesn't have Ethernet at all: It's totally unaffected.
- If your Ethernet board has an external clock crystal: You don't need to do anything. The broken clock signal is not being sent to the Ethernet chip.
- If your Ethernet board uses the ESP32 clock for Ethernet:
- If you want to connect to the controller via WiFi:
- Unplug any ethernet cable you may have had on the board.
- Use WiFi to connect to the WLED controller.
- Feel free to use ESP-NOW and WLED-AP, since you are entirely within the WiFi ecosystem.
- But if you see any long, severe ESP32 freezes, it's possible that the Ethernet chip is still freaking out about the unstable clock from all the WiFi activity (it's a possibility, as mentioned in the previous section). In that case, consider going wired instead.
- If you want to connect to the controller via Ethernet:
- Disable the ESP-NOW remote support. (It's off by default in WLED's settings, though.)
- Do not use the WLED-AP WiFi connection. Always use the Ethernet port's IP instead.
- If WLED gets an option to disable the WiFi antenna on affected Ethernet boards in a safe way without risk of user lockout, you can consider enabling that if you want total stability.
- If you want to connect to the controller via WiFi:
To Reproduce Bug
See above.
Expected Behavior
See above.
Install Method
Binary from WLED.me
What version of WLED?
- ESP-NOW support has been added to all Ethernet versions of WLED from 0.15.x and newer.
- Every ESP32 controller is affected, regardless of WLED version. But the only boards that use the PLL clock signal for anything are connecting it to Ethernet controller chips, so if the board doesn't have Ethernet, it's completely unaffected.
Which microcontroller/board are you seeing the problem on?
ESP32
Relevant log/trace output
Anything else?
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
[-]ESP-NOW must be disabled on ESP32 Ethernet boards that use GPIO17 as clock source[/-][+]ESP-NOW must be disabled on ESP32 Ethernet boards that use ESP32 as PHY clock source[/+][-]ESP-NOW must be disabled on ESP32 Ethernet boards that use ESP32 as PHY clock source[/-][+]ESP-NOW must be disabled on ESP32 Ethernet boards that use ESP32 as PHY clock source; WLED-AP is affected too![/+]blazoncek commentedon May 30, 2025
AFAIK when you connect Ethernet, WiFi is turned off (
WiFi.diconnect(true); see here for 0.15.x).However AP mode cannot be disabled outright as that may prevent users from recovering. ESP-NOW is an optional feature, not enabled by default.
IMO it would suffice to do one (or both) of the following for when Ethernet cable is plugged in:
enableESPNow = false;if users enabled ESP-NOW (perhaps a bit more detailed but that's the principle)Regarding unconnected Ethernet being affected with broken PLL: It doesn't matter that much as no Ethernet code is touched in WiFi mode. It should resolve when cable is plugged in.
Arcitec commentedon May 30, 2025
enableESPNow = falsewhen the user plugs in a cable would break the Ethernet boards that have external crystals and could safely have both features (WiFi remote control and Ethernet cable). So my post had an idea for an algorithm that could disable it only for the boards that are broken.By the way, I vaguely remember that some pull request was working on a feature to allow WiFi and Ethernet at the same time. If I don't totally misremember. So that pull request would need scrutiny if someone was trying to contribute such a feature.
My brain is very tired right now, but I think it seems necessary to do board detection and some of the smarter algorithms I mentioned so that WiFi and Ethernet can coexist on boards that support it in hardware.
I'll have a look later at the potential mitigations again, with the info you provided. The difficulty will be in having an algorithm that protects vulnerable boards (detectable via the pinout configs in WLED's source code) but still allows WiFi/ESP-NOW and Ethernet to coexist on safe boards.
blazoncek commentedon May 30, 2025
Are you aware of any boards with independent clock signal supported by WLED? I am not. All of the supported boards use ESP's clock generator AFAIK.
Arcitec commentedon May 30, 2025
I have seen one board that seems to use an external crystal, but this example was purely from memory since I remembered being curious and clicking this link once:
WLED/wled00/network.cpp
Line 139 in 4a3af81
That link has been moved here nowadays:
https://github.com/Xinyuan-LilyGO/LilyGO-T-ETH-Series/blob/master/schematic/T_POE_Pro(Final).pdf
Download the schematic file, since GitHub is terrible and doesn't let you zoom PDFs to see the details.
You can see in the top left corner that they're connecting a 25 MHz crystal and its supporting components to the XTAL1/XTAL2 pins (which are for interacting with both poles of external crystals). The 8720A ethernet chip is capable of operating with either 25 MHz or 50 MHz (preferable) external crystals, and this board chose a 25 MHz crystal.
If you use a pure ESP32 clock, you would not need to connect both XTAL1 and XTAL2. Therefore, this board schematic definitely uses an external crystal. You can even see the crystal (marked "Y1") on the schematic.
However, looking closer at it... the board still requests a 50 MHz ESP32 clock to go out via GPIO0, and then passes it into a TI SN74AUP1T14 logic inverter gate. Which makes sense since the GPIO0 pin has the opposite PLL clock polarity than the GPIO17 pin. So they are also taking the ESP32 clock, fixing the polarity to make it the same as what would have come out of GPIO17, and then they do the strangest thing I can ever imagine: They combine the 25 MHz and 50 MHz clock signals on the exact same XTAL1/XTAL2 ethernet chip pins.
So... on final inspection, the T-POE seems to be a misdesigned board that has totally failed to understand how to correctly hook up a LAN8720A chip, and uses both a crystal and the ESP32 signal. That schematic is a mess.
Edit: Upon checking network.cpp, it seems highly likely that every WLED Ethernet board in the world uses GPIO0 or GPIO17, meaning the ESP32 PLL signal. So it seems like every board is indeed vulnerable.
Arcitec commentedon May 30, 2025
Alright, I've analyzed the scenarios where users are affected, and which scenarios already mask/hide the issue. This also helps us understand why it hasn't been discovered sooner.
The issue (a quick summary for anyone who's reading for the first time): Anytime the ESP32's WiFi radio ( is enabled while the ESP32 has been told to also communicate with an Ethernet chip, the ESP32 can freeze/hang or even crash. Because the WiFi radio interferes with the ESP32's clock signal output, which is used by most WLED Ethernet boards.
There's only a few conditions in WLED's codebase where that hardware bug will be triggered. All of these scenarios below require a WLED board that has an Ethernet chip! It will not happen on WiFi-only boards!
WiFi-network users:
Ethernet-network users:
So we're closer to having a better overview and plan for how to solve this... What do you think? Does anyone have ideas for any other solutions?
Arcitec commentedon May 30, 2025
To support the addition of boards that will be using external clock crystals to fix the hardware bug, we will need to add a feature in the WLED source code, where
network.cppwill be able to define aneth_clk_modeofNone(by setting it toETH_CLOCK_EXTERNAL, which could have the internal value-1).When clock mode is set to
-1, WLED should then simply ignore the PLL output mode-setting, and let the board hardware deal with the PHY clock.I've looked through the
ETH_CLOCKconstants and see that there's only support for GPIO0, 16, and 17. No support for "None" yet:WLED/wled00/wled_ethernet.h
Lines 14 to 19 in 4a3af81
We'll also need to investigate how to tell the ESP32 SDK that the Ethernet clock is external, and that it shouldn't be controlled by the ESP32's PLL output. It's some flag in the
ETH.begincall. ProbablyEMAC_CLK_EXT_IN, but the documentation is terrible:https://docs.espressif.com/projects/arduino-esp32/en/latest/api/ethernet.html
Edit: In fact, it seems like all the GPIO clock constants used by WLED come from the ESP32 SDK. In that case, they already have a name for the "use external clock" constant somewhere in their SDK. Let's investigate and find the name inside the actual SDK headers, to confirm whether
EMAC_CLK_EXT_INis correct or not...Arcitec commentedon May 30, 2025
Here's something worth being aware of during all planning:
< 3.2found", to make all mitigations conditional in the future. But if such an SDK call doesn't exist, then another method is needed to distinguish the working chips.Arcitec commentedon Jun 11, 2025
While designing my own board, I now know exactly how we can identify Ethernet boards where we must block WiFi/ESP-Now:
We can simply look at the available clock signal constants:
https://github.com/espressif/arduino-esp32/blob/0f72681fa02f61cd2acf5025ea16451422c48c42/libraries/Ethernet/src/ETH.h#L83-L88
Affected boards (can't enable WiFi/ESP-Now + Ethernet at the same time):
ETH_CLOCK_GPIO0_OUT(ESP32 provides 50MHz clock output via GPIO0) (Edit: As a sidenote, this is a terrible configuration for another reason, because the ESP32 PLL cannot generate a clock output on GPIO 0 when you use I2S peripherals such as microphones, so the GPIO0 OUT stops outputting anything when I2S is enabled. The other clock outputs (16/17 below) can do I2S at the same time.)ETH_CLOCK_GPIO16_OUT(ESP32 provides 50MHz clock output via GPIO16)ETH_CLOCK_GPIO17_OUT(ESP32 provides 50MHz clock output via GPIO17)Safe boards (these can enable WiFi/ESP-Now + Ethernet the same time):
ETH_CLOCK_GPIO0_IN(External oscillator, clock input received via GPIO0)The Ethernet MAC is in the ESP32 and the PHY is in the external chip (LAN87x0A etc). They must always be synced to the same clock. The ESP32 has only one mode that tells us that an external clock signal exists. That's
ETH_CLOCK_GPIO0_IN.So this is the easy test condition:
ETH_CLOCK_GPIO0_IN, we will allow WiFi + Ethernet at the same time.github-actions commentedon Oct 11, 2025
Hey! This issue has been open for quite some time without any new comments now. It will be closed automatically in a week if no further activity occurs.
Thank you for using WLED! ✨
Add independent Ethernet/WiFi IP config and primary network interface…
Add independent Ethernet/WiFi IP config and primary network interface…
Add independent Ethernet/WiFi IP config and primary network interface…
Add independent Ethernet/WiFi IP config and primary network interface…
Add independent Ethernet/WiFi IP config and primary network interface…
Add independent Ethernet/WiFi IP config and primary network interface…