Skip to content

Add native Ethernet mii support - #11511

Open
tannewt wants to merge 7 commits into
adafruit:mainfrom
tannewt:ethernet
Open

tannewt wants to merge 7 commits into
adafruit:mainfrom
tannewt:ethernet

Conversation

@tannewt

@tannewt tannewt commented Oct 6, 2026

Copy link
Copy Markdown
Member

MII is the family of bus protocols used to connect a SoC's MAC to an Ethernet PHY.

It works similar to wifi but the singleton is on the board module instead of wifi.

@tannewt
tannewt force-pushed the ethernet branch 2 times, most recently from 74f0fe0 to 1789180 Compare October 6, 2026 19:13
It works similar to `wifi` but the singleton is on the `board` module
instead of `wifi`.
@tannewt
tannewt requested a review from dhalbert October 8, 2026 21:41

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Very clean code. A few things to address, including documentation.

Comment on lines -1 to -6
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
//
// SPDX-License-Identifier: MIT

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lines 1-6 header seems to have been deleted inadvertently.

Comment thread py/circuitpy_mpconfig.mk
CFLAGS += -DCIRCUITPY_IO_IOBASE=$(CIRCUITPY_IO_IOBASE)

CIRCUITPY_IPADDRESS ?= $(CIRCUITPY_WIFI)
CIRCUITPY_IPADDRESS ?= $(call enable-if-any,$(CIRCUITPY_WIFI) $(CIRCUITPY_MII))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about making a CIRCUITPY_NETWORKING or CIRCUITPY_NETWORK which is $(call enable-if-any,$(CIRCUITPY_WIFI) $(CIRCUITPY_MII)) ? That can be used a number of places.

Comment on lines +11 to +20
//| """
//| The `mii` module provides necessary low-level functionality for managing
//| wired ethernet connections through a Media-indepentent interface (MII)
//| bus. Use `socketpool` for communicating over the network.
//|
//| The `mii.Ethernet` object(s) are available as ``board.ETHERNET`` on boards
//| with onboard ethernet. The interface is enabled and DHCP is started
//| automatically.
//| """
//|

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation should mention RMII.

Comment on lines +51 to +54
//| Boards with onboard ethernet provide it as ``board.ETHERNET``. On
//| Espressif ports, further interfaces can be created by wiring an external
//| RMII PHY and constructing `mii.RMII` from its wiring. The interface
//| is enabled and DHCP is started automatically.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use more explanation of MII vs RMII, including definitions and maybe what might be found on a board.

Comment on lines +13 to +20
//| """External RMII bus wiring for the built-in ethernet MAC.
//|
//| Pass the pins the PHY is wired to: ``mdc`` and ``mdio`` for its SMI,
//| ``rxd0``, ``rxd1`` and ``rx_dv`` into the MAC, ``txd0``, ``txd1`` and
//| ``tx_en`` out of it, ``refclk`` for the 50 MHz reference clock and,
//| optionally, ``reset`` for its active-low reset. The bus can be shared
//| by two `mii.Ethernet` interfaces on chips with more than one MAC;
//| the PHYs are distinguished by their MDIO ``device`` number.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define RMII, and MDIO some more. This may be opaque to the average user.

Comment on lines +24 to +29
// The object is not zeroed on allocation. Without this, cert_buf.buf holds
// heap garbage, wrap_socket() takes that for a client certificate and feeds
// it to mbedtls_pk_parse_key(), which fails with MBEDTLS_ERR_PK_BAD_INPUT_DATA
// -- surfacing as the confusing "invalid key" on every default-context TLS
// connection (garbage is usually small ints; the exception only appears
// when the heap happens to hold nonzero junk, e.g. after other network use).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is overly explanatory and sounds like "I fixed this bug". The point is that it's not initialized on allocation, but the fields must be initialized or bad values will be used.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants