Showing results for 
Search instead for 
Did you mean: 

Howto create a custom Ethernet PHY driver, that integrates into CubeMX?


My board has ethernet PHY Micrel KSZ8721.

I use STM32F407, RMII, LWIP, noRTOS.

CubeMX 6.7, STM32Lib 1.27.1

Although this is no exotic PHY, it is not listed in the supported BSP PHY as LAN8742 and DP83848.

How can I write a mock driver so that custom calls to support the PHY are integrated into the auto-generated LWIP.c functions.

I see some potential problems in the current CubeMX setup:

1) PHY must be setup in Ethernet AND LwIP tab.

As the single responsibility theory says: one should setup only in 1(one) place.

2) If USER_PHY is selected , then USER_PHX calls should be generated, and not omitted as now.

3) USER_PHY creates warning, but it should be an accepted solution ...

Thanks, Adib.


I'll second this; I'm running the CubeIDE 1.13.0 & FW_H7_1.11.1 on a custom board. ST only includes a driver for the LAN8742. It is very annoying that the only other option is Undefined and a custom BSP module can't be provided for Cube to be aware of.


Not only does this produce a warning every time code is generated, but it also then just removes the HAL_ETH_MspInit and MspDeInit function from being generated for no reason. The GPIO configuration should have nothing to do with which PHY driver is selected.


Obviously the current setup can be worked around (and is still preferred over the legacy version IMO), but it's just clunky. For anyone else, I generated code first with the LAN8742 driver, re-generated with it turned off, and ran a file difference between the two to ensure I filled in all the missing functionality.


Muhammed Güler
Senior III

If you create your project for LAN8742 and edit the ethernetif.c file according to the PHY you want to use, you can use the PHY you want. Only LAN8742 can be selected in the STM32H7 series.
Years ago I used DP83848 with STM32H723. I created the project with LAN8742 and rewrote the ethernetif.c file for DP83848. I wish you success in examining the datasheets in depth and making the necessary changes in the code.