Skip to content

esp32: Add LAN8670. #16421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged

esp32: Add LAN8670. #16421

merged 1 commit into from
May 16, 2025

Conversation

dpgeorge
Copy link
Member

@dpgeorge dpgeorge commented Dec 16, 2024

Summary

This adds support for LAN8670 to the esp32 port, when built with ESP-IDF v5.3 or newer.

Addresses issue #15731.

Testing

This is untested.

Trade-offs and Alternatives

Merging this PR won't cause LAN8670 support to be available in the nightly builds until we update the ESP-IDF version there to V5.3.x. This will probably happen after the MicroPython 1.25.0 release.

@dpgeorge
Copy link
Member Author

@JohannesMaierhofer @DuaneKaufman are you able to test this PR?

@DuaneKaufman
Copy link

DuaneKaufman commented Dec 16, 2024 via email

@xorbit
Copy link
Contributor

xorbit commented Jan 3, 2025

@dpgeorge I tested this on a board with LAN8671 chip and when I try to create the LAN object I get this error:

>>> lan = network.LAN(mdc = machine.Pin(8), mdio = machine.Pin(7),
...                   power = None, phy_type = network.PHY_LAN8670, phy_addr=0)
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
OSError: esp_eth_driver_install failed with invalid argument

Which is odd, because on the same board, a previously hacked together proof-of-concept MicroPython build initializes the LAN8671 as expected without error. Not sure what the difference is.

@xorbit
Copy link
Contributor

xorbit commented Jan 3, 2025

Oh, if I run it again after that failure, I get an extra error:

>>> lan = network.LAN(mdc = machine.Pin(8), mdio = machine.Pin(7),
...                   power = None, phy_type = network.PHY_LAN8670, phy_addr=0)
E (2977611) esp_netif_lwip: esp_netif_new_api: Failed to configure netif with config=0x3ffd74fc (config or if_key is NULL or duplicate key)
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
OSError: esp_eth_driver_install failed with invalid argument

@projectgus projectgus self-requested a review January 6, 2025 23:51
@projectgus
Copy link
Contributor

projectgus commented Jan 29, 2025

I tested this on a board with LAN8671 chip and when I try to create the LAN object I get this error:

@xorbit There was a bug, the LAN8670 was accidentally grouped with the SPI/Ethernet PHYs so it failed to install. I've pushed an updated commit and it should work now, but I'm not able to test it apart from verifying that the install step passes.

@xorbit
Copy link
Contributor

xorbit commented Jan 29, 2025

I tried this new commit and it seems to work on my boards. 👍

However, I had some problem with the make submodules not pulling in berkeley db, I needed to apply this fix first:
https://github.com/orgs/micropython/discussions/10658

Anyway, that's not really related to this PR I think.

I was wondering if it would make sense to have the idf_component.yml defined per board?

If not, how many boards fail to build with IDF 5.3+?

@DuaneKaufman
Copy link

DuaneKaufman commented Jan 29, 2025 via email

@xorbit
Copy link
Contributor

xorbit commented Jan 30, 2025

@DuaneKaufman it is a custom board that hopefully soon will become a product. The timing of which may hinge on this PR making it into mainline MicroPython. 😆

@projectgus
Copy link
Contributor

projectgus commented Feb 3, 2025

I was wondering if it would make sense to have the idf_component.yml defined per board?

Probably not, we already have multiple copy-paste copies and changing to that we'd have dozens. However, we could maybe provide a way to override idf_component.yml for a particular board.

(I think you can already add a custom in-tree component to a board via mpconfigboard.cmake, and that component can have its own idf_component.yml file that pulls in a Component Manager component like this one. However that's likely not even a per-board solution for this case as the "main" network.LAN implementation needs to know about the PHY component...)

If not, how many boards fail to build with IDF 5.3+?

Probably none, but the question is more "are there subtle behaviour changes or regressions when built with IDF 5.3+?"

Updating the minimum IDF version boils down to two things:

  • Currently the nightly builds are done with IDF 5.2.2. We can switch this up to 5.3 at some point, but there's some risk of a subtle regression that tests haven't found. So ideally we don't do this right before a release (for example).
  • After doing that, we could drop support for IDF 5.2.x and anyone building their own board will need to update ESP-IDF. We can do this whenever we want, but it's not particularly convenient for folks (and we only dropped support for <5.2 six weeks ago, in esp32: Remove support for ESP-IDF <5.2 #16128).

There's also the bigger picture view, which is that if MicroPython has a need to keep adding support for features distributed via ESP-IDF component manager, and if these components may have particular version or platform requirements, then we may need a way to support them flexibly.

@dpgeorge dpgeorge added this to the release-1.26.0 milestone Feb 4, 2025
@projectgus
Copy link
Contributor

I've reworked this PR so that it builds a new main_esp32_idf53 component if IDF>=5.3 is in use, and the old main_esp32 component otherwise. When we drop support for ESP-IDF 5.2.x these components can be merged again.

Nightly builds currently use ESP-IDF 5.2.2 so they won't contain LAN8670 support immediately after this merges. To get support you'll need to build MicroPython locally with a newer ESP-IDF version (5.3.x or 5.4.x).

Suggest after 1.25.0 releases that we bump the build version (for nightly and CI) to use ESP-IDF 5.3.2.

@projectgus
Copy link
Contributor

projectgus commented Feb 4, 2025

I've reworked this PR so that it builds a new main_esp32_idf53 component if IDF>=5.3 is in use, and the old main_esp32 component otherwise. When we drop support for ESP-IDF 5.2.x these components can be merged again.

Turns out I didn't look hard enough at the Component Manager docs, it can do conditional dependencies just fine. 🤦 So have simplified to this!

I think we can use this technique to collapse the per-target main_xyz components down to one main component again. Have made a note to look at this when I have a chance.

@projectgus projectgus force-pushed the esp32-add-lan8670 branch 3 times, most recently from 3b3ff5b to 943e31b Compare February 5, 2025 02:50
@xorbit
Copy link
Contributor

xorbit commented Apr 3, 2025

Is there a reason this is not being merged? I'm waiting on this functionality to create a new board definition.

@projectgus
Copy link
Contributor

Is there a reason this is not being merged? I'm waiting on this functionality to create a new board definition.

Thanks for being patient. The 1.25 release has run behind and this feature is slated for 1.26. 1.25 should be released very soon, at which point we'll start merging 1.26 changes.

I've just rebased this PR on master to resolve the merge conflict.

@xorbit
Copy link
Contributor

xorbit commented Apr 8, 2025

Thank you for the update, I just wanted to ensure this wasn't lost in the shuffle. 😊

@dpgeorge dpgeorge force-pushed the esp32-add-lan8670 branch from 79e9b54 to 88c3fd4 Compare May 16, 2025 05:07
This adds support for LAN8670 to the esp32 port.  Enabled conditionally for
the esp32 target, if ESP-IDF version is new enough (v5.3 or newer).

Fixes issue micropython#15731.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Angus Gratton <angus@redyak.com.au>
@dpgeorge dpgeorge force-pushed the esp32-add-lan8670 branch from 88c3fd4 to 10f6c06 Compare May 16, 2025 05:16
@dpgeorge dpgeorge merged commit 10f6c06 into micropython:master May 16, 2025
8 checks passed
@dpgeorge
Copy link
Member Author

IDF is now at 5.4.1 and this PR is now merged. LAN8670 should be supported by the ESP32 (only) in latest downloads.

@dpgeorge dpgeorge deleted the esp32-add-lan8670 branch May 16, 2025 05:24
@xorbit
Copy link
Contributor

xorbit commented May 16, 2025

Awesome, thank you!

@DuaneKaufman
Copy link

Yes, this is good news - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants