Many STM32 microcontrollers include an Ethernet MAC, which makes wired networking look easy: enable the peripheral, add a connector, and go. In practice the first Ethernet board from a team often does not link up on the first try. The causes are nearly always the same few: a reference clock that is not where the MAC expects it, a strap pin pulled the wrong way, a reset released too early, or a transformer wired for a different kind of transceiver.
This checklist walks through each part of the design in the order you will meet it, from choosing the transceiver to bringing up the software. The examples use the Microchip LAN8742A, a 10/100 PHY that ST fits to many of its own evaluation boards, but most of the points apply to any RMII transceiver.
What you need
A complete 10/100 Ethernet port on an STM32 needs five things besides the microcontroller:
- An Ethernet PHY with an RMII interface
- A clock source: a 25 MHz crystal or a 50 MHz oscillator
- A small number of resistors and capacitors for bias, termination and decoupling
- Magnetics, either a discrete transformer module or a connector with the transformer built in
- An RJ45 connector
1. Choose the PHY
Pick a PHY that supports RMII, runs from your supply rails and has the features your product needs. The LAN8742A is a common choice for several reasons. It works from a single 3.3 V supply and generates its own 1.2 V core voltage. Its I/O supply can be set anywhere from 1.6 V to 3.6 V. It handles straight and crossover cables automatically. It adds Wake-on-LAN and cable diagnostics. And because ST uses it on its Nucleo-144 and other boards, the example projects and drivers in ST’s software packages support it directly.
Decide on the temperature grade. The LAN8742A-CZ-TR is the commercial-temperature part on tape and reel. An industrial-temperature version is available for harsher environments.
If you need that commercial reel code, Verified Electronics is a Microchip components supplier and LAN8742A-CZ-TR distributor that lists the part and uses third-party testing.
2. Assign the RMII pins
RMII uses these signals between the MAC and the PHY:
| Signal | Direction | Purpose |
|---|---|---|
| REF_CLK | Into the MAC | 50 MHz reference clock |
| TX_EN | MAC to PHY | Transmit enable |
| TXD0, TXD1 | MAC to PHY | Transmit data |
| RXD0, RXD1 | PHY to MAC | Receive data |
| CRS_DV | PHY to MAC | Carrier sense and receive data valid |
| MDC | MAC to PHY | Management clock |
| MDIO | Both ways | Management data |
On an STM32, each of these maps to one or more specific pins. Some have only one possible location, and others, usually the transmit signals, can be placed on a choice of pins. Set up the Ethernet peripheral in RMII mode in STM32CubeMX before drawing the schematic. The tool shows the available pins and flags conflicts with other peripherals you have enabled.
Check: every RMII signal is on a pin that supports that function, and no other peripheral needs the same pin.
Check: the MDIO line has a pull-up resistor, typically 1.5 kilohms, to the I/O supply.
Check: the GPIO speed setting for the RMII pins is high or very high in firmware. Slow pin settings cause intermittent data errors.
3. Decide where the 50 MHz clock comes from
This is the decision that causes the most trouble. The MAC and the PHY must both run from the same 50 MHz reference. There are three common ways to provide it.
Option A: crystal at the PHY, clock out to the MAC. Connect a 25 MHz crystal to the PHY. The LAN8742A multiplies it internally and outputs 50 MHz on a pin that you route to the STM32’s REF_CLK input. This is the lowest-cost arrangement. On the LAN8742A, the pin that provides this clock is shared with the interrupt function, and a strap selects which one it is, so in this mode the interrupt is not available on that pin.
Option B: external 50 MHz oscillator. A single oscillator drives both the PHY’s clock input and the STM32’s REF_CLK pin. This gives the cleanest clock and keeps the PHY’s interrupt pin available. Keep the two branches short and similar in length.
Option C: clock from the microcontroller. The STM32 outputs a clock on its MCO pin to the PHY. Supplying 25 MHz to the PHY’s crystal input, with the PHY returning 50 MHz, is the more robust form of this option. Driving 50 MHz directly from a PLL output can work but needs care, because PLL jitter may exceed what the PHY tolerates.
Check: the clock mode strap on the PHY matches the option you chose.
Check: the crystal’s load capacitors match the crystal specification, and the frequency tolerance meets the Ethernet requirement of 50 parts per million.
Check: the REF_CLK trace is short, has a continuous ground plane beneath it and, if needed, a small series resistor at the source.
4. Set the configuration straps
The PHY samples several pins when reset is released and uses them to set its initial configuration. On the LAN8742A the straps select the PHY address, the operating mode, whether the internal regulator is on and the function of the shared clock and interrupt pin. Internal pull resistors give default values, and external resistors override them.
Check: the PHY address strap gives the address your firmware expects. On ST’s reference boards the address is 0.
Check: the mode straps select auto-negotiation with all capabilities advertised, unless you have a reason to do otherwise.
Check: the regulator strap leaves the internal 1.2 V regulator enabled, unless you supply that rail externally.
Check: nothing else on the strap lines fights the intended level during reset. The strap pins double as RMII and LED signals. An LED connected the wrong way round, or a microcontroller pin with a pull resistor enabled at startup, can change a strap.
LED polarity deserves a note. On this device, the polarity of each LED output is determined by the strap level on that pin, so the LED must be wired to match: to ground or to the supply, as the datasheet shows for each strap setting.
5. Get reset right
The PHY needs a clean reset after its supplies and clock are stable. Straps are latched at the end of reset, so the timing matters.
Check: the PHY reset pin is driven by a microcontroller GPIO, or by a supervisor, and not left to a simple pull-up alone.
Check: firmware holds reset low for longer than the datasheet minimum after power is stable, releases it, and then waits before the first management access.
Check: if the microcontroller supplies the PHY’s clock, that clock is running before reset is released.
A GPIO-controlled reset also gives firmware a way to recover the PHY if it ever stops responding.
6. Power and decoupling
- Fit a 0.1 microfarad ceramic capacitor at each supply pin, as close as possible.
- Fit the capacitors the datasheet specifies on the internal regulator’s output pin. They are needed for stability.
- Feed the analog supply pins through a ferrite bead with local decoupling, to keep digital noise out of the transceiver.
- Fit the bias resistor at the value and 1 percent tolerance the datasheet specifies. It sets internal reference currents, and the wrong value affects transmit levels.
- Connect the exposed pad to the ground plane with multiple vias.
Check: the I/O supply of the PHY matches the voltage of the STM32 pins it connects to.
7. The cable side: termination and magnetics
Between the PHY and the connector sit the termination resistors and the isolation transformer. Their arrangement depends on the type of output driver in the PHY, so follow the reference schematic for your specific device. Do not copy the circuit from a different PHY family.
For the LAN8742A, each line of the transmit and receive pairs has a 49.9 ohm resistor to the analog supply, and the transformer center taps on the PHY side connect to that supply as the datasheet shows.
Check: the magnetics have a 1:1 turns ratio on both transmit and receive, as required for auto-crossover operation.
Check: if you use a connector with integrated magnetics, its internal circuit and pinout suit this arrangement. These connectors come in several variants that look identical from outside.
Check: the cable-side center taps are terminated through 75 ohm resistors and a high-voltage capacitor to chassis ground, the arrangement often called a Bob Smith termination. Many integrated connectors include it.
Check: the connector shield goes to chassis ground, kept separate from signal ground except at a defined point.
8. Layout
- Route each transmit and receive pair as a 100 ohm differential pair, with the two traces matched in length.
- Keep the pairs short, and avoid vias and sharp corners.
- Keep the transmit and receive pairs apart from each other, and well away from the crystal, the reference clock and switching regulators.
- Place termination resistors close to the PHY.
- Remove ground and power planes under the cable side of the magnetics and the connector, to preserve isolation.
- Keep RMII traces short and roughly matched, over an unbroken ground plane.
- Place the crystal next to the PHY with a ground guard and no signals routed beneath it.
9. Protection
For products that must pass electrostatic discharge and surge testing, add low-capacitance protection diodes on the PHY side of the magnetics, close to the transformer. The transformer provides isolation, but fast transients can still couple through it.
10. Software bring-up
With the hardware done, configure the firmware.
- Enable the Ethernet peripheral in RMII mode in STM32CubeMX and confirm the pin assignments match the schematic.
- Set the PHY address to match the strap.
- Select the driver for your PHY. ST’s packages include one for the LAN8742A.
- Add the TCP/IP stack and set a MAC address. Every device needs a unique one.
- Make sure the PHY reset sequence runs before the Ethernet initialization.
- On Cortex-M7 parts with data cache, place the Ethernet buffers and descriptors in the memory region the driver expects and configure the memory protection unit as the examples show. Misplaced buffers are a classic cause of an interface that links but passes no data.
11. First power-up: a debugging order
If the link does not come up, check in this order.
- Supplies. Measure 3.3 V and the 1.2 V regulator output at the PHY.
- Clock. Look for 25 MHz at the crystal and 50 MHz at the STM32’s REF_CLK pin.
- Management bus. Read the PHY identifier registers. If they return the expected values, the address, MDC, MDIO and reset are all working. If they return all ones, the PHY is not responding: check the address strap, the MDIO pull-up and reset.
- Link. Plug in a cable to a known-good switch and read the status register. The link LED should light. No link with good management access points to the cable side: magnetics, termination or connector wiring.
- Data. If the link is up but no packets arrive, check the RMII data pins, the GPIO speed settings, the speed and duplex setting written to the MAC, and the buffer placement.
12. Test before you call it done
A link light is not the end of testing. Before the design is released, run a few checks that expose marginal hardware. Send sustained traffic in both directions for several hours and count errors: a clean design shows none. Test at both 10 and 100 Mbit/s, with short and long cables, and against more than one brand of switch. Repeat the test at the temperature extremes your product is rated for, since clock tolerance and timing margins shift with temperature. Power-cycle the board many times and confirm the link comes up on every attempt, which catches reset and strap problems that only appear occasionally. If the product has to pass emissions testing, do a pre-scan early, because Ethernet magnetics and cable shields are frequent contributors.
Common mistakes
- Clock strap set for input mode when the design expects the PHY to output the clock, or the reverse.
- PHY address in firmware not matching the strap.
- An LED wired against its strap level.
- Reset released before the clock is running.
- A connector with the wrong internal magnetics.
- Missing MDIO pull-up.
- RMII pins left at low GPIO speed.
- Regulator output capacitors omitted.
Summary
A reliable Ethernet port on an STM32 comes from getting a short list of details right: an RMII PHY suited to your supply and feature needs, pins assigned with the configuration tool, a clear decision on the 50 MHz clock source with the strap to match, correct strap levels and LED wiring, a controlled reset, proper decoupling and bias, the right termination and magnetics for the PHY, and careful differential routing. The LAN8742A is a well-supported choice that matches ST’s own reference designs. Work through the checklist before layout, follow the debugging order at first power-up, and confirm every value against the current datasheets for your PHY and microcontroller.