From bac5f091e1f1eb9ee770f3ca07f2a5715c8ba293 Mon Sep 17 00:00:00 2001 From: IBEN EL HADJ MESSAOUD Marwa Date: Wed, 12 Feb 2025 15:56:29 +0100 Subject: [PATCH 1/2] boards: st: stm32n6570_dk: Add ethernet node Add the Ethernet MAC and MDIO nodes in the device tree. Add Kconfig for Ethernet Support. Signed-off-by: IBEN EL HADJ MESSAOUD Marwa --- boards/st/stm32n6570_dk/Kconfig.defconfig | 15 +++++++++ .../stm32n6570_dk/stm32n6570_dk_common.dtsi | 32 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 boards/st/stm32n6570_dk/Kconfig.defconfig diff --git a/boards/st/stm32n6570_dk/Kconfig.defconfig b/boards/st/stm32n6570_dk/Kconfig.defconfig new file mode 100644 index 000000000000..0196c3c0b854 --- /dev/null +++ b/boards/st/stm32n6570_dk/Kconfig.defconfig @@ -0,0 +1,15 @@ +# STM32N6570 DISCOVERY board configuration + +# Copyright (c) 2025 STMicroelectronics +# SPDX-License-Identifier: Apache-2.0 + +if BOARD_STM32N6570_DK + +if NETWORKING + +config NET_L2_ETHERNET + default y + +endif # NETWORKING + +endif # BOARD_STM32N6570_DK diff --git a/boards/st/stm32n6570_dk/stm32n6570_dk_common.dtsi b/boards/st/stm32n6570_dk/stm32n6570_dk_common.dtsi index 5d7e0a5ec4c9..a5f102bc6e3b 100644 --- a/boards/st/stm32n6570_dk/stm32n6570_dk_common.dtsi +++ b/boards/st/stm32n6570_dk/stm32n6570_dk_common.dtsi @@ -247,3 +247,35 @@ }; }; }; + +&mac { + status = "okay"; + pinctrl-0 = <ð1_rgmii_gtx_clk_pf0 + ð1_rgmii_clk125_pf2 + ð1_rgmii_rx_clk_pf7 + ð1_rgmii_rxd2_pf8 + ð1_rgmii_rxd3_pf9 + ð1_rgmii_rx_ctl_pf10 + ð1_rgmii_tx_ctl_pf11 + ð1_rgmii_txd1_pf13 + ð1_rgmii_txd0_pf12 + ð1_rgmii_rxd0_pf14 + ð1_rgmii_rxd1_pf15 + ð1_rgmii_txd2_pg3 + ð1_rgmii_txd3_pg4 + ð1_phy_intn_pd3>; + pinctrl-names = "default"; + phy-connection-type = "rgmii"; + phy-handle = <ð_phy>; +}; + +&mdio { + status = "okay"; + pinctrl-0 = <ð1_mdio_pd12 ð1_mdc_pd1>; + pinctrl-names = "default"; + + eth_phy: ethernet-phy@0 { + compatible = "ethernet-phy"; + reg = <0x0>; + }; +}; From 73d619c0f9ea7e364714cd79a72e01d635cddcf4 Mon Sep 17 00:00:00 2001 From: IBEN EL HADJ MESSAOUD Marwa Date: Wed, 26 Mar 2025 15:14:51 +0100 Subject: [PATCH 2/2] drivers: ethernet: Integrate GRMII and RMII interfaces - Added macros `STM32_ETH_PHY_MODE` to determine the PHY mode (RGMII, GMII, RMII, and MII) from the `phy_connection_type` property in the device tree. - Removed previous definitions for ETH_MEDIA_INTERFACE_MII and ETH_MEDIA_INTERFACE_RMII. - Updated STM32_ETH_PHY_MODE macro to use ETH_MII_MODE and ETH_RMII_MODE. Signed-off-by: IBEN EL HADJ MESSAOUD Marwa --- drivers/ethernet/eth_stm32_hal.c | 40 +++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/drivers/ethernet/eth_stm32_hal.c b/drivers/ethernet/eth_stm32_hal.c index e0c16c93213f..cf7f9f4e3ddd 100644 --- a/drivers/ethernet/eth_stm32_hal.c +++ b/drivers/ethernet/eth_stm32_hal.c @@ -66,9 +66,6 @@ static const struct device *eth_stm32_phy_dev = DEVICE_DT_GET(DT_INST_PHANDLE(0, #define ETH_RXBUFNB ETH_RX_DESC_CNT #define ETH_TXBUFNB ETH_TX_DESC_CNT -#define ETH_MEDIA_INTERFACE_MII HAL_ETH_MII_MODE -#define ETH_MEDIA_INTERFACE_RMII HAL_ETH_RMII_MODE - /* Only one tx_buffer is sufficient to pass only 1 dma_buffer */ #define ETH_TXBUF_DEF_NB 1U #else @@ -78,11 +75,32 @@ static const struct device *eth_stm32_phy_dev = DEVICE_DT_GET(DT_INST_PHANDLE(0, #endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_ethernet) */ +#if defined(CONFIG_ETH_STM32_HAL_API_V2) +#define ETH_MII_MODE HAL_ETH_MII_MODE +#define ETH_RMII_MODE HAL_ETH_RMII_MODE +#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_ethernet) +#define ETH_GMII_MODE HAL_ETH_GMII_MODE +#define ETH_RGMII_MODE HAL_ETH_RGMII_MODE +#endif + +#else +#define ETH_MII_MODE ETH_MEDIA_INTERFACE_MII +#define ETH_RMII_MODE ETH_MEDIA_INTERFACE_RMII +#endif + #define MAC_NODE DT_NODELABEL(mac) +#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_ethernet) +#define STM32_ETH_PHY_MODE(node_id) \ + ((DT_ENUM_HAS_VALUE(node_id, phy_connection_type, rgmii) ? ETH_RGMII_MODE : \ + (DT_ENUM_HAS_VALUE(node_id, phy_connection_type, gmii) ? ETH_GMII_MODE : \ + (DT_ENUM_HAS_VALUE(node_id, phy_connection_type, mii) ? ETH_MII_MODE : \ + ETH_RMII_MODE)))) +#else #define STM32_ETH_PHY_MODE(node_id) \ (DT_ENUM_HAS_VALUE(node_id, phy_connection_type, mii) ? \ - ETH_MEDIA_INTERFACE_MII : ETH_MEDIA_INTERFACE_RMII) + ETH_MII_MODE : ETH_RMII_MODE) +#endif #define ETH_DMA_TX_TIMEOUT_MS 20U /* transmit timeout in milliseconds */ @@ -1090,7 +1108,10 @@ static void set_mac_config(const struct device *dev, struct phy_link_state *stat mac_config.DuplexMode = PHY_LINK_IS_FULL_DUPLEX(state->speed) ? ETH_FULLDUPLEX_MODE : ETH_HALFDUPLEX_MODE; - mac_config.Speed = PHY_LINK_IS_SPEED_100M(state->speed) ? ETH_SPEED_100M : ETH_SPEED_10M; + mac_config.Speed = + IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_ethernet), + PHY_LINK_IS_SPEED_1000M(state->speed) ? ETH_SPEED_1000M :) + PHY_LINK_IS_SPEED_100M(state->speed) ? ETH_SPEED_100M : ETH_SPEED_10M; hal_ret = HAL_ETH_SetMACConfig(heth, &mac_config); if (hal_ret != HAL_OK) { @@ -1428,9 +1449,12 @@ static const struct eth_stm32_hal_dev_cfg eth0_config = { .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0), }; -BUILD_ASSERT(DT_ENUM_HAS_VALUE(MAC_NODE, phy_connection_type, mii) || - DT_ENUM_HAS_VALUE(MAC_NODE, phy_connection_type, rmii), - "Unsupported PHY connection type selected"); +BUILD_ASSERT(DT_ENUM_HAS_VALUE(MAC_NODE, phy_connection_type, mii) + || DT_ENUM_HAS_VALUE(MAC_NODE, phy_connection_type, rmii) + IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_ethernet), + (|| DT_ENUM_HAS_VALUE(MAC_NODE, phy_connection_type, rgmii) + || DT_ENUM_HAS_VALUE(MAC_NODE, phy_connection_type, gmii))), + "Unsupported PHY connection type"); static struct eth_stm32_hal_dev_data eth0_data = { .heth = {