@@ -121,11 +121,20 @@ calling ``wlan.config(reconnects=n)``, where n are the number of desired reconne
121
121
attempts (0 means it won't retry, -1 will restore the default behaviour of trying
122
122
to reconnect forever).
123
123
124
+ .. _esp32_network_lan :
125
+
124
126
LAN
125
127
^^^
126
128
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::
129
138
130
139
import network
131
140
@@ -134,20 +143,33 @@ and mode ::
134
143
lan.ipconfig('addr4') # get the interface's IPv4 addresses
135
144
136
145
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:
138
160
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.)
149
171
150
- These are working configurations for LAN interfaces of popular boards::
172
+ These are working configurations for LAN interfaces of some popular ESP32 boards::
151
173
152
174
# Olimex ESP32-GATEWAY: power controlled by Pin(5)
153
175
# 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::
172
194
lan = network.LAN(id=0, mdc=Pin(23), mdio=Pin(18), power=Pin(5),
173
195
phy_type=network.PHY_IP101, phy_addr=1)
174
196
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
+
175
257
Delay and timing
176
258
----------------
177
259
0 commit comments