Skip to content

Conversation

@bklaric1
Copy link
Contributor

@bklaric1 bklaric1 commented Nov 13, 2025

Changes

  • Added mac and mdio configuration to stm32h7s78_dk-common.dtsi and enabled them. The RMII Ethernet pin configuration follows this schematic from ST: MB1736.
  • Added fallback option for definition of sram_eth_node in mpu_regions.c and sections.ld. This definition earlier defaulted to sram2, but now has sram1 as fallback option. Defined the SRAM region for Ethernet descriptor and buffer
    using memory-regions = <...> in the mac node (as discussed) and added the updated definition of sram_eth_node to mpu_regions.c and sections.ld. Also added the needed property in dts/bindings/ethernet/st,stm32h7-ethernet.yaml.
    • Added memory-regions = <...> to boards/st/nucleo_h7s3l8/nucleo_h7s3l8.dts, since they use the same mpu_regions.c and sections.ld.
  • Updated stm32h7s78_dk.yaml and stm32h7s78_dk_stm32h7s7xx_ext_flash_app.yaml to include the Ethernet tag.
  • Updated index.rst to include the Ethernet feature and documented the steps needed in order to use Ethernet for this board.
  • Added tests/drivers/memc/ram/boards/stm32h7s78_dk_stm32h7s7xx_ext_flash_app.overlay and updated tests/drivers/memc/ram/boards/stm32h7s78_dk.overlay since Ethernet drivers fully consume sram1 node and thus fail the test without the additions.
  • Added #memory-region-cells = <0>; to all possible memory regions (sram1 and sram2 nodes) in dts/arm/st/h7rs/stm32h7rs.dtsi

Tests

I tested these changes with the following examples:

I could ping the board after flashing both samples and also open the website in the browser. Everything worked as expected.

Notes

I opened #99164 in order to discuss how to implement the fallback for sram2 and whether this approach is correct. Taking a look at the discussion should answer some questions about the implementation.

Closes #99164

@bklaric1
Copy link
Contributor Author

The #99505 should be resolved first before proceeding with the merge (if it even gets to that point), since the changes to mpu_regions.c might become obsolete.

@bklaric1
Copy link
Contributor Author

Regarding the failed checks:

  • compliance check fail (intendation and trailing whitespace) will be fixed with the next commit
  • twister check error wasn't caused by changes that my commit introduced as far as I can say. The error output:
    /opt/toolchains/zephyr-sdk-0.17.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: zephyr/zephyr_pre0.elf section `SRAM1' will not fit in region `SRAM1'
    /opt/toolchains/zephyr-sdk-0.17.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: region `SRAM1' overflowed by 256 bytes
    
    states that the SRAM1 region is overflowed. But the comment in the mpu_regions.c file states the following:
    /* Region 6 - Ethernet DMA descriptor RAM (overlays the first 256B of SRAM_ETH_BUF)*/

So I think this isn't relevant to the PR, but I might be wrong.

Note: next commit will also add - netif:eth to stm32h7s78_dk_stm32h7s7xx_ext_flash_app.yaml, since I forgot to add that.

Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you squash to 2 commits?

@bklaric1 bklaric1 force-pushed the feat-stm32h7s78_dk-ethernet branch from 2fdc201 to dc13beb Compare November 26, 2025 09:02
@bklaric1
Copy link
Contributor Author

Squashed upcoming commit into 2. commit and added the requested changes.

@bklaric1
Copy link
Contributor Author

Regarding the failed Compliance Check: I don't see the trailing whitespace that is being reported, neither locally nor in GitHub Web Editor, so I can't really fix this.

@pdgendt
Copy link
Contributor

pdgendt commented Nov 26, 2025

Regarding the failed Compliance Check: I don't see the trailing whitespace that is being reported, neither locally nor in GitHub Web Editor, so I can't really fix this.

Your first commit introduces a trailing whitespace, which is then fixed by your second commit. This isn't allowed.

@bklaric1 bklaric1 force-pushed the feat-stm32h7s78_dk-ethernet branch from dc13beb to 473226c Compare November 26, 2025 11:27
@bklaric1
Copy link
Contributor Author

@pdgendt I edited the first commit and removed the trailing whitespace there. Hopefully this fixes the CI check error.

@bklaric1 bklaric1 requested a review from etienne-lms December 2, 2025 10:33
@etienne-lms
Copy link
Contributor

Since I have already squashed the commits into one commit, should I still split them up or is the current single commit good enough?

This unique commit as-is makes sense to me.

I am open to looking into adding the memory-region property to mac node for H7x series. As you said, H7x and H7rs are similar enough. This should be done in a seperate PR, right?

Ok for another P-R.

@bklaric1 bklaric1 force-pushed the feat-stm32h7s78_dk-ethernet branch from f24dfb6 to a491c3a Compare December 3, 2025 08:32
@bklaric1
Copy link
Contributor Author

bklaric1 commented Dec 3, 2025

@etienne-lms Amended the last commit to include the requested changes.
Edit: some requested changes might be wrong. Take a look at the review comments.

Question: do I need to add a (second) Copyright line when I edit an existing file or only when I create a new file?

@bklaric1 bklaric1 force-pushed the feat-stm32h7s78_dk-ethernet branch 5 times, most recently from 39967ac to 9884696 Compare December 3, 2025 14:05
@bklaric1 bklaric1 requested a review from etienne-lms December 3, 2025 14:27
@bklaric1 bklaric1 force-pushed the feat-stm32h7s78_dk-ethernet branch from 9884696 to a54f308 Compare December 3, 2025 14:31
@bklaric1
Copy link
Contributor Author

bklaric1 commented Dec 4, 2025

@etienne-lms I kindly ask again that you review my comments to your changes to see why the twister-builds fail (and how to fix the fail → revert to the #error ... block check I already had). That way this PR can move forward. Thanks in advance.

@bklaric1 bklaric1 force-pushed the feat-stm32h7s78_dk-ethernet branch from a54f308 to 99ec211 Compare December 8, 2025 15:37
include: st,stm32-ethernet-common.yaml

properties:
memory-region:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe have it consistent between the stm ethernet macs, and do it like in dts/bindings/ethernet/st,stm32mp13-ethernet.yaml and use memory-regions (with an s)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed the s. Will update.
But if we are trying to be consistent, shouldn't the property also include the required: true as in st,stm32mp13-ethernet.yaml?

properties:
memory-regions:
required: true
description: |
Memory region in which the Ethernet DMA lists and data buffers will be
placed. The memory region has to be non-cacheable and accessible by the
Ethernet peripheral.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, the soc/st/stm32/stm32h7x doesn't use it and we still want to be able to have it on the main ram by not setting it.
Implied by

BUILD_ASSERT(!DT_SAME_NODE(sram_eth_node, DT_CHOSEN(zephyr_sram)),
	     "Remove property memory-region from 'mac' node "
	     "to locate ethernet buffers in system RAM.")

But that's something the ST people (@etienne-lms )should decide

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the s across the commit.

@bklaric1 bklaric1 force-pushed the feat-stm32h7s78_dk-ethernet branch from 99ec211 to 1f3a8e3 Compare December 9, 2025 10:14
compatible: "st,stm32h7-ethernet"

include: st,stm32-ethernet-common.yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add

include:
  - "st,stm32-ethernet-common.yaml"
  - "memory-region.yaml"

and remove type: phandle

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do that, then I get the following error:

devicetree error: <Node /memory@30000000 in /zephyr/dts/arm/st/h7rs/stm32h7rs.dtsi:60> lacks #memory-region-cells

That line corresponds to sram1:

sram1: memory@30000000 {
reg = <0x30000000 DT_SIZE_K(16)>;
compatible = "zephyr,memory-region", "mmio-sram";
zephyr,memory-region = "SRAM1";
zephyr,memory-attr = <DT_MEM_ARM(ATTR_MPU_RAM)>;
};

The memory region stm32mp series uses for Ethernet is custom defined region and not predefined region as sram1 or sram2. And in that custom defined region the attribute #memory-region-cells is defined:

eth_ram: sram@2fffc000 {
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x2fffc000 DT_SIZE_K(16)>;
#memory-region-cells = <0>;
zephyr,memory-region = "ETH_SRAM";
};

What do you suggest here?
Note that I tried to get Ethernet working with custom region but wasn't successful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add #memory-region-cells = <0>; to all possible memory regions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding it fixes the mentioned error and doesn't break anything else with this build (http_server sample). I added it to the sram0, sram1 and sram2 nodes.
However, I can't guarantee that this addition doesn't break something else unrelated to Ethernet. I can add it to the commit and see if it triggers any twister-build errors. Would that work?

Comment on lines 37 to 39
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.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could do

#if DT_NODE_HAS_STATUS_OKAY(sram_eth_node) && !DT_SAME_NODE(sram_eth_node, DT_CHOSEN(zephyr_sram))

here and in the sections.ld file to get rid of the build assert

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing assert and replacing it with a similar check works. For example, I already had this:

#if DT_NODE_HAS_COMPAT(sram_eth_node, zephyr_sram)
#error "Invalid Ethernet memory-region: cannot use zephyr,sram. \
Use a SRAM region like sram1 or sram2 for Ethernet."

but @etienne-lms suggested BUILD_ASSERT instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then leave it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. But what do I do about the failing twister-builds caused by the BUILD_ASSERT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apply:

diff --git a/soc/st/stm32/stm32h7rsx/mpu_regions.c b/soc/st/stm32/stm32h7rsx/mpu_regions.c
index 5384d8bb2a6..f28fdf8b5b4 100644
--- a/soc/st/stm32/stm32h7rsx/mpu_regions.c
+++ b/soc/st/stm32/stm32h7rsx/mpu_regions.c
@@ -34,10 +34,6 @@ static const struct arm_mpu_region mpu_regions[] = {
 	DT_NODE_HAS_PROP(DT_NODELABEL(mac), memory_regions)
 #define sram_eth_node DT_PHANDLE(DT_NODELABEL(mac), memory_regions)
 
-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.")
-
 #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),
@@ -48,6 +44,12 @@ BUILD_ASSERT(!DT_SAME_NODE(sram_eth_node, DT_CHOSEN(zephyr_sram)),
 #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,

you can't do a BUILD_ASSERT inside a
static const struct arm_mpu_region mpu_regions[] = {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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 <benjamin.klaric01@gmail.com>
@bklaric1 bklaric1 force-pushed the feat-stm32h7s78_dk-ethernet branch from 1f3a8e3 to cd00b2c Compare December 9, 2025 13:59
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 9, 2025

@etienne-lms
Copy link
Contributor

Question: do I need to add a (second) Copyright line when I edit an existing file or only when I create a new file

You don't need to add a copyright line at source/header files entry when you modify them to have your copyright implicitly taken into account. What drives the copyright owners list is the Git reversion history, which tracks all contributions, not the file entry inline comment.
You are free to add your copyright line, but it's not handy when each contributor adds its own line, especially for small modifications.

@bklaric1
Copy link
Contributor Author

You don't need to add a copyright line at source/header files entry when you modify them to have your copyright implicitly taken into account. What drives the copyright owners list is the Git reversion history, which tracks all contributions, not the file entry inline comment. You are free to add your copyright line, but it's not handy when each contributor adds its own line, especially for small modifications.

That is what I thought, just wanted to be sure. Thanks for the explanation. Noted for future PRs.

};

#ifdef sram_eth_node
BUILD_ASSERT(!DT_SAME_NODE(sram_eth_node, DT_CHOSEN(zephyr_sram)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

Suggested change
BUILD_ASSERT(!DT_SAME_NODE(sram_eth_node, DT_CHOSEN(zephyr_sram)),
BUILD_ASSERT(!DT_SAME_NODE(sram_eth_node, DT_CHOSEN(zephyr_sram)),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

reg = <0x24000000 DT_SIZE_K(456)>;
compatible = "zephyr,memory-region", "mmio-sram";
zephyr,memory-region = "SRAM0";
#memory-region-cells = <0>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed. We don't expect one to reference &sram0 as a memory-region phandle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

compatible = "zephyr,memory-region", "mmio-sram";
zephyr,memory-region = "SRAM1";
#memory-region-cells = <0>;
zephyr,memory-attr = <DT_MEM_ARM(ATTR_MPU_RAM)>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the change made in #97731, won't sram1 MPU attributes here now conflicts with the one defined by mpu_regions.c?

Copy link
Contributor Author

@bklaric1 bklaric1 Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is partially what I was discussing with @TD-JBL in #99164.
I can only confirm that I get no errors during build process and Ethernet works as expected with either sram1 or sram2.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the change made in #97731, won't sram1 MPU attributes here now conflicts with the one defined by mpu_regions.c?

Yes it will create 2 overlaying mpu regions for sram1 and the one from zephyr,memory-attr has the higher priority and should cause problems with caching on the dma region, but for whatever reason it seems to work.

pinctrl-names = "default";
phy-connection-type = "rmii";
phy-handle = <&eth_phy>;
memory-regions = <&sram1>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use sram2 to preserve to previous configuration?
Otherwise, the commit message should tell that h7rs based device ethnet buffers are now in sram1 (AXI SRAM1) by default instead of sram2 (AXI SRAM2).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sram1 and sram2 are AHB, sram0 is AXI sram (called sram 1-4 in the datasheet/rm)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sram2 is disabled by default. That is why I opted to use sram1.
I can switch to using sram2 but that requires the node to be enabled by default. Otherwise an introduction of a fallback is needed (to sram1).
What should I do here?
I will update the commit message in any case. Thanks @TD-JBL for clarification.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the sram2 is disabled to have users enable it on purpose:

  1. Use as normal ram: enabled it in your board and set zephyr,memory-attr = <DT_MEM_ARM(ATTR_MPU_RAM)>
  2. Use it as dma buffer for ethernet, enable it in your board and let mpu_regions.c configure the mpu-region for it.
    I don't mind changing this behaviour, maybe have it already enabled... not sure whats be best way

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that preserving behavior is that important for a dev board

Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment for equivalent change on H7.
Please apply the same for H7RS (configure memory in .dtsi files)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

STM32H7S78-DK Ethernet support

8 participants