Repository navigation
esp32 network: Add Ethernet (EMAC + RMII PHY) - #2419
Conversation
bettio
left a comment
There was a problem hiding this comment.
The PR is good but it requires some improvements.
The biggest missing thing are tests, CI already runs an OpenCores Ethernet MAC on QEMU here for test_net, test_socket and test_ssl. Please make the new path testable on it: under CONFIG_ETH_USE_OPENETH, have start_eth create the MAC with esp_eth_mac_new_openeth and the PHY with esp_eth_phy_new_dp83848 at address 1, as eth_start() does, instead of esp_eth_mac_new_esp32. Then add a test_eth.erl sim test, gated like the other QEMU cases, that checks: network:wait_for_eth/1 returns {ok, IpInfo}; the callbacks arrive in order started, connected, got_ip; network:stop/0 followed by a second wait_for_eth succeeds (exercises stop_eth); and a run that returns without network:stop/0, as test_wifi_teardown does, so the driver destroy path is covered. Set autonego_timeout_ms to 100 as the harness does to keep it fast, and add CONFIG_AVM_ENABLE_ETHERNET=y to src/platforms/esp32/test/sdkconfig.defaults once the option exists.
Also about commit 185b311 (esp32 network: Add Ethernet (EMAC + RMII PHY)):
The extraction of start_wifi from start_network is a pure move mixed into the feature, so the start_network hunk reads as a move plus edits and cannot be checked mechanically. Please split it into its own commit ahead of this one (esp32 network: Refactor start_network into start_wifi, no behaviour change), as the git guide asks: Refactor first, then Feature. The body of this commit is good as it is.
See also my other comments
99b35a2 to
674b6a7
Compare
|
Thanks for the thorough review! Pushed a new version (force-push, rebased on release-0.7), now three commits:
Point by point:
@UncleGrumpy on interface priority: commit 3 adds Not hardware-tested yet: the driver code is the same our boards run on our fork, but this new version will only be tested on real hardware (Dingtian DT-R002 and LilyGO T-Internet-COM) on Monday. I'll report the results here. |
|
Thank you! That’s great for now, we can always add interface priorities for WiFi later, in case someone wants to prefer AP over STA, but that seems like a rare case. |
|
CI found real problems besides the Docker Hub rate limit; pushed a fix commit on top (happy to squash):
Checked locally in QEMU with the memory-check build (IDF 5.5.5): esp32, esp32s3 and esp32c3 (the last with #2423) pass The hardware test moves to Tuesday; I'll report here. |
|
You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool. What Enabling Code Scanning Means:
For more information about GitHub Code Scanning, check out the documentation. |
|
Pushed 00961d8 for the ESP32-S3 USB CDC job: In QEMU (memory-check build, IDF 5.5.5): esp32s3 passes Hardware test today; I'll report here. |
|
Hardware test of 00961d8 (ESP-IDF 5.5.5,
Both with
Each |
|
The two red jobs are the ones expected until #2423 is merged: on esp32c3 (IDF 5.4.4 and 5.5.5) |
3c58f24 to
e8b5bd7
Compare
bettio
left a comment
There was a problem hiding this comment.
Few minor fixes are required.
|
Thanks! The three fixes are in 3e9b784, details in each thread. About the CI run on e8b5bd7: |
|
Hardware test of 3e9b784 on a LilyGO T-Internet-COM (ESP32-WROVER-E, LAN8720,
No resets or watchdog. Each |
|
late here, few AMP code review things, I suggest punting the mdns issue, and fix it later.. Review: AtomVM PR #2419
1. P2:
|
|
Thanks @petermm, all three checked against the code:
QEMU (memory-check build, ESP-IDF v5.5.5): esp32 and esp32c3 suites pass ( |
4da38ed to
f6c6384
Compare
|
Rebased on |
bettio
left a comment
There was a problem hiding this comment.
We are good at 99%, so mostly there, mostly some cleanup in comments, and let's cleanup history.
Briefly we should cleanup branch history as described in GIT_WORKFLOW_AND_HISTORY_STYLE_GUIDE.md:
- Four fix-up commits patch the feature commit 1ff89c9 within the same PR: f795569, ab94087, 2003816, f6c6384.
- The feature commit alone does not build. 1ff89c9 enables the Ethernet option in the test sdkconfig while the driver stops at #error below IDF 5.4, so the test app fails on 5.2 and 5.3 until f795569. That breaks bisect.
- Subject lines over the 50-character limit: f6c6384 at 68, 2003816 at 57, dfce29e at 53. One body line of 73 columns in f6c6384.
- Also I suggest to cleanup the PR description on GitHub, we use it as merge-commit body. I suggest to keep it shorter and it should work as a recap for the PR. So it should say what the PR does, briefly how, etc...
f6c6384 to
07e854f
Compare
|
Thanks @bettio! History cleaned up and rebased on
The final tree is the same as before apart from the rebase; QEMU (esp32) passes at the driver commit and at the head. |
Move the WiFi part of start_network (interfaces, esp_wifi_init, event handlers, mode, STA/AP config and esp_wifi_start) into start_wifi, so another interface can be started next to it. No behaviour change: start_wifi replies to the caller and returns false where start_network jumped to cleanup. Signed-off-by: Gabriel Mancini <gabriel.mancini@gmail.com>
Boards like the Dingtian DT-R002 or the LilyGO T-Internet-COM have a
LAN8720-class PHY on the ESP32's EMAC and nothing in AtomVM could bring
it up. network:start/1 now accepts {eth, [...]}, alone or next to sta
and ap: mdc, mdio, rmii_clock ({in | out, Gpio}), power, reset,
phy_addr (default: first PHY found), dhcp_hostname, and the started,
connected, disconnected and got_ip callbacks. WiFi is only initialized
when sta or ap is given. network:wait_for_eth/0,1,2 and
network:eth_status/0 mirror their STA counterparts, eth_status/0 is
connected once there is an IP, as for STA, and the mDNS responder binds
to the Ethernet address when there is one. sta_connect/1 keeps a running
Ethernet as it is, and wait_for_eth/2 returns the reason the driver
refused a configuration instead of timing out.
Ethernet is opt-in with CONFIG_AVM_ENABLE_ETHERNET (default n), on
ESP-IDF 5.4 or newer; on older ones the option has no effect. Without
it, or on a chip without an EMAC, an eth entry makes network:start/1
return {error, eth_not_supported}. Pins and phy_addr are validated
(badarg), pins bounded by GPIO_PIN_COUNT first, since the GPIO_IS_VALID
macros shift by the pin number; pin defaults come from
ETH_ESP32_EMAC_DEFAULT_CONFIG(), and the GPIO16/17 PSRAM handling
applies to the classic ESP32 only. A pin configuration the MAC rejects
is ESP_FAIL, with a log line, rather than ESP_ERR_NO_MEM.
Auto-negotiation waits 100 ms at start, so a missing cable does not
stall the scheduler. start_eth undoes its own work on failure, and stop
releases the power pin.
Under CONFIG_ETH_USE_OPENETH the driver uses QEMU's OpenCores MAC with a
DP83848 at address 1, so test_eth and test_eth_teardown run in the QEMU
suite on IDF 5.4 or newer, except in JIT-only builds, which have no
precompiled avm_network; an esp32 IDF 5.4 job builds the option.
Signed-off-by: Gabriel Mancini <gabriel.mancini@gmail.com>
esp_netif's default route priority for ETH (50) loses to STA's (100):
with both up, traffic went over WiFi even with a cable plugged in.
Ethernet now defaults to 128, so a cable, when there is one, carries
it; {route_priority, 0..255} in the eth entry overrides it, e.g. to
keep WiFi preferred.
Signed-off-by: Gabriel Mancini <gabriel.mancini@gmail.com>
|
Thanks @bettio! Removed the six comments, each from the commit that added it, so the history stays three commits that build:
Comments only, the code is unchanged. |
07e854f to
5eed805
Compare
|
Approved. Do not change this PR: it has been already merged locally. |
Adds Ethernet to the ESP32
networkmodule, for boards with a LAN8720-class PHY on the EMAC (Dingtian DT-R002, LilyGO T-Internet-COM).network:start/1accepts{eth, [...]}, alone or next tosta/ap: the MDIO and RMII clock pins, PHY power and reset,phy_addr,route_priority,dhcp_hostname, and thestarted,connected,disconnectedandgot_ipcallbacks.network:wait_for_eth/0,1,2andnetwork:eth_status/0mirror their STA counterparts, and mDNS binds to the Ethernet address when there is one. With both up, Ethernet carries the default route unlessroute_prioritysays otherwise.Ethernet is opt-in with
CONFIG_AVM_ENABLE_ETHERNET, on ESP-IDF 5.4 or newer; otherwise anethentry returns{error, eth_not_supported}.Commits:
start_networkintostart_wifi(no behaviour change).test_ethandtest_eth_teardownin the QEMU suite.Tested in QEMU (esp32) at each commit, and on a DT-R002 and a T-Internet-COM (link, DHCP, cable pull/plug,
ethwithsta).These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later