Skip to content

Commit 12dd9cb

Browse files
projectgusdpgeorge
authored andcommitted
docs/esp32: Add documentation for SPI Ethernet devices on esp32 port.
Also cross-link with the other WIZNET5K driver, to avoid confusion. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent b11ba39 commit 12dd9cb

File tree

3 files changed

+104
-16
lines changed

3 files changed

+104
-16
lines changed

docs/esp32/quickref.rst

Lines changed: 96 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,20 @@ calling ``wlan.config(reconnects=n)``, where n are the number of desired reconne
121121
attempts (0 means it won't retry, -1 will restore the default behaviour of trying
122122
to reconnect forever).
123123

124+
.. _esp32_network_lan:
125+
124126
LAN
125127
^^^
126128

127-
To use the wired interfaces via :class:`network.LAN` one has to specify the pins
128-
and mode ::
129+
Built-in MAC (original ESP32)
130+
"""""""""""""""""""""""""""""
131+
132+
The original ESP32 SoC has a built-in Ethernet MAC. Using this MAC requires an
133+
external Ethernet PHY to be wired to the chip's EMAC pins. Most of the EMAC pin
134+
assignments are fixed, consult the ESP32 datasheet for details.
135+
136+
If the PHY is connected, the internal Ethernet MAC can be configured via
137+
the :class:`network.LAN` constructor::
129138

130139
import network
131140

@@ -134,20 +143,33 @@ and mode ::
134143
lan.ipconfig('addr4') # get the interface's IPv4 addresses
135144

136145

137-
The keyword arguments for the constructor defining the PHY type and interface are:
146+
Required keyword arguments for the constructor:
147+
148+
- ``mdc`` and ``mdio`` - :class:`machine.Pin` objects (or integers) specifying
149+
the MDC and MDIO pins.
150+
- ``phy_type`` - Select the PHY device type. Supported devices are
151+
``PHY_LAN8710``, ``PHY_LAN8720``, ``PHY_IP101``, ``PHY_RTL8201``,
152+
``PHY_DP83848``, ``PHY_KSZ8041`` and ``PHY_KSZ8081``. These values are all
153+
constants defined in the ``network`` module.
154+
- ``phy_addr`` - The address number of the PHY device. Must be an integer in the
155+
range 0x00 to 0x1f, inclusive. Common values are ``0`` and ``1``.
156+
157+
All of the above keyword arguments must be present to configure the interface.
158+
159+
Optional keyword arguments:
138160

139-
- mdc=pin-object # set the mdc and mdio pins.
140-
- mdio=pin-object
141-
- reset=pin-object # set the reset pin of the PHY device.
142-
- power=pin-object # set the pin which switches the power of the PHY device.
143-
- phy_type=<type> # Select the PHY device type. Supported devices are PHY_LAN8710,
144-
PHY_LAN8720, PH_IP101, PHY_RTL8201, PHY_DP83848 and PHY_KSZ8041
145-
- phy_addr=number # The address number of the PHY device.
146-
- ref_clk_mode=mode # Defines, whether the ref_clk at the ESP32 is an input
147-
or output. Suitable values are Pin.IN and Pin.OUT.
148-
- ref_clk=pin-object # defines the Pin used for ref_clk.
161+
- ``reset`` - :class:`machine.Pin` object (or integer) specifying the PHY reset pin.
162+
- ``power`` - :class:`machine.Pin` object (or integer) specifying a pin which
163+
switches the power of the PHY device.
164+
- ``ref_clk`` - :class:`machine.Pin` object (or integer) specifying the pin used
165+
for the EMAC ``ref_clk`` signal. If not specified, the board default is used
166+
(typically GPIO 0, but may be different if a particular board has Ethernet.)
167+
- ``ref_clk_mode`` - Defines whether the EMAC ``ref_clk`` pin of the ESP32
168+
should be an input or an output. Suitable values are ``machine.Pin.IN`` and
169+
``machine.Pin.OUT``. If not specified, the board default is used
170+
(typically input, but may be different if a particular board has Ethernet.)
149171

150-
These are working configurations for LAN interfaces of popular boards::
172+
These are working configurations for LAN interfaces of some popular ESP32 boards::
151173

152174
# Olimex ESP32-GATEWAY: power controlled by Pin(5)
153175
# Olimex ESP32 PoE and ESP32-PoE ISO: power controlled by Pin(12)
@@ -172,6 +194,66 @@ These are working configurations for LAN interfaces of popular boards::
172194
lan = network.LAN(id=0, mdc=Pin(23), mdio=Pin(18), power=Pin(5),
173195
phy_type=network.PHY_IP101, phy_addr=1)
174196

197+
198+
.. _esp32_spi_ethernet:
199+
200+
SPI Ethernet Interface
201+
""""""""""""""""""""""
202+
203+
All ESP32 SoCs support external SPI Ethernet interface chips. These are Ethernet
204+
interfaces that connect via a SPI bus, rather than an Ethernet RMII interface.
205+
206+
.. note:: The only exception is the ESP32 ``d2wd`` variant, where this feature is disabled
207+
to save code size.
208+
209+
SPI Ethernet uses the same :class:`network.LAN` constructor, with a different
210+
set of keyword arguments::
211+
212+
import machine, network
213+
214+
spi = machine.SPI(1, sck=SCK_PIN, mosi=MOSI_PIN, miso=MISO_PIN)
215+
lan = network.LAN(spi=spi, cs=CS_PIN, ...) # Set the pin and mode configuration
216+
lan.active(True) # activate the interface
217+
lan.ipconfig('addr4') # get the interface's IPv4 addresses
218+
219+
Required keyword arguments for the constructor:
220+
221+
- ``spi`` - Should be a :class:`machine.SPI` object configured for this
222+
connection. Note that any clock speed configured on the SPI object is ignored,
223+
the SPI Ethernet clock speed is configured at compile time.
224+
- ``cs`` - :class:`machine.Pin` object (or integer) specifying the CS pin
225+
connected to the interface.
226+
- ``int`` - :class:`machine.Pin` object (or integer) specifying the INT pin
227+
connected to the interface.
228+
- ``phy_type`` - Select the SPI Ethernet interface type. Supported devices are
229+
``PHY_KSZ8851SNL``, ``PHY_DM9051``, ``PHY_W5500``. These values are all
230+
constants defined in the ``network`` module.
231+
- ``phy_addr`` - The address number of the PHY device. Must be an integer in the
232+
range 0x00 to 0x1f, inclusive. This is usually ``0`` for SPI Ethernet devices.
233+
234+
All of the above keyword arguments must be present to configure the interface.
235+
236+
Optional keyword arguments for the constructor:
237+
238+
- ``reset`` - :class:`machine.Pin` object (or integer) specifying the SPI Ethernet
239+
interface reset pin.
240+
- ``power`` - :class:`machine.Pin` object (or integer) specifying a pin which
241+
switches the power of the SPI Ethernet interface.
242+
243+
Here is a sample configuration for a WIZNet W5500 chip connected to pins on
244+
an ESP32-S3 development board::
245+
246+
import machine, network
247+
from machine import Pin, SPI
248+
249+
spi = SPI(1, sck=Pin(12), mosi=Pin(13), miso=Pin(14))
250+
lan = network.LAN(spi=spi, phy_type=network.PHY_W5500, phy_addr=0,
251+
cs=Pin(10), int=Pin(11))
252+
253+
.. note:: WIZnet W5500 Ethernet is also supported on some other MicroPython
254+
ports, but using a :ref:`different software interface
255+
<network.WIZNET5K>`.
256+
175257
Delay and timing
176258
----------------
177259

docs/library/network.LAN.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class LAN -- control an Ethernet module
66

77
This class allows you to control the Ethernet interface. The PHY hardware type is board-specific.
88

9-
Example usage::
9+
Example usage, for a board with built-in LAN support::
1010

1111
import network
1212
nic = network.LAN(0)
@@ -32,7 +32,7 @@ Constructors
3232
- *phy_addr* specifies the address of the PHY interface. As with *phy_type*, the hardwired value has
3333
to be used for most boards and that value is the default.
3434
- *ref_clk_mode* specifies, whether the data clock is provided by the Ethernet controller or
35-
the PYH interface.
35+
the PHY interface.
3636
The default value is the one that matches the board. If set to ``LAN.OUT`` or ``Pin.OUT``
3737
or ``True``, the clock is driven by the Ethernet controller, if set to ``LAN.IN``
3838
or ``Pin.IN`` or ``False``, the clock is driven by the PHY interface.
@@ -41,6 +41,9 @@ Constructors
4141

4242
nic = LAN(0, phy_type=LAN.PHY_LAN8720, phy_addr=1, ref_clk_mode=Pin.IN)
4343

44+
.. note:: On esp32 port the constructor requires different arguments. See
45+
:ref:`esp32 port reference <esp32_network_lan>`.
46+
4447
Methods
4548
-------
4649

docs/library/network.WIZNET5K.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ the W5200 and W5500 chipsets. The particular chipset that is supported
99
by the firmware is selected at compile-time via the MICROPY_PY_NETWORK_WIZNET5K
1010
option.
1111

12+
.. note:: The esp32 port also supports WIZnet W5500 chipsets, but this port
13+
uses the :ref:`network.LAN interface <esp32_spi_ethernet>`.
14+
1215
Example usage::
1316

1417
import network

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy