Skip to content

Conversation

@bklaric1
Copy link
Contributor

@bklaric1 bklaric1 commented Dec 11, 2025

Changes

  • Added the memory-regions property to h7 series boards (to the ones supporting ethernet) in order to explicitly locate ethernet buffer and descriptor to an sram region inside the DT. Since sram3 was the first option and sram2 the fallback (in mpu_regions.c and sections.ld), I tried to use sram3 when possible and used sram2 otherwise.
  • Added #memory-region-cells to sram3 and sram2 nodes in dts/arm/st/h7 since it is needed by the memory-regions property.
  • Added the same check and definition of the sram_eth_node in mpu_regions.c and sections.ld as in boards: st: stm32h7s78_dk: add Ethernet support #99296.
  • Added memory-regions property to dts/bindings/ethernet/st,stm32h7-ethernet.yaml so twister-builds can run (will be added by the PR listed under Dependencies and can be removed later).

Dependencies

Notes

@etienne-lms suggested this change in #99296.

@bklaric1 bklaric1 force-pushed the feat-stm32h7-memory_region_ethernet branch from f1b20a2 to 60a4695 Compare December 11, 2025 17:12
@bklaric1
Copy link
Contributor Author

Failed twister-builds have nothing to do with the changes this PR introduces, as far as I can say.

Copy link
Contributor

@juickar juickar left a comment

Choose a reason for hiding this comment

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

@bklaric1 try to rebase on main. A fix has been pushed for the CI failed test

@bklaric1 bklaric1 force-pushed the feat-stm32h7-memory_region_ethernet branch from 60a4695 to 81c21ce Compare December 13, 2025 16:04
@bklaric1
Copy link
Contributor Author

@juickar they seem to be queued now for almost a day. Was there another fix in the meantime?

@juickar
Copy link
Contributor

juickar commented Dec 15, 2025

@juickar they seem to be queued now for almost a day. Was there another fix in the meantime?

@bklaric1 No, but from what I witnessed CI also fails to launch on other PRs

@bklaric1
Copy link
Contributor Author

@juickar the first run before the rebase seemed to pass, at least the part that runs the build with code changes. So I guess I'll wait for the CI fix and/or review to update this branch to rerun the checks.

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.

Thanks for the change, but in order to avoid impacting existing users, I'd prefer you keep the changes out of the boards.

So please assign the memory regions (memory-regions = <&sram2/3>;) in .dtsi files and keep existing pattern of using sram3 when available otherwise sram2.
This was, out of tree users won't see any difference.

Comment on lines 39 to 43
#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
Copy link
Member

Choose a reason for hiding this comment

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

Since this is not an option today, I'd suggest to remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was suggested by @etienne-lms. But I can remove it if wanted.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should prevent one to set memory-regions property to the zephyr,sram phandle.
I'd suggest:

 #include <zephyr/devicetree.h>
 #include <zephyr/arch/arm/mpu/arm_mpu_mem_cfg.h>
 
+#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(mac))
+#define sram_eth_node DT_PHANDLE(DT_NODELABEL(mac), memory_regions)
+
+BUILD_ASSERT(DT_NODE_HAS_PROP(DT_NODELABEL(mac), memory_regions) &&
+	     DT_NODE_HAS_STATUS_OKAY(sram_eth_node),
+	     "Ethernet MAC node must provide an enabled memory region for ethernet buffers");
+BUILD_ASSERT(!DT_SAME_NODE(sram_eth_node, DT_CHOSEN(zephyr_sram)),
+	     "Ethernet buffer memory-region cannot be located in Zephyr system RAM.");
+#endif /* mac node enabled */
+
 static const struct arm_mpu_region mpu_regions[] = {
	(...)

 #ifdef sram_eth_node
 	MPU_REGION_ENTRY("SRAM_ETH_BUF",		
 					 DT_REG_ADDR(sram_eth_node),
 					 REGION_RAM_NOCACHE_ATTR(REGION_16K)),
 	MPU_REGION_ENTRY("SRAM_ETH_DESC",
 					 DT_REG_ADDR(sram_eth_node),
 					 REGION_PPB_ATTR(REGION_256B)),
 #endif
 };

 (...)

I guess DT_NODE_HAS_PROP(DT_NODELABEL(mac), memory_regions) assertion can be removed if the property is tagged required.

@bklaric1
Copy link
Contributor Author

bklaric1 commented Dec 15, 2025

Thanks for the change, but in order to avoid impacting existing users, I'd prefer you keep the changes out of the boards.

So please assign the memory regions (memory-regions = <&sram2/3>;) in .dtsi files and keep existing pattern of using sram3 when available otherwise sram2. This was, out of tree users won't see any difference.

@erwango If I understand this correctly, this is what you're suggesting:

  1. Remove memory-regions from all boards dts/dtsi files under boards/st/stm32h7*
  2. Define memory-regions once in dts/arm/st/h7/stm32h7.dtsi with sram3 as default
  3. Override sram3 with sram2 for boards that don't have sram3 in dts/arm/st/h7 dtsi files directly (for example: stm32h723.dtsi)
  4. Restore the previous check/definition in mpu_regions.c and sections.ld

Eveything else stays the same (pending BUILD_ASSERT change).
Is that correct? If yes, then the addition of memory-regions doesn't do anything, since it gets ignored by check/definition in mpu_regions.c. Maybe we consider a hybrid approach?

@erwango
Copy link
Member

erwango commented Dec 15, 2025

@erwango If I understand this correctly, this is what you're suggesting:

  1. Remove memory-regions from all boards dts/dtsi files under boards/st/stm32h7*

Yes

  1. Define memory-regions once in dts/arm/st/h7/stm32h7.dtsi with sram3 as default

Yes

  1. Override sram3 with sram2 for boards that don't have sram3 in dts/arm/st/h7 dtsi files directly (for example: stm32h723.dtsi)

I assume you're talking about SoC instead of "boards".
I'd prefer to use sram2 as default and overwrite with sram3 when available. Otherwise, for a out of tree user of a SoC not supported in tree that has no sram3, it would break.

  1. Restore the previous check/definition in mpu_regions.c and sections.ld

Not required. Keep what is proposed in the PR, except the build assert proposing a fallback on System RAM.
My goal is to stay as close as possible to existing behavior for all users, including out of tree users.

Comment on lines 39 to 43
#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
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should prevent one to set memory-regions property to the zephyr,sram phandle.
I'd suggest:

 #include <zephyr/devicetree.h>
 #include <zephyr/arch/arm/mpu/arm_mpu_mem_cfg.h>
 
+#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(mac))
+#define sram_eth_node DT_PHANDLE(DT_NODELABEL(mac), memory_regions)
+
+BUILD_ASSERT(DT_NODE_HAS_PROP(DT_NODELABEL(mac), memory_regions) &&
+	     DT_NODE_HAS_STATUS_OKAY(sram_eth_node),
+	     "Ethernet MAC node must provide an enabled memory region for ethernet buffers");
+BUILD_ASSERT(!DT_SAME_NODE(sram_eth_node, DT_CHOSEN(zephyr_sram)),
+	     "Ethernet buffer memory-region cannot be located in Zephyr system RAM.");
+#endif /* mac node enabled */
+
 static const struct arm_mpu_region mpu_regions[] = {
	(...)

 #ifdef sram_eth_node
 	MPU_REGION_ENTRY("SRAM_ETH_BUF",		
 					 DT_REG_ADDR(sram_eth_node),
 					 REGION_RAM_NOCACHE_ATTR(REGION_16K)),
 	MPU_REGION_ENTRY("SRAM_ETH_DESC",
 					 DT_REG_ADDR(sram_eth_node),
 					 REGION_PPB_ATTR(REGION_256B)),
 #endif
 };

 (...)

I guess DT_NODE_HAS_PROP(DT_NODELABEL(mac), memory_regions) assertion can be removed if the property is tagged required.

@bklaric1 bklaric1 force-pushed the feat-stm32h7-memory_region_ethernet branch from 81c21ce to 4161046 Compare December 16, 2025 12:01
@bklaric1
Copy link
Contributor Author

bklaric1 commented Dec 16, 2025

@erwango @etienne-lms I amended the commit to add the requested changes, update the property to be required, and update the commit message.
Now the stm32h7.dtsi defines memory-regions and sets it to sram2 by default.
stm32h7a3.dtsi has sram3 override for a and b series (these series don't support Ethernet as of now, but the addition of memory-regions to stm32h7.dtsi requires the addition of this).
stm32h743.dtsi has sram3 override for 43 and 53 series.
stm32h745.dtsi has sram3 override for 45, 47, 55 and 57 series.
I hope I didn't forget anything/understood something wrong. In any case, I am open to feedback.

@bklaric1 bklaric1 force-pushed the feat-stm32h7-memory_region_ethernet branch from 4161046 to f6e1669 Compare December 16, 2025 12:30
Use the memory-regions property in stm32h7.dtsi to explicitly locate
ethernet buffer and descriptor to an sram region. Set sram2 as default
and override with sram3 when available, in soc level .dtsi files.

Add #memory-region-cells to sram2 and sram3 nodes in specific
.dtsi files in dts/arm/st/h7, since it is needed by the
memory-regions property.

Also add the memory-regions property to stm32h563.dtsi since ethernet
defined there uses the same .yaml file and thus requires the same
addition as in stm32h7.dtsi. Also add #memory-region-cells to sram2
and sram3 nodes in stm32h562.dtsi.

Use the same check and definition of the sram_eth_node in mpu_regions.c
and sections.ld as in soc/st/stm32/h7rsx.

Signed-off-by: Benjamin Klaric <benjamin.klaric01@gmail.com>
@bklaric1 bklaric1 force-pushed the feat-stm32h7-memory_region_ethernet branch from f6e1669 to f57c012 Compare December 16, 2025 13:28
@bklaric1
Copy link
Contributor Author

Note: I also needed to add the memory-regions to the mac node in stm32h563.dtsi, since it uses the same .yaml file for ethernet
properties. Otherwise this error is reported:

devicetree error: 'memory-regions' is marked as required in 'properties:' in /__w/zephyr/zephyr/dts/bindings/ethernet/st,stm32h7-ethernet.yaml, but does not appear in <Node /soc/ethernet@40028000/ethernet in /__w/zephyr/zephyr/dts/arm/st/h5/stm32h563.dtsi:29>

Also note that I didn't override the mac region with sram3 here. The reason is that for other SOCs, the sram3 is smaller than sram2 but here it's the other way around.
Let me know if I need to add the override.

@sonarqubecloud
Copy link

compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x20040000 DT_SIZE_K(64)>;
zephyr,memory-region = "SRAM2";
#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.

This should be declared in zephyr,memory-region.yml or somewhere else; IIRC edtlib has special casing for #xxx-cells properties so this works, but it should still be listed and documented as part of a binding.

Copy link
Contributor Author

@bklaric1 bklaric1 Dec 16, 2025

Choose a reason for hiding this comment

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

As far as I can tell, this is needed because memory-regions is defined as phandle-array here:

properties:
memory-regions:
type: phandle-array
description: List of memory region phandles

I don't know if it's possible to define it in memory-region.yaml directly (as <0>), and if it's wanted there, since <0> might not always be the use case.

I hope I didn't miss the point of your comment.

};

&mac {
memory-regions = <&sram3>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: maybe memory-region-names should be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

memory-region-names is not phandle but rather string-array:

memory-region-names:
type: string-array
description: A list of names, one for each corresponding phandle in memory-region

Since we need to pass a referance to sram node, I am unsure if it will work with memory-region-names, tho I might be wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

Names used in memory-region-names are rather identifiers for the phandle indices used in a memory-regions property. It's useful when there can be several phandles, not a single one, see for examples clocks = ... and clock-names.
Since here we only expect one, I don't think it's really useful.

#endif

#if DT_NODE_HAS_STATUS_OKAY(sram_eth_node)
#if defined(sram_eth_node) && DT_NODE_HAS_STATUS_OKAY(sram_eth_node)
Copy link
Contributor

Choose a reason for hiding this comment

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

defined(sram_eth_node) will always evaluate to 1: it is defined literally one line above

Either the check is not necessary:

Suggested change
#if defined(sram_eth_node) && DT_NODE_HAS_STATUS_OKAY(sram_eth_node)
#if DT_NODE_HAS_STATUS_OKAY(sram_eth_node)

Or this is a mistake and you were looking for another macro (DT_NODE_EXISTS? DT_NODE_HAS_PROP on &mac?)

Copy link
Contributor Author

@bklaric1 bklaric1 Dec 16, 2025

Choose a reason for hiding this comment

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

This was a copy&paste mistake I made from mpu_regions.c. The idea will be explained in the comment regarding mpu_regions.c. Will remove it here.

#endif

#if DT_NODE_HAS_STATUS_OKAY(sram_eth_node)
#if defined(sram_eth_node) && DT_NODE_HAS_STATUS_OKAY(sram_eth_node)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto wrt defined(sram_eth_node)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea here was, disregarding the mistake made in sections.ld, to check if sram_eth_node has status = "okay", meaning we check if the sram node passed with memory-regions has status = "okay", to avoid the case of passing sram node which is disabled. This is the case with the current implementation of this check here:

#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(mac))
#define sram_eth_node DT_NODELABEL(sram2)
#if DT_NODE_HAS_STATUS_OKAY(sram_eth_node)

sram2 is passed but it is disabled by default in DT.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, right, I see now that (unlike in the linker script) here sram_eth_node is only defined if the ETH MAC node is enabled. So indeed here it does make sense.

REGION_RAM_NOCACHE_ATTR(REGION_16K)),
MPU_REGION_ENTRY("SRAM_ETH_DESC",
DT_REG_ADDR(sram_eth_node),
REGION_PPB_ATTR(REGION_256B)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, outside PR scope: (ab)using REGION_PPB as a REGION_STRONGLY_ORDERED is really ugly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you said, it's outside the scope of PR and also beyond my current knowledge on the topic, but taking a guess here, could it be defined as REGION_RAM_NOCACHE_ATTR() instead? As far as I can tell, the goal is to make the region non-cacheable.

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume there is a reason for which PPB was used rather than RAM_NOCACHE as done above, but I don't know which. So let's leave it as is for now...

@bklaric1
Copy link
Contributor Author

The failed twister-build (5) is related to missing memory-regions from stm32h7rs.dtsi. As originally stated, this PR depends on #99296, but maybe the dependency should be the other way around.
Should I then add everything related to the memory-regions with this PR and then just use it in another PR?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants