mii – Media-independent interface (MII) is a family of standards to connect an Ethernet medium access control (MAC) peripheral to an Ethernet physical transceiver (PHY). Different versions have different pinouts depending on the pin count and Ethernet speed. Reduced pin count variants like reduced media-independent interface (RMII) and reduced gigabit media-independent interface (RGMII) are often used in microcontrollers to save pin count.

A portion of the pins in MII are for the Management Data Input/Output (MDIO) which is used to configure the PHY. Like I2C, multiple PHYs can share an MDIO because the commands include an address. This module splits the Management Data Input/Output (MDIO) definition from the MII portion because the MDIO bus can be shared between PHYs.

See: https://en.wikipedia.org/wiki/Media-independent_interface

Available on these boards
  • Adafruit Feather ESP32 V2
  • Adafruit Feather HUZZAH32
  • Adafruit HUZZAH32 Breakout
  • Adafruit ItsyBitsy ESP32
  • Adafruit Metro ESP32-P4
  • Adafruit Mini Sparkle Motion
  • Adafruit P4 GPIO
  • Adafruit QT Py ESP32 PICO
  • Adafruit Sparkle Motion
  • Adafruit Sparkle Motion Stick
  • Ai Thinker ESP32-CAM
  • CRCibernetica IdeaBoard
  • Deneyap Kart
  • Deneyap Kart 1A
  • ESP32 Devkit V1
  • ESP32-P4 Stamp XL
  • ESP32-P4-Function-EV
  • ESP32-P4X-Function-EV
  • Elecrow CrowPanel
  • Espressif ESP32 DevKitc V4 WROOM-32E
  • Espressif ESP32 DevKitc V4 WROVER
  • Espressif ESP32 TTGO T8 v1.7
  • Espressif ESP32-EYE
  • Espressif ESP32-LyraT
  • Freenove ESP32 Display 3.5 inch
  • Freenove ESP32-WROVER-DEV-CAM
  • Hardkernel Odroid Go
  • LILYGO TTGO T-DISPLAY v1.1
  • LILYGO TTGO T-DISPLAY v1.1 4M
  • Lilygo T-watch 2020 V3
  • M5Stack Atom Echo
  • M5Stack Atom Lite
  • M5Stack Atom Matrix
  • M5Stack Atom U
  • M5Stack Core Basic
  • M5Stack Core Fire
  • M5Stack Core2
  • M5Stack M5Paper
  • M5Stack Stick C
  • M5Stack Stick C Plus
  • M5Stack Stick C Plus2
  • M5Stack Tab5
  • M5Stack Timer Camera X
  • NXP Semiconductors FRDM-MCXN947 (Zephyr)
  • NXP Semiconductors FRDM-RW612 (Zephyr)
  • NXP Semiconductors MIMXRT1170-EVK (Zephyr)
  • Oxocard Artwork
  • Oxocard Connect
  • Oxocard Galaxy
  • Oxocard Science
  • Renesas Electronics Corporation RA6M5 Evaluation Kit (Zephyr)
  • Renesas Electronics Corporation RA8D1 Evaluation Kit (Zephyr)
  • SQFMI Watchy
  • STMicroelectronics Nucleo N657X0-Q (Zephyr)
  • TinyPICO
  • TinyPICO Nano
  • TinyPICO[D]
  • VIDI X V1.1
  • WeMos LOLIN32 Lite
  • Yoto Mini 2024
  • Yoto Player V3
  • sunton_esp32_2432S024C
  • sunton_esp32_2432S028
  • sunton_esp32_2432S032C

class mii.Ethernet(rmii: RMII)

Wired ethernet interface.

Boards with onboard ethernet PHYs provide it as board.ETHERNET or another distinguishing name.

Further interfaces can be created by wiring an external PHY over a variant of the media independent interface (MII) bus. See other classes in this module for supported MII variants. The interface is enabled and DHCP is started automatically.

Create another ethernet interface driving the PHY wired to rmii.

Only Espressif ports support this; Zephyr ports only serve the interface from the devicetree, available as board.ETHERNET, and raise NotImplementedError here.

enabled: bool

True when the ethernet interface is enabled. If you set the value to False, any open sockets will be closed.

connected: bool

True when the ethernet cable is plugged in and link is up. (read-only)

hostname: str | circuitpython_typing.ReadableBuffer

Hostname for the ethernet interface. When the hostname is altered after the interface is started the changes would only be reflected once the interface restarts.

mac_address: bytes

MAC address of the ethernet interface. (read-only, 6 bytes)

Link speed in Mbps (10, 100, 1000, etc.) when connected, 0 otherwise. (read-only)

full_duplex: bool

True if the link is full duplex, False if half duplex. (read-only)

ipv4_address: ipaddress.IPv4Address | None

IP v4 address when connected. None otherwise. (read-only)

ipv4_gateway: ipaddress.IPv4Address | None

IP v4 gateway address when connected. None otherwise. (read-only)

ipv4_subnet: ipaddress.IPv4Address | None

IP v4 subnet mask when connected. None otherwise. (read-only)

ipv4_dns: ipaddress.IPv4Address

IP v4 address of the DNS server to be used.

addresses: Sequence[str]

Address(es) of the interface when connected. Empty sequence when not connected. (read-only)

dns: Sequence[str]

Address of the DNS server to be used.

set_ipv4_address(*, ipv4: ipaddress.IPv4Address, netmask: ipaddress.IPv4Address, gateway: ipaddress.IPv4Address, ipv4_dns: ipaddress.IPv4Address | None) → None

Sets the IP v4 address of the interface. Must include the netmask and gateway. DNS address is optional. Setting the address manually will stop the DHCP client.

start_dhcp(*, ipv4: bool = True, ipv6: bool = False) → None

Starts the DHCP client.

By default, calling this function starts DHCP for IPv4 networks but not IPv6 networks. When the ipv4 and ipv6 arguments are False then the corresponding DHCP client is stopped if it was active.

stop_dhcp() → None

Stops the DHCP client. Needed to assign a static IP address.

ping(ip: ipaddress.IPv4Address, *, timeout: float | None = 0.5) → float | None

Ping an IP to test connectivity. Returns echo time in seconds. Returns None when it times out.

class mii.MDIO(mdc: microcontroller.Pin, mdio: microcontroller.Pin)

Management data input/output (MDIO) bus wiring.

MDIO is the two wire management bus used to configure Ethernet PHYs over an mii variant. mdc is the management data clock and mdio is the bidirectional management data line. Configuration commands on the bus address a PHY by a number between 0 and 31, so, like I2C, multiple PHYs can share one bus.

Create the MDIO bus on the given clock and data pins.

class mii.RMII(mdio: MDIO, device: int, rxd0: microcontroller.Pin, rxd1: microcontroller.Pin, rx_dv: microcontroller.Pin, txd0: microcontroller.Pin, txd1: microcontroller.Pin, tx_en: microcontroller.Pin, refclk: microcontroller.Pin, reset: microcontroller.Pin | None = None)

Reduced media independent interface (RMII) bus wiring for the built-in ethernet MAC.

RMII is a pin-reduced variant of the media independent interface (MII) family: it shifts two data bits on a pair of pins at a 50 MHz reference clock instead of running a wider bus more slowly, saving pins on microcontrollers. The PHY sends data to the MAC over rxd0 and rxd1 and marks received bytes with rx_dv (receive data valid). The MAC sends data back over txd0 and txd1 and frames it with tx_en (transmit enable). refclk is the 50 MHz reference clock, usually driven by an oscillator on the PHY.

The PHY is configured over an mii.MDIO management bus, which may be shared between interfaces; pass it as mdio. device selects the PHY’s MDIO address (0-31) on that bus, so that two mii.Ethernet interfaces on chips with more than one MAC can share it. Optionally, pass reset wired to the PHY’s active-low reset, if it has one.

Not all chips can route RMII signals freely: ports that can’t (or Zephyr ports, which take their wiring from the devicetree) raise NotImplementedError.

Create the RMII bus on the given mii.MDIO management bus, with the PHY at its MDIO device address, and the given data signals.