From cd00b2c22e6cec10f8141b63e47d3bd46308776a Mon Sep 17 00:00:00 2001 From: Benjamin Klaric Date: Thu, 13 Nov 2025 09:58:34 +0100 Subject: [PATCH] boards: st: stm32h7s78_dk: add Ethernet support Add Ethernet configuration for mac and mdio nodes. Define the SRAM region for Ethernet descriptor and buffer using memory-regions = <...> in the mac node for this board and for nucleo_h7s3l8, since they both use the same mpu_regions.c and sections.ld files. Add memory-regions property to st,stm32h7-ethernet.yaml file. Update mpu_regions.c and sections.ld to use the region defined in board's .dtsi file. Add an assert to mpu_regions.c to check if the memory-region node refers to the zephyr,sram region. Disable mac node in .overlay files for tests/drivers/memc/ram since ethernet drivers that get enabled by it consume sram1 node and thus fail the test. Update the yaml files to include Ethernet tag and update documentation to explain Ethernet usage. Signed-off-by: Benjamin Klaric --- boards/st/nucleo_h7s3l8/nucleo_h7s3l8.dts | 1 + boards/st/stm32h7s78_dk/doc/index.rst | 7 +++++ .../stm32h7s78_dk/stm32h7s78_dk-common.dtsi | 31 +++++++++++++++++++ boards/st/stm32h7s78_dk/stm32h7s78_dk.yaml | 1 + ...m32h7s78_dk_stm32h7s7xx_ext_flash_app.yaml | 1 + dts/arm/st/h7rs/stm32h7rs.dtsi | 3 ++ .../ethernet/st,stm32h7-ethernet.yaml | 9 +++++- soc/st/stm32/stm32h7rsx/mpu_regions.c | 12 +++++-- soc/st/stm32/stm32h7rsx/sections.ld | 6 ++-- .../memc/ram/boards/stm32h7s78_dk.overlay | 8 +++++ ...h7s78_dk_stm32h7s7xx_ext_flash_app.overlay | 18 +++++++++++ 11 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 tests/drivers/memc/ram/boards/stm32h7s78_dk_stm32h7s7xx_ext_flash_app.overlay diff --git a/boards/st/nucleo_h7s3l8/nucleo_h7s3l8.dts b/boards/st/nucleo_h7s3l8/nucleo_h7s3l8.dts index 7dc3d8b8e9968..aa3564b95c0fc 100644 --- a/boards/st/nucleo_h7s3l8/nucleo_h7s3l8.dts +++ b/boards/st/nucleo_h7s3l8/nucleo_h7s3l8.dts @@ -181,6 +181,7 @@ pinctrl-names = "default"; phy-connection-type = "rmii"; phy-handle = <ð_phy>; + memory-regions = <&sram1>; status = "okay"; }; diff --git a/boards/st/stm32h7s78_dk/doc/index.rst b/boards/st/stm32h7s78_dk/doc/index.rst index 5d52555097723..300e38acb35db 100644 --- a/boards/st/stm32h7s78_dk/doc/index.rst +++ b/boards/st/stm32h7s78_dk/doc/index.rst @@ -181,6 +181,7 @@ Default Zephyr Peripheral Mapping: - XSPI1 NCS/DQS0/DQS1/CLK/IO: PO0/PO2/PO3/PO4/PP0..15 - I2C1 SCL/SDA: PB6/PB9 - FDCAN1 RX/TX : PB8/PB9 +- ETH: PA2/PA7/PB0/PB1/PC1/PC4/PC5/PD7/PG11 System Clock ------------ @@ -208,6 +209,12 @@ STM32H7S78-DK Discovery board has 2 FDCAN bus interfaces. FDCAN1 is configured but not enabled by default. To enable it, make sure that ``i2c1`` is disabled, since they share the PB9 pin. +Ethernet +-------- + +In order to use Ethernet on STM32H7S78-DK, you need to set the ``JP6`` jumper +to PC1 position on the back side of the board. + Programming and Debugging ************************* diff --git a/boards/st/stm32h7s78_dk/stm32h7s78_dk-common.dtsi b/boards/st/stm32h7s78_dk/stm32h7s78_dk-common.dtsi index 40b2d0780963f..48df23bdaa16a 100644 --- a/boards/st/stm32h7s78_dk/stm32h7s78_dk-common.dtsi +++ b/boards/st/stm32h7s78_dk/stm32h7s78_dk-common.dtsi @@ -11,6 +11,11 @@ #include "zephyr/dt-bindings/display/panel.h" #include +/* + * WARNING: + * JP6 must be in PC1 position when using Ethernet. + */ + / { chosen { zephyr,console = &uart4; @@ -228,6 +233,32 @@ status = "disabled"; }; +&mac { + pinctrl-0 = <ð_rmii_ref_clk_pd7 + ð_rmii_crs_dv_pa7 + ð_rmii_rxd0_pc4 + ð_rmii_rxd1_pc5 + ð_rmii_tx_en_pg11 + ð_rmii_txd0_pb0 + ð_rmii_txd1_pb1>; + pinctrl-names = "default"; + phy-connection-type = "rmii"; + phy-handle = <ð_phy>; + memory-regions = <&sram1>; + status = "okay"; +}; + +&mdio { + pinctrl-0 = <ð_mdio_pa2 ð_mdc_pc1>; + pinctrl-names = "default"; + status = "okay"; + + eth_phy: ethernet-phy@0 { + compatible = "ethernet-phy"; + reg = <0x00>; + }; +}; + &xspi1 { pinctrl-0 = <&xspim_p1_ncs1_po0 &xspim_p1_dqs0_po2 &xspim_p1_dqs1_po3 &xspim_p1_clk_po4 diff --git a/boards/st/stm32h7s78_dk/stm32h7s78_dk.yaml b/boards/st/stm32h7s78_dk/stm32h7s78_dk.yaml index 1d2120606da07..2c6f571adfe49 100644 --- a/boards/st/stm32h7s78_dk/stm32h7s78_dk.yaml +++ b/boards/st/stm32h7s78_dk/stm32h7s78_dk.yaml @@ -16,4 +16,5 @@ supported: - octospi - usbd - memc + - netif:eth vendor: st diff --git a/boards/st/stm32h7s78_dk/stm32h7s78_dk_stm32h7s7xx_ext_flash_app.yaml b/boards/st/stm32h7s78_dk/stm32h7s78_dk_stm32h7s7xx_ext_flash_app.yaml index 92ef6680b284a..12d379f83d3a8 100644 --- a/boards/st/stm32h7s78_dk/stm32h7s78_dk_stm32h7s7xx_ext_flash_app.yaml +++ b/boards/st/stm32h7s78_dk/stm32h7s78_dk_stm32h7s7xx_ext_flash_app.yaml @@ -17,4 +17,5 @@ supported: - octospi - usbd - memc + - netif:eth vendor: st diff --git a/dts/arm/st/h7rs/stm32h7rs.dtsi b/dts/arm/st/h7rs/stm32h7rs.dtsi index 22526507d7c08..9ab2ecc92f14a 100644 --- a/dts/arm/st/h7rs/stm32h7rs.dtsi +++ b/dts/arm/st/h7rs/stm32h7rs.dtsi @@ -54,6 +54,7 @@ reg = <0x24000000 DT_SIZE_K(456)>; compatible = "zephyr,memory-region", "mmio-sram"; zephyr,memory-region = "SRAM0"; + #memory-region-cells = <0>; }; /* System data RAM accessible over AHB bus: SRAM1 in D2 domain */ @@ -61,6 +62,7 @@ reg = <0x30000000 DT_SIZE_K(16)>; compatible = "zephyr,memory-region", "mmio-sram"; zephyr,memory-region = "SRAM1"; + #memory-region-cells = <0>; zephyr,memory-attr = ; }; @@ -69,6 +71,7 @@ compatible = "zephyr,memory-region", "mmio-sram"; reg = <0x30004000 DT_SIZE_K(16)>; zephyr,memory-region = "SRAM2"; + #memory-region-cells = <0>; /* Disable SRAM2 by default to avoid unintended access. * To enable it, explicitly define zephyr,memory-attr * to configure MPU attributes. diff --git a/dts/bindings/ethernet/st,stm32h7-ethernet.yaml b/dts/bindings/ethernet/st,stm32h7-ethernet.yaml index 7878817c4fd64..6590ee0fd8c2a 100644 --- a/dts/bindings/ethernet/st,stm32h7-ethernet.yaml +++ b/dts/bindings/ethernet/st,stm32h7-ethernet.yaml @@ -11,4 +11,11 @@ description: | compatible: "st,stm32h7-ethernet" -include: st,stm32-ethernet-common.yaml +include: + - "st,stm32-ethernet-common.yaml" + - "memory-region.yaml" + +properties: + memory-regions: + description: | + Reference to SRAM node used for Ethernet DMA buffer and descriptor. diff --git a/soc/st/stm32/stm32h7rsx/mpu_regions.c b/soc/st/stm32/stm32h7rsx/mpu_regions.c index 35dfce848cded..f28fdf8b5b410 100644 --- a/soc/st/stm32/stm32h7rsx/mpu_regions.c +++ b/soc/st/stm32/stm32h7rsx/mpu_regions.c @@ -30,8 +30,10 @@ static const struct arm_mpu_region mpu_regions[] = { /* Region 4 - Ready only flash with unique device id */ MPU_REGION_ENTRY("ID", 0x08FFF800, REGION_FLASH_ATTR(REGION_2K)), -#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(mac)) -#define sram_eth_node DT_NODELABEL(sram2) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(mac)) && \ + DT_NODE_HAS_PROP(DT_NODELABEL(mac), memory_regions) +#define sram_eth_node DT_PHANDLE(DT_NODELABEL(mac), memory_regions) + #if DT_NODE_HAS_STATUS_OKAY(sram_eth_node) /* Region 5 - Ethernet DMA buffer RAM */ MPU_REGION_ENTRY("SRAM_ETH_BUF", DT_REG_ADDR(sram_eth_node), @@ -42,6 +44,12 @@ static const struct arm_mpu_region mpu_regions[] = { #endif }; +#ifdef sram_eth_node + BUILD_ASSERT(!DT_SAME_NODE(sram_eth_node, DT_CHOSEN(zephyr_sram)), + "Remove property memory-regions from 'mac' node " + "to locate ethernet buffers in system RAM."); +#endif + const struct arm_mpu_config mpu_config = { .num_regions = ARRAY_SIZE(mpu_regions), .mpu_regions = mpu_regions, diff --git a/soc/st/stm32/stm32h7rsx/sections.ld b/soc/st/stm32/stm32h7rsx/sections.ld index 7f1209682dcca..33713e7ff1e0f 100644 --- a/soc/st/stm32/stm32h7rsx/sections.ld +++ b/soc/st/stm32/stm32h7rsx/sections.ld @@ -4,8 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(mac)) -#define sram_eth_node DT_NODELABEL(sram2) +#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(mac)) && \ + DT_NODE_HAS_PROP(DT_NODELABEL(mac), memory_regions) +#define sram_eth_node DT_PHANDLE(DT_NODELABEL(mac), memory_regions) + #if DT_NODE_HAS_STATUS_OKAY(sram_eth_node) SECTION_DATA_PROLOGUE(eth_stm32,(NOLOAD),) { diff --git a/tests/drivers/memc/ram/boards/stm32h7s78_dk.overlay b/tests/drivers/memc/ram/boards/stm32h7s78_dk.overlay index 9a7568844a39e..6b371ffbcd27b 100644 --- a/tests/drivers/memc/ram/boards/stm32h7s78_dk.overlay +++ b/tests/drivers/memc/ram/boards/stm32h7s78_dk.overlay @@ -8,3 +8,11 @@ zephyr,memory-attr = ; status = "okay"; }; + +&mac { + /* + * mac is disabled for this test since the ethernet driver that gets + * enabled by this node consumes the sram1 node thus failing this test + */ + status = "disabled"; +}; diff --git a/tests/drivers/memc/ram/boards/stm32h7s78_dk_stm32h7s7xx_ext_flash_app.overlay b/tests/drivers/memc/ram/boards/stm32h7s78_dk_stm32h7s7xx_ext_flash_app.overlay new file mode 100644 index 0000000000000..b8020f041f0c5 --- /dev/null +++ b/tests/drivers/memc/ram/boards/stm32h7s78_dk_stm32h7s7xx_ext_flash_app.overlay @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Benjamin Klaric + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&sram2 { + zephyr,memory-attr = ; + status = "okay"; +}; + +&mac { + /* + * mac is disabled for this test since the ethernet driver that gets + * enabled by this node consumes the sram1 node thus failing this test + */ + status = "disabled"; +};