nopnop2002 / Arduino-STM32-Ethernet-LAN8720

Ethernet on STM32 using external PHY
MIT License
39 stars 11 forks source link
arduino ethernet lan8720 stm32 tcp udp

STM32Ethernet_LAN8720

STM provides an Ethernet library for Arduino_Core_STM32, but it supports only LAN8742A.
However, it is difficult to get LAN8742 PHY.
We can get the LAN8720 PHY cheaply instead of the LAN8742 PHY.
With a little change, You can use LAN8720 PHY with STM32F407.

Note
STM is currently rebuilding external PHY Ethernet support for Arduino_Core_STM32.
In the future, Ethernet support using external PHYs will change significantly and support may change.
This is an interim action until officially supported.
When STM become officially supports external PHY Ethernet, I will delete this repository.

Hardware requirements

Software requirements

Library modify

You have to modify your local file.
The file location is C:\Users\user\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.3.0\system\STM32F4xx.
The file location may vary depending on core library version.
Please look for stm32f4xx_hal_conf_default.h.

stm32f4xx_hal_conf_default.h

Wireing

LAN8720 PHY --- STM32F407
TX1 --- PB_13
TX_EN --- PB_11
TX0 --- PB_12
RX0 --- PC_4
RX1 --- PC_5
nINT/RETCLK --- PA_1
CRS --- PA_7
MDIO --- PA_2
MDC --- PC_1
GND --- GND
VCC --- +3.3V

How to flash

STM32 NUCLEO provides a on-board STLINK-V2.1 USB interface.
Actually the board has two STM32 chips. One is the target of the demo board, and the other is the STLINK.
This STLINK-V2.1 can be used as programmer and debugger for external targets.
Remove the two jumpers from CN2, and place them at the two outermost empty jumper pins marked CN11 and CN12.
SWD port pinmap for using the Nucleo as a programming device can be found here.

Connect the NUCLEO SWD port to the STM32F407.

NUCLEO SWD --- STM32F407
SWDIO --- PA_13
SWCLK --- PA_14
nRST --- RESET(*1)
GND --- GND
+3.3V --- +3.3V

(*1)If a non-standard BootLoader has already been written to STM32, connection of nRTS pin and RESET pin is required.

Choose Tool->Upload method "STM32CubeProgrammer(SWD)"

Please note the board part number.
Some boards do not support Ethernet.

LAN8720-Arduino

Serial monitor

You need to use a USB-TTL converter to display the serial output.

USB-TTL --- STM32F407
TX --- PA_9
GND --- GND

Note for Virtual COM port
STM32F407 can use a Virtual COM port.
If you enable Virtual COM port, you can use the USB port as a serial port.
But Ethernet and Virtual COM port cannot be used at the same time.
Something is probably in conflict.
Don't use USB Support.

Other examples

There is other examples provided by STM.
To use these you need to add hal_conf_extra.h.
https://github.com/stm32duino/STM32Ethernet/tree/main/examples