class LAN – control an Ethernet interface

The LAN class drives the MCU’s on-chip Ethernet MAC against an external RMII PHY. The PHY type, MDIO address and pinout are all board-specific; sensible defaults are baked into each OpenMV board so the constructor normally takes no arguments.

Available on:

  • OpenMV Cam N6 (STM32 port) – default PHY PHY_LAN8742.

  • Arduino Portenta H7 (STM32 port) – default PHY PHY_LAN8742.

  • OpenMV Cam RT1062 (mimxrt port) – default PHY PHY_KSZ8081.

Example usage:

import network

nic = network.LAN()
nic.active(True)

while not nic.isconnected():
    pass

print(nic.ipconfig("addr4"))

Constructors

class network.LAN(id: int = 0, *, phy_type: int | None = None, phy_addr: int | None = None, ref_clk_mode: int | None = None) None

Construct a LAN interface object. All arguments after id are keyword-only.

id selects the Ethernet port on boards that expose more than one (mimxrt port: 0 = ENET, 1 = ENET_1). Ignored on STM32 boards, which only have a single MAC.

phy_type selects the PHY driver (one of the PHY_* constants below). Pass None (the default) to use the PHY wired to the OpenMV board.

phy_addr is the MDIO address of the PHY on the management bus. Pass None (the default) to use the board’s wired value.

ref_clk_mode (mimxrt only) selects whether the RMII reference clock is driven by the MAC (OUT) or by the PHY (IN). Ignored on STM32 boards.

Methods

active(is_active: bool | None = None) bool

Bring the Ethernet MAC up or down.

With no argument, return the current PHY link status as a truthy/falsy integer – see status() for the full set of encoded values.

active(True) starts the MAC and PHY, kicks off auto-negotiation, and brings the lwIP netif up. Link-up itself may take a moment to complete – poll isconnected() if you need to block until the link is fully ready. All other methods (ipconfig(), config(), …) require the interface to be active.

active(False) stops the MAC and tears down the netif.

isconnected() bool

Return True when the PHY has negotiated link-up and the interface is in the fully-up state (link status value 3).

status() int

Return the raw PHY link status as an integer:

  • 0 – link down.

  • 1 – link up (PHY only, IP stack not yet ready).

  • 2 – transitioning.

  • 3 – link up and the IP stack has finished bringing the interface up.

ifconfig(config: Tuple[str, str, str, str] | None = None) Tuple[str, str, str, str] | None

Get or set IPv4 interface parameters as a 4-tuple of (ip, subnet, gateway, dns) dotted-quad strings.

Note

Prefer ipconfig() for new code:

nic.ipconfig(addr4="192.168.0.4/24", gw4="192.168.0.1")
network.ipconfig(dns="8.8.8.8")
ipconfig(param: str) Any
ipconfig(**kwargs: Any) None

Get or set IPv4 / IPv6 interface parameters. Behaves the same as AbstractNIC.ipconfig() – see that method for the full list of supported parameter names (dhcp4, addr4, gw4, autoconf6, addr6, …).

config(param: str) Any
config(**kwargs: Any) None

Get or set Ethernet-specific interface parameters.

With a single positional string argument, return the value of that parameter:

  • "mac" – the interface MAC address as a 6-byte bytes object.

With keyword arguments, set one or more parameters:

  • trace=<int> – enable lwIP tracing. Bit-field: 2 traces TX, 4 traces RX, 8 enables full tracing.

  • low_power=<bool> – enable or disable the PHY’s IEEE 802.3az (Energy Efficient Ethernet) low-power mode.

Constants

PHY_LAN8742: int

Microchip LAN8742A 10/100 Ethernet PHY. STM32 port only; default on the OpenMV Cam N6 and Arduino Portenta H7.

PHY_LAN8720: int

Microchip LAN8720 10/100 Ethernet PHY. Available on both STM32 and mimxrt ports.

PHY_DP83848: int

Texas Instruments DP83848 10/100 Ethernet PHY. Available on both STM32 and mimxrt ports.

PHY_DP83825: int

Texas Instruments DP83825 10/100 Ethernet PHY. Available on both STM32 and mimxrt ports.

PHY_KSZ8081: int

Microchip KSZ8081 10/100 Ethernet PHY. mimxrt port only; default on the OpenMV Cam RT1062.

PHY_DP83867: int

Texas Instruments DP83867 gigabit Ethernet PHY. mimxrt port only.

PHY_RTL8211F: int

Realtek RTL8211F gigabit Ethernet PHY. mimxrt port only.

IN: int

Pass to ref_clk_mode so the RMII reference clock is driven by the PHY. mimxrt port only.

OUT: int

Pass to ref_clk_mode so the RMII reference clock is driven by the MAC. mimxrt port only.