Skip to content

Commit ac165f6

Browse files
spectrum70aescolar
authored andcommitted
drivers: eth: eth_stm32: use phy api support for h5/h7
Use PHY apis to access the PHY, to avoid any kind of collisions with other tasks using the PHY apis. Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
1 parent 5341f4a commit ac165f6

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

drivers/ethernet/Kconfig.stm32_hal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ menuconfig ETH_STM32_HAL
1212
select NOCACHE_MEMORY if SOC_SERIES_STM32H7X && CPU_CORTEX_M7
1313
select HWINFO
1414
select ETH_DSA_SUPPORT
15+
select MDIO if SOC_SERIES_STM32H5X || SOC_SERIES_STM32H7X
1516
imply CRC
1617
help
1718
Enable STM32 HAL based Ethernet driver. It is available for

drivers/ethernet/eth_stm32_hal.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
2323
#include <zephyr/net/net_pkt.h>
2424
#include <zephyr/net/net_if.h>
2525
#include <zephyr/net/ethernet.h>
26+
#include <zephyr/net/phy.h>
2627
#include <ethernet/eth_stats.h>
2728
#include <soc.h>
2829
#include <zephyr/sys/printk.h>
@@ -57,6 +58,11 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
5758

5859
#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(CONFIG_SOC_SERIES_STM32H5X)
5960

61+
#define DEVICE_PHY_BY_NAME(n) \
62+
DEVICE_DT_GET(DT_CHILD(DT_INST_CHILD(n, mdio), ethernet_phy_0))
63+
64+
static const struct device *eth_stm32_phy_dev = DEVICE_PHY_BY_NAME(0);
65+
6066
#define PHY_BSR ((uint16_t)0x0001U) /*!< Transceiver Basic Status Register */
6167
#define PHY_LINKED_STATUS ((uint16_t)0x0004U) /*!< Valid link established */
6268

@@ -211,8 +217,9 @@ static HAL_StatusTypeDef read_eth_phy_register(ETH_HandleTypeDef *heth,
211217
uint32_t PHYReg,
212218
uint32_t *RegVal)
213219
{
214-
#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(CONFIG_SOC_SERIES_STM32H5X) || \
215-
defined(CONFIG_ETH_STM32_HAL_API_V2)
220+
#if defined(CONFIG_MDIO)
221+
return phy_read(eth_stm32_phy_dev, PHYReg, RegVal);
222+
#elif defined(CONFIG_ETH_STM32_HAL_API_V2)
216223
return HAL_ETH_ReadPHYRegister(heth, PHYAddr, PHYReg, RegVal);
217224
#else
218225
ARG_UNUSED(PHYAddr);
@@ -1225,7 +1232,6 @@ static int eth_initialize(const struct device *dev)
12251232
setup_mac_filter(heth);
12261233

12271234

1228-
12291235
LOG_DBG("MAC %02x:%02x:%02x:%02x:%02x:%02x",
12301236
dev_data->mac_addr[0], dev_data->mac_addr[1],
12311237
dev_data->mac_addr[2], dev_data->mac_addr[3],

0 commit comments

Comments
 (0)