Difference between revisions of "Ethernet device tree configuration"

[quality revision] [pending revision]
m
m
 

1 Article purpose[edit]

This article explains how to configure the Ethernet when it is assigned to the Linux® OS. In that case, it is controlled by the Ethernet framework

The configuration is performed using the device tree mechanism that provides a hardware description of the Ethernet peripheral, used by the STM32 DWMAC driver

2 DT bindings documentation[edit]

The Ethernet is a multifunction device.

Each function is represented by a separate binding document:

  • "Generic" Ethernet device tree bindings [1]
  • specific STM32 ETH device tree bindings[2]

3 DT configuration[edit]

This hardware description is a combination of the STM32 microprocessor device tree files (.dtsi extension) and board device tree files (.dts extension). See the Device tree for an explanation of the device tree file split.

3.1 DT configuration (STM32 level)[edit]

Ethernet peripheral nodes are located in stm32mp151.dtsi [3] file with a disabled status and some required properties such as:

  • Physical base address and size of the device register map
  • STMMAC interrupts
  • stmmaceth clock and Rx, Tx clocks

This is a set of properties that may not vary for a given STM32MP device, such as: register addresses, interrupts, clocks, ...

ethernet0: ethernet@5800a000 {
	compatible = "st,stm32mp1-dwmac", "snps,dwmac-4.20a";
	reg = <0x5800a000 0x2000>;
	reg-names = "stmmaceth";
	interrupts-extended = <&intc GIC_SPI 61 IRQ_TYPE_NONE>;
	interrupt-names = "macirq";
	clock-names = "stmmaceth",
		      "mac-clk-tx",
		      "mac-clk-rx",
		      "eth-ck",
		      "ethstp";
	clocks = <&rcc ETHMAC>,
		 <&rcc ETHTX>,
		 <&rcc ETHRX>,
		 <&rcc ETHCK_K>,
		 <&rcc ETHSTP>;
	st,syscon = <&syscfg 0x4>;
	snps,mixed-burst;
	snps,pbl = <2>;
	snps,axi-config = <&stmmac_axi_config_0>;
	snps,tso;
	power-domains = <&pd_core>;
	status = "disabled";
};

The required and optional properties are fully described in the bindings files.

Warning.png This device tree part is related to STM32 microprocessors. It must be kept as is, without being modified by the end-user. These DT are same between U-Boot and kernel OS


3.2 Ethernet DT configuration (board level)[edit]

The device tree board file (.dts) contains all hardware configurations related to board design. The DT node ("ethernet") should be updated to:

  • Enable the Ethernet block by setting status = "okay".
  • Configure the pins in use via pinctrl, through pinctrl-0 (default pins), pinctrl-1 (sleep pins) and pinctrl-names.
  • Configure Ethernet interface used phy-mode = "rgmii"., (rmii, mii, gmii).
  • Configure Ethernet max speed max-speed = <1000>"..
&ethernet0 {
	status = "okay";
	pinctrl-0 = <&ethernet0_rgmii_pins_a>;
	pinctrl-1 = <&ethernet0_rgmii_pins_sleep_a>;
	pinctrl-names = "default", "sleep";
	phy-mode = "rgmii";
	max-speed = <1000>;
	phy-handle = <&phy0>;

	mdio0 {
		#address-cells = <1>;
		#size-cells = <0>;
		compatible = "snps,dwmac-mdio";
		phy0: ethernet-phy@1 {
			reg = <1>;
		};
	};
};

3.3 DT configuration examples at board level[edit]

The example below shows how to configure and enable an Ethernet instance at board level:

&ethernet0 {
   status = "okay";                             /* enable ethernet0 */ 
   pinctrl-0 = <&ethernet0_rmii_pins_a>;        /* configure pinctrl modes for ethernet0 */
   pinctrl-1 = <&ethernet0_rmii_pins_sleep_a>;  /* configure ethernet0_rmii_pins_sleep_a as sleep pinctrl configuration for ethernet0 */
   pinctrl-names = "default", "sleep";
   phy-mode = "rmii";                           /* configure ethernet phy mode for ethernet0 */
   max-speed = <100>;                           /* configure ethernet max speed for ethernet0 */
   phy-handle = <&phy0>;
   
   mdio0 {
       #address-cells = <1>;
       #size-cells = <0>;
       compatible = "snps,dwmac-mdio";
       phy0: ethernet-phy@1 {
           reg = <1>;                           /* configure ethernet phy @ for ethernet0 */
       };
   };
};

How to configure Ethernet for :

3.3.1 RMII with Crystal on PHY (Reference clock (standard RMII clock name) is provided by a Phy Crystal)[edit]

   ethernet0: ethernet@5800a000 {
       compatible = "st,stm32mp1-dwmac", "snps,dwmac-4.20a";
       reg = <0x5800a000 0x2000>;
       reg-names = "stmmaceth";
       interrupts-extended = <&intc GIC_SPI 61 IRQ_TYPE_LEVEL_HIGH>,
                             <&intc GIC_SPI 62 IRQ_TYPE_LEVEL_HIGH>,
                             <&exti 70 1>;
       interrupt-names = "macirq",
                         "eth_wake_irq",
                         "stm32_pwr_wakeup";
       clock-names = "stmmaceth",
                     "mac-clk-tx",
                     "mac-clk-rx",
                     "eth-ck",
                     "ethstp";
       clocks = <&rcc ETHMAC>,
                <&rcc ETHTX>,
                <&rcc ETHRX>,
                <&rcc ETHCK_K>,
                <&rcc ETHSTP>;
       st,syscon = <&syscfg 0x4>;
       snps,mixed-burst;
       snps,pbl = <2>;
       snps,en-tx-lpi-clockgating;
       snps,axi-config = <&stmmac_axi_config_0>;
       snps,tso;
       power-domains = <&pd_core>;
       status = "disabled";
};


   &ethernet0 {
       status = "okay";
       pinctrl-0 = <&ethernet0_rmii_pins_a>;
       pinctrl-1 = <&ethernet0_rmii_pins_sleep_a>;
       pinctrl-names = "default", "sleep";
       phy-mode = "rmii";
       max-speed = <100>;
       phy-handle = <&phy0>;
       mdio0 {
               #address-cells = <1>;
               #size-cells = <0>;
               compatible = "snps,dwmac-mdio";
               phy0: ethernet-phy@0 {
                       reg = <0>;
               };
       };
   };

3.3.2 RMII with 25MHz on ETH_CLK (no PHY Crystal), REF_CLK from PHY (Reference clock (standard RMII clock name) is provided by a RCC SoC internal clockPHY)[edit]

   ethernet0: ethernet@5800a000 {
       compatible = "st,stm32mp1-dwmac", "snps,dwmac-4.20a";
       reg = <0x5800a000 0x2000>;
       reg-names = "stmmaceth";
       interrupts-extended = <&intc GIC_SPI 61 IRQ_TYPE_LEVEL_HIGH>,
                             <&intc GIC_SPI 62 IRQ_TYPE_LEVEL_HIGH>,
                             <&exti 70 1>;
       interrupt-names = "macirq",
                         "eth_wake_irq",
                         "stm32_pwr_wakeup";
       clock-names = "stmmaceth",
                      "ethmac-ckclk-tx",
                      "mac-clk-txrx",
                      "maceth-clk-rxck",
                      "ethstp";
       clocks = <&rcc ETHMAC>,
                      <&rcc ETHCK_K>ETHTX>,
                      <&rcc ETHRX>,
        <&rcc ETHTX>,                 <&rcc ETHRX>ETHCK_K>,
                      <&rcc ETHSTP>;
       st,syscon = <&syscfg 0x4>;
       snps,mixed-burst;
       snps,pbl = <2>;
       snps,en-tx-lpi-clockgating;
       snps,axi-config = <&stmmac_axi_config_0>;
       snps,tso;
       power-domains = <&pd_core>;
       status = "disabled";
};
   &ethernet0 {
       status = "okay";
       pinctrl-0 = <&ethernet0_rmii_pins_a>;
       pinctrl-1 = <&ethernet0_rmii_pins_sleep_a>;
       pinctrl-names = "default", "sleep";
       phy-mode = "rmii";
       max-speed = <100>;
       phy-handle = <&phy0>;
       mdio0 {
               #address-cells = <1>;
               #size-cells = <0>;
               compatible = "snps,dwmac-mdio";
               phy0: ethernet-phy@0 {
                       reg = <0>;
               };
       };
   };

+ update stm32mp15-pinctrl.dtsi [4] to add ETHCK pin in ethernet0_rmii_pins_* node:
For example:

 <STM32_PINMUX('G', 8, AF2)>, /* ETH_RMII_ETHCK */

+ Need also to update TFA devicetree to generate 25Mhz clock (from PLL4P or PLL3Q):
for example if PLL4P in ed1 board: update fdts/stm32mp15xx-edx.dtsi

st,pkcs = <
 CLK_CKPER_HSE
 CLK_FMC_ACLK
 CLK_QSPI_ACLK
 - CLK_ETH_DISABLED
 + CLK_ETH_PLL4P
...
 /* VCO = 600.0 MHz => P = 25, Q = 50, R = 50 */
   pll4: st,pll@3 {
     compatible = "st,stm32mp1-pll";
     reg = <3>;
     cfg = < 1 49 23 11 11 PQR(1,1,1) >;
 };

3.3.3 RMII with 50MHz on ETH_CLK (no PHY Crystal), internal REF_CLK from RCC (Reference clock (standard RMII clock name) is provided by a RCC SoC internal clock)[edit]

   ethernet0: ethernet@5800a000 {
       compatible = "st,stm32mp1-dwmac", "snps,dwmac-4.20a";
       reg = <0x5800a000 0x2000>;
       reg-names = "stmmaceth";
       interrupts-extended = <&intc GIC_SPI 61 IRQ_TYPE_LEVEL_HIGH>,
                             <&intc GIC_SPI 62 IRQ_TYPE_LEVEL_HIGH>,
                             <&exti 70 1>;
       interrupt-names = "macirq",
                         "eth_wake_irq",
                         "stm32_pwr_wakeup";
       clock-names = "stmmaceth",
                      "ethmac-ckclk-tx",
                      "mac-clk-txrx",
                      "maceth-clk-rxck",
                      "ethstp";
       clocks = <&rcc ETHMAC>,
                      <&rcc ETHCK_K>ETHTX>,
                      <&rcc ETHRX>,
        <&rcc ETHTX>,                 <&rcc ETHRX>ETHCK_K>,
                      <&rcc ETHSTP>;
       st,syscon = <&syscfg 0x4>;
       snps,mixed-burst;
       snps,pbl = <2>;
       snps,en-tx-lpi-clockgating;
       st,eth_ref_clk_sel;               /* In case of U-Boot */ 
      or
       st,eth-ref-clk-selext-phyclk;
              /* In case of Linux Kernel */ 
       snps,axi-config = <&stmmac_axi_config_0>;
       snps,tso;
       power-domains = <&pd_core>;
       status = "disabled";
};
   &ethernet0 {
       status = "okay";
       pinctrl-0 = <&ethernet0_rmii_pins_a>;
       pinctrl-1 = <&ethernet0_rmii_pins_sleep_a>;
       pinctrl-names = "default", "sleep";
       phy-mode = "rmii";
       max-speed = <100>;
       phy-handle = <&phy0>;
       mdio0 {
               #address-cells = <1>;
               #size-cells = <0>;
               compatible = "snps,dwmac-mdio";
               phy0: ethernet-phy@0 {
                       reg = <0>;
               };
       };
   };

+ update stm32mp15-pinctrl.dtsi to add ETHCK pin in ethernet0_rmii_pins_* node:
For example:

 <STM32_PINMUX('G', 8, AF2)>, /* ETH_RMII_ETHCK */

+ Need also to update TFA to generate 50Mhz clock (from PLL4P or PLL3Q):
for example if PLL4P in ed1 board: update fdts/stm32mp15xx-edx.dtsi

st,pkcs = <
 CLK_CKPER_HSE
 CLK_FMC_ACLK
 CLK_QSPI_ACLK
 - CLK_ETH_DISABLED
 + CLK_ETH_PLL4P
...
 /* VCO = 508.0 MHz => P = 50, Q = 60, R = 60 */
   pll4: st,pll@3 {
     compatible = "st,stm32mp1-pll";
     reg = <3>;
    cfg = < 1 49 11 9 9 PQR(1,1,1) >;
  };

3.3.4 RGMII with Crystal on PHY, CLK125 from PHY (Reference clock (standard RGMII clock name) is provided by a Phy Crystal)[edit]

   ethernet0: ethernet@5800a000 {
       compatible = "st,stm32mp1-dwmac", "snps,dwmac-4.20a";
       reg = <0x5800a000 0x2000>;
       reg-names = "stmmaceth";
       interrupts-extended = <&intc GIC_SPI 61 IRQ_TYPE_LEVEL_HIGH>,
                             <&intc GIC_SPI 62 IRQ_TYPE_LEVEL_HIGH>,
                             <&exti 70 1>;
       interrupt-names = "macirq",
                         "eth_wake_irq",
                         "stm32_pwr_wakeup";
       clock-names = "stmmaceth",
                      "mac-clk-tx",
                      "mac-clk-rx",
                      "eth-ck",
                      "ethstp";
       clocks = <&rcc ETHMAC>,
                      <&rcc ETHTX>,
                      <&rcc ETHTX>ETHRX>,
                      <&rcc ETHRX>ETHCK_K>,
                      <&rcc ETHSTP>;
       st,syscon = <&syscfg 0x4>;
       snps,mixed-burst;
       snps,pbl = <2>;
       snps,en-tx-lpi-clockgating;
       snps,axi-config = <&stmmac_axi_config_0>;
       snps,tso;
       power-domains = <&pd_core>;
       status = "disabled";
   };
   &ethernet0 {
       status = "okay";
       pinctrl-0 = <&ethernet0_rgmii_pins_a>;
       pinctrl-1 = <&ethernet0_rgmii_pins_sleep_a>;
       pinctrl-names = "default", "sleep";
       phy-mode = "rgmii";
       max-speed = <1000>;
       phy-handle = <&phy0>;
       mdio0 {
               #address-cells = <1>;
               #size-cells = <0>;
               compatible = "snps,dwmac-mdio";
               phy0: ethernet-phy@0 {
                       reg = <0>;
               };
           };
   };

3.3.5 RGMII with 25MHz on ETH_CLK (no PHY Crystal), CLK125 from PHY (Reference clock (standard RGMII clock name) is provided by a RCC SoC internal clock)[edit]

   ethernet0: ethernet@5800a000 {
       compatible = "st,stm32mp1-dwmac", "snps,dwmac-4.20a";
       reg = <0x5800a000 0x2000>;
       reg-names = "stmmaceth";
       interrupts-extended = <&intc GIC_SPI 61 IRQ_TYPE_LEVEL_HIGH>,
                             <&intc GIC_SPI 62 IRQ_TYPE_LEVEL_HIGH>,
                             <&exti 70 1>;
       interrupt-names = "macirq",
                         "eth_wake_irq",
                         "stm32_pwr_wakeup";
       clock-names = "stmmaceth",
                      "ethmac-ckclk-tx",
                      "mac-clk-txrx",
                      "maceth-clk-rxck",
                      "ethstp";
       clocks = <&rcc ETHMAC>,
                      <&rcc ETHCK_K>ETHTX>,
                      <&rcc ETHRX>,
        <&rcc ETHTX>,                 <&rcc ETHRX>ETHCK_K>,
                      <&rcc ETHSTP>;
       st,syscon = <&syscfg 0x4>;
       snps,mixed-burst;
       snps,pbl = <2>;
       snps,en-tx-lpi-clockgating;
       snps,axi-config = <&stmmac_axi_config_0>;
       snps,tso;
       power-domains = <&pd_core>;
       status = "disabled";
};
   &ethernet0 {
       status = "okay";
       pinctrl-0 = <&ethernet0_rgmii_pins_a>;
       pinctrl-1 = <&ethernet0_rgmii_pins_sleep_a>;
       pinctrl-names = "default", "sleep";
       phy-mode = "rgmii";
       max-speed = <1000>;
       phy-handle = <&phy0>;
       mdio0 {
               #address-cells = <1>;
               #size-cells = <0>;
               compatible = "snps,dwmac-mdio";
               phy0: ethernet-phy@0 {
                       reg = <0>;
               };
       };
   };

+ update stm32mp15-pinctrl.dtsi to add ETHCK pin in ethernet0_rgmii_pins_* node:
For example:

 <STM32_PINMUX('G', 8, AF2)>, /* ETH_RGMII_ETHCK */

+ Need also to update TFA to generate 25Mhz clock (from PLL4P or PLL3Q):
for example if PLL4P in ed1 board: update fdts/stm32mp15xx-edx.dtsi

st,pkcs = <
 CLK_CKPER_HSE
 CLK_FMC_ACLK
 CLK_QSPI_ACLK
 - CLK_ETH_DISABLED
 + CLK_ETH_PLL4P
...
 /* VCO = 600.0 MHz => P = 25, Q = 50, R = 50 */
   pll4: st,pll@3 {
     compatible = "st,stm32mp1-pll";
     reg = <3>;
     cfg = < 1 49 23 11 11 PQR(1,1,1) >;
 };

3.3.6 RGMII with Crystal on PHY, no 125Mhz from PHY[edit]

   ethernet0: ethernet@5800a000 {
       compatible = "st,stm32mp1-dwmac", "snps,dwmac-4.20a";
       reg = <0x5800a000 0x2000>;
       reg-names = "stmmaceth";
       interrupts-extended = <&intc GIC_SPI 61 IRQ_TYPE_LEVEL_HIGH>,
                             <&intc GIC_SPI 62 IRQ_TYPE_LEVEL_HIGH>,
                             <&exti 70 1>;
       interrupt-names = "macirq",
                         "eth_wake_irq",
                         "stm32_pwr_wakeup";
       clock-names = "stmmaceth",
                      "ethmac-ckclk-tx",
                      "mac-clk-txrx",
                      "maceth-clk-rxck",
                      "ethstp";
       clocks = <&rcc ETHMAC>,
                      <&rcc ETHCK_K>ETHTX>,
                      <&rcc ETHRX>,
        <&rcc ETHTX>,                 <&rcc ETHRX>ETHCK_K>,
                      <&rcc ETHSTP>;
       st,syscon = <&syscfg 0x4>;
       snps,mixed-burst;
       snps,pbl = <2>;
       snps,en-tx-lpi-clockgating;
       st,eth_clk_sel;               /* In case of U-Boot */ 
      or
       st,eth-clk-selext-phyclk;
              /* In case of Linux Kernel */ 
       snps,axi-config = <&stmmac_axi_config_0>;
       snps,tso;
       power-domains = <&pd_core>;
       status = "disabled";
};
   &ethernet0 {
       status = "okay";
       pinctrl-0 = <&ethernet0_rgmii_pins_a>;
       pinctrl-1 = <&ethernet0_rgmii_pins_sleep_a>;
       pinctrl-names = "default", "sleep";
       phy-mode = "rgmii";
       max-speed = <1000>;
       phy-handle = <&phy0>;
       mdio0 {
               #address-cells = <1>;
               #size-cells = <0>;
               compatible = "snps,dwmac-mdio";
               phy0: ethernet-phy@0 {
                       reg = <0>;
               };
       };
   };

+ update stm32mp15-pinctrl.dtsi to delete CLK125 pin (also no need of ETHCK pin) in ethernet0_rgmii_pins_* node:

+ Need also to update TFA to generate 125Mhz clock (from PLL4P or PLL3Q):
for example if PLL4P in ed1 board: update fdts/stm32mp15xx-edx.dtsi

st,pkcs = <
 CLK_CKPER_HSE
 CLK_FMC_ACLK
 CLK_QSPI_ACLK
 - CLK_ETH_DISABLED
 + CLK_ETH_PLL4P
...
 /* VCO = 750.0 MHz => P = 125, Q = 62.5, R = 62.5 */
 pll4: st,pll@3 {
     compatible = "st,stm32mp1-pll";
     reg = <3>;
     cfg = < 3 124 5 11 11 PQR(1,1,1) >;
 };

4 How to configure a PHY reset signal[edit]

Some Ethernet PHY have possibility to drive PHY reset using GPIO

   &ethernet0 {
       status = "okay";
       pinctrl-0 = <&ethernet0_rgmii_pins_a>;
       pinctrl-1 = <&ethernet0_rgmii_pins_sleep_a>;
       pinctrl-names = "default", "sleep";
       phy-mode = "rgmii";
       max-speed = <1000>;
       phy-handle = <&phy0>;
       mdio0 {
               #address-cells = <1>;
               #size-cells = <0>;
               compatible = "snps,dwmac-mdio";
               phy0: ethernet-phy@0 {
                       compatible = "ethernet-phy-id0007.c131";
                       reset-gpios = <&gpioa 4 GPIO_ACTIVE_LOW>  
                       reg = <0>;
               };
       };
   };


You need to find and replace value 0007.c131 corresponding to your Ethernet PHY: this can be found in datasheet of the Ethernet PHY, and find PHY Identifier 1 and PHY Identifier 2 registers.

5 How to configure Ethernet using CubeMX[edit]

The STM32CubeMX tool can be used to configure the STM32MPU device and get the corresponding platform configuration device tree files.
The STM32CubeMX may not support all the properties described in the above DT bindings documentation paragraph. If so, the tool inserts user sections in the generated device tree. These sections can then be edited to add some properties and they are preserved from one generation to another. Refer to STM32CubeMX user manual for further information.

5 6 References[edit]


{{ClonedFrom | stm32mpu}}== Article purpose ==
This article explains how to configure the [[ETH internal peripheral|Ethernet]] when it is assigned to the Linux<sup>&reg;</sup> OS. In that case, it is controlled by the [[Ethernet overview|Ethernet framework]]

The configuration is performed using the [[Device tree|device tree]] mechanism that provides a hardware description of the Ethernet peripheral, used by the STM32 DWMAC driver

== DT bindings documentation ==
The ''Ethernet'' is a multifunction device.

Each function is represented by a separate binding document:
* "Generic" Ethernet device tree bindings <ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/net/stmmac.txt}}</ref>

* specific STM32 ETH device tree bindings<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/net/stm32-dwmac.txt}}</ref>

{{ReviewsComments|-- [[User:Olivier Kaps|Olivier Kaps]] ([[User talk:Olivier Kaps|talk]]) 18:08, 9 July 2021 (CEST)<br />Could be a good idea to update the link to yaml directly?
(1) This file has moved to snps,dwmac.yaml -> Documentation/devicetree/bindings/net/snps%2Cdwmac.yaml<br>

(2) Link does not exist in 5.10 kernel version -> linux/Documentation/devicetree/bindings/net/stm32-dwmac.yaml
}}== DT configuration ==
This hardware description is a combination of the '''STM32 microprocessor''' device tree files (''.dtsi'' extension) and '''board''' device tree files (''.dts'' extension). See the [[Device tree]] for an explanation of the device tree file split. 

=== DT configuration (STM32 level) ===

Ethernet peripheral nodes are located in stm32mp151.dtsi <ref>{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp151.dtsi | arch/arm/boot/dts/stm32mp151.dtsi}}, STM32MP151 device tree file</ref> file with a disabled status and some required properties such as:
* Physical base address and size of the device register map
* STMMAC interrupts {{ReviewsComments|-- [[User:Olivier Kaps|Olivier Kaps]] ([[User talk:Olivier Kaps|talk]]) 18:08, 9 July 2021 (CEST)<br />STM32 DWMAC interrupts ?}}* stmmaceth clock and Rx, Tx clocks

This is a set of properties that may not vary for a given STM32MP device, such as: register addresses, interrupts, clocks, ...
<pre>

ethernet0: ethernet@5800a000 {
	compatible = "st,stm32mp1-dwmac", "snps,dwmac-4.20a";
	reg = <0x5800a000 0x2000>;
	reg-names = "stmmaceth";
	interrupts-extended = <&intc GIC_SPI 61 IRQ_TYPE_NONE>;
	interrupt-names = "macirq";
	clock-names = "stmmaceth",
		      "mac-clk-tx",
		      "mac-clk-rx",
		      "eth-ck",
		      "ethstp";
	clocks = <&rcc ETHMAC>,<&rcc ETHTX>,<&rcc ETHRX>,<&rcc ETHSTPETHCK_K>,<&rcc ETHSTP>;
	st,syscon = <&syscfg 0x4>;
	snps,mixed-burst;
	snps,pbl = <2>;
	snps,axi-config = <&stmmac_axi_config_0>;
	snps,tso;
	power-domains = <&pd_core>;
	status = "disabled";
};</pre>


The required and optional properties are fully described in the [[Ethernet device tree configuration#DT bindings documentation|bindings files]].
{{Warning|This device tree part is related to STM32 microprocessors. It must be kept as is, without being modified by the end-user.}}
 These DT are same between U-Boot and kernel OS}}
{{ReviewsComments|-- [[User:Emmanuel Combette|Emmanuel Combette]] ([[User talk:Emmanuel Combette|talk]]) 11:27, 9 July 2021 (CEST)<br />"These DT are same between U-Boot and kernel OS", can you move this warning in chapter above  3 DT configuration . Misleading in this chapter, as we can consider this is apply only at STM32 level  and not at board level}}
=== Ethernet DT configuration (board level) ===

The device tree board file (.dts) contains all hardware configurations related to board design. The DT node ('''"ethernet"''') should be updated to:

* Enable the Ethernet block by setting '''status = "okay".'''
* Configure the pins in use via [[Pinctrl overview|pinctrl]], through '''pinctrl-0''' (default pins), '''pinctrl-1''' (sleep pins) and '''pinctrl-names'''.
* Configure Ethernet interface used '''phy-mode = "rgmii".''', (rmii, mii, gmii).
* Configure Ethernet max speed '''max-speed = <1000>".'''.
<pre>

&ethernet0 {
	status = "okay";
	pinctrl-0 = <&ethernet0_rgmii_pins_a>;
	pinctrl-1 = <&ethernet0_rgmii_pins_sleep_a>;
	pinctrl-names = "default", "sleep";
	phy-mode = "rgmii";
	max-speed = <1000>;
	phy-handle = <&phy0>;

	mdio0 {
		#address-cells = <1>;
		#size-cells = <0>;
		compatible = "snps,dwmac-mdio";
		phy0: ethernet-phy@1 {
			reg = <1>;
		};
	};
};</pre>


=== DT configuration examples at board level ===
The example below shows how to configure and enable an Ethernet instanceat board level:
{{ReviewsComments|-- 10 oct ECO <br /> in all the example <&rcc SYSCFG>; is missinh on the clock list , isn't it ?}}
&ethernet0 {
    status = "okay";                             {{highlight|/* enable ethernet0 */}} 
    pinctrl-0 = <&ethernet0_rmii_pins_a>;        {{highlight|/* configure pinctrl modes for ethernet0 */}}
    pinctrl-1 = <&ethernet0_rmii_pins_sleep_a>;  {{highlight|/* configure ethernet0_rmii_pins_sleep_a as sleep pinctrl configuration for ethernet0 */}}
    pinctrl-names = "default", "sleep";
    phy-mode = "rmii";                           {{highlight|/* configure ethernet phy mode for ethernet0 */}}
    max-speed = <100>;                           {{highlight|/* configure ethernet max speed for ethernet0 */}}
    phy-handle = <&phy0>;

    mdio0 {
        #address-cells = <1>;
        #size-cells = <0>;
        compatible = "snps,dwmac-mdio";
        phy0: ethernet-phy@1 {
            reg = <1>;                           {{highlight|/* configure ethernet phy @ for ethernet0 */}}
        };
    };
 };

How to configure Ethernet for :
==== RMII with Crystal on PHY (Reference clock (standard RMII clock name) is provided by a Phy Crystal) ====

    ethernet0: ethernet@5800a000 {
        compatible = "st,stm32mp1-dwmac", "snps,dwmac-4.20a";
        reg = <0x5800a000 0x2000>;
        reg-names = "stmmaceth";
        interrupts-extended = <&intc GIC_SPI 61 IRQ_TYPE_LEVEL_HIGH>,<&intc GIC_SPI 62 IRQ_TYPE_LEVEL_HIGH>,<&exti 70 1>;
        interrupt-names = "macirq",
                          "eth_wake_irq",
                          "stm32_pwr_wakeup";
        clock-names = "stmmaceth",
                      "mac-clk-tx",
                      "mac-clk-rx",
                      "eth-ck",
                      "ethstp";
        clocks = <&rcc ETHMAC>,<&rcc ETHTX>,<&rcc ETHRX>,<&rcc ETHSTPETHCK_K>,<&rcc ETHSTP>;
        st,syscon = <&syscfg 0x4>;
        snps,mixed-burst;
        snps,pbl = <2>;
        snps,en-tx-lpi-clockgating;
        snps,axi-config = <&stmmac_axi_config_0>;
        snps,tso;
        power-domains = <&pd_core>;
        status = "disabled";
 };
{{ReviewsComments|-- [[User:Olivier Kaps|Olivier Kaps]] ([[User talk:Olivier Kaps|talk]]) 18:08, 9 July 2021 (CEST)<br /> Are we still at board level or is it a merge of the stm32mp151.dtsi file above?  if it is the case then the comment in 3.1 not to touch the stm32mp151.dtsi file should be removed }}
&ethernet0 {
        status = "okay";
        pinctrl-0 = <&ethernet0_rmii_pins_a>;
        pinctrl-1 = <&ethernet0_rmii_pins_sleep_a>;
        pinctrl-names = "default", "sleep";
        phy-mode = "rmii";
        max-speed = <100>;
        phy-handle = <&phy0>;
        mdio0 {
                #address-cells = <1>;
                #size-cells = <0>;
                compatible = "snps,dwmac-mdio";
                phy0: ethernet-phy@0 {
                        reg = <0>;
                };
        };
    };

==== RMII with 25MHz on ETH_CLK (no PHY Crystal), REF_CLK from PHY (Reference clock (standard RMII clock name) is provided by a RCC SoC internal clockPHY) ====

    ethernet0: ethernet@5800a000 {
        compatible = "st,stm32mp1-dwmac", "snps,dwmac-4.20a";
        reg = <0x5800a000 0x2000>;
        reg-names = "stmmaceth";
        interrupts-extended = <&intc GIC_SPI 61 IRQ_TYPE_LEVEL_HIGH>,<&intc GIC_SPI 62 IRQ_TYPE_LEVEL_HIGH>,<&exti 70 1>;
        interrupt-names = "macirq",
                          "eth_wake_irq",
                          "stm32_pwr_wakeup";
        clock-names = "stmmaceth",'''"eth-ck",'''
                      "mac-clk-tx",
                      "mac-clk-rx",
                      "ethstp";
        clocks = <&rcc ETHMAC>,
                 '''<&rcc ETHCK_K>,'''                <&rcc ETHTX>,<&rcc ETHRX>, "mac-clk-tx",
                       "mac-clk-rx",
                       "eth-ck",
                       "ethstp";
        clocks = <&rcc ETHMAC>,<&rcc ETHTX>,<&rcc ETHRX>,<&rcc ETHCK_K>,<&rcc ETHSTP>;
        st,syscon = <&syscfg 0x4>;
        snps,mixed-burst;
        snps,pbl = <2>;
        snps,en-tx-lpi-clockgating;
        snps,axi-config = <&stmmac_axi_config_0>;
        snps,tso;
        power-domains = <&pd_core>;
        status = "disabled";
 };

    &ethernet0 {
        status = "okay";
        pinctrl-0 = <&ethernet0_rmii_pins_a>;
        pinctrl-1 = <&ethernet0_rmii_pins_sleep_a>;
        pinctrl-names = "default", "sleep";
        phy-mode = "rmii";
        max-speed = <100>;
        phy-handle = <&phy0>;
        mdio0 {
                #address-cells = <1>;
                #size-cells = <0>;
                compatible = "snps,dwmac-mdio";
                phy0: ethernet-phy@0 {
                        reg = <0>;
                };
        };
    };

+ update stm32mp15-pinctrl.dtsi <ref>{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp15-pinctrl.dtsi | arch/arm/boot/dts/stm32mp15-pinctrl.dtsi}}, STM32MP15 pinctrl device tree file</ref> to add ETHCK pin in ethernet0_rmii_pins_* node:<br>

For example:<STM32_PINMUX('G', 8, AF2)>, /* ETH_RMII_ETHCK */

+ Need also to update TFA devicetree to generate 25Mhz clock (from PLL4P or PLL3Q):<br>

for example if PLL4P in ed1 board:
update fdts/stm32mp15xx-edx.dtsi 

 st,pkcs = <
  CLK_CKPER_HSE
  CLK_FMC_ACLK
  CLK_QSPI_ACLK
  '''- CLK_ETH_DISABLED'''
  '''+ CLK_ETH_PLL4P'''
 ...
  /* VCO = 600.0 MHz => P = 25, Q = 50, R = 50 */
    pll4: st,pll@3 {
      compatible = "st,stm32mp1-pll";
      reg = <3>;
      '''cfg = < 1 49 23 11 11 PQR(1,1,1) >;'''
  };

==== RMII with 50MHz on ETH_CLK (no PHY Crystal), internal REF_CLK from RCC  (Reference clock (standard RMII clock name) is provided by a RCC SoC internal clock) ====

    ethernet0: ethernet@5800a000 {
        compatible = "st,stm32mp1-dwmac", "snps,dwmac-4.20a";
        reg = <0x5800a000 0x2000>;
        reg-names = "stmmaceth";
        interrupts-extended = <&intc GIC_SPI 61 IRQ_TYPE_LEVEL_HIGH>,<&intc GIC_SPI 62 IRQ_TYPE_LEVEL_HIGH>,<&exti 70 1>;
        interrupt-names = "macirq",
                          "eth_wake_irq",
                          "stm32_pwr_wakeup";
        clock-names = "stmmaceth",'''"eth-ck",'''
                      "mac-clk-tx",
                      "mac-clk-rx",
                      "ethstp";
        clocks = <&rcc ETHMAC>,
                 '''<&rcc ETHCK_K>,'''                <&rcc ETHTX>,<&rcc ETHRX>, "mac-clk-tx",
                       "mac-clk-rx",
                       "eth-ck",
                       "ethstp";
        clocks = <&rcc ETHMAC>,<&rcc ETHTX>,<&rcc ETHRX>,<&rcc ETHCK_K>,<&rcc ETHSTP>;
        st,syscon = <&syscfg 0x4>;
        snps,mixed-burst;
        snps,pbl = <2>;
        snps,en-tx-lpi-clockgating;
        '''st,eth_ref_clk_sel;'''               {{highlight|/* In case of U-Boot */}} 
       or
        '''st,eth-ref-clk-sel;'''               {{highlight|/* In case of Linux Kernel */}} ext-phyclk;'''snps,axi-config = <&stmmac_axi_config_0>;
        snps,tso;
        power-domains = <&pd_core>;
        status = "disabled";
 };

    &ethernet0 {
        status = "okay";
        pinctrl-0 = <&ethernet0_rmii_pins_a>;
        pinctrl-1 = <&ethernet0_rmii_pins_sleep_a>;
        pinctrl-names = "default", "sleep";
        phy-mode = "rmii";
        max-speed = <100>;
        phy-handle = <&phy0>;
        mdio0 {
                #address-cells = <1>;
                #size-cells = <0>;
                compatible = "snps,dwmac-mdio";
                phy0: ethernet-phy@0 {
                        reg = <0>;
                };
        };
    };

+ update stm32mp15-pinctrl.dtsi to add ETHCK pin in ethernet0_rmii_pins_* node:<br>

For example:<STM32_PINMUX('G', 8, AF2)>, /* ETH_RMII_ETHCK */

+ Need also to update TFA to generate 50Mhz clock (from PLL4P or PLL3Q):<br>

for example if PLL4P in ed1 board:
update fdts/stm32mp15xx-edx.dtsi 
 st,pkcs = <
  CLK_CKPER_HSE
  CLK_FMC_ACLK
  CLK_QSPI_ACLK
  '''- CLK_ETH_DISABLED'''
  '''+ CLK_ETH_PLL4P'''
 ...
  /* VCO = 508.0 MHz => P = 50, Q = 60, R = 60 */
    pll4: st,pll@3 {
      compatible = "st,stm32mp1-pll";
      reg = <3>;
     '''cfg = < 1 49 11 9 9 PQR(1,1,1) >;'''
   };

==== RGMII with Crystal on PHY, CLK125 from PHY (Reference clock (standard RGMII clock name) is provided by a Phy Crystal) ====

    ethernet0: ethernet@5800a000 {
        compatible = "st,stm32mp1-dwmac", "snps,dwmac-4.20a";
        reg = <0x5800a000 0x2000>;
        reg-names = "stmmaceth";
        interrupts-extended = <&intc GIC_SPI 61 IRQ_TYPE_LEVEL_HIGH>,<&intc GIC_SPI 62 IRQ_TYPE_LEVEL_HIGH>,<&exti 70 1>;
        interrupt-names = "macirq",
                          "eth_wake_irq",
                          "stm32_pwr_wakeup";
        clock-names = "stmmaceth", "mac-clk-tx", "mac-clk-rx","ethstp";
        clocks = <&rcc ETHMAC>,             <&rcc ETHTX>,<&rcc ETHRX>, "eth-ck",
                       "ethstp";
        clocks = <&rcc ETHMAC>,<&rcc ETHTX>,<&rcc ETHRX>,<&rcc ETHCK_K>,<&rcc ETHSTP>;
        st,syscon = <&syscfg 0x4>;
        snps,mixed-burst;
        snps,pbl = <2>;
        snps,en-tx-lpi-clockgating;
        snps,axi-config = <&stmmac_axi_config_0>;
        snps,tso;
        power-domains = <&pd_core>;
        status = "disabled";
    };

    &ethernet0 {
        status = "okay";
        pinctrl-0 = <&ethernet0_rgmii_pins_a>;
        pinctrl-1 = <&ethernet0_rgmii_pins_sleep_a>;
        pinctrl-names = "default", "sleep";
        phy-mode = "rgmii";
        max-speed = <1000>;
        phy-handle = <&phy0>;
        mdio0 {
                #address-cells = <1>;
                #size-cells = <0>;
                compatible = "snps,dwmac-mdio";
                phy0: ethernet-phy@0 {
                        reg = <0>;
                };
            };
    };

==== RGMII with 25MHz on ETH_CLK (no PHY Crystal), CLK125 from PHY (Reference clock (standard RGMII clock name) is provided by a RCC SoC internal clock) ====

    ethernet0: ethernet@5800a000 {
        compatible = "st,stm32mp1-dwmac", "snps,dwmac-4.20a";
        reg = <0x5800a000 0x2000>;
        reg-names = "stmmaceth";
        interrupts-extended = <&intc GIC_SPI 61 IRQ_TYPE_LEVEL_HIGH>,<&intc GIC_SPI 62 IRQ_TYPE_LEVEL_HIGH>,<&exti 70 1>;
        interrupt-names = "macirq",
                          "eth_wake_irq",
                          "stm32_pwr_wakeup";
        clock-names = "stmmaceth",'''"eth-ck",'''
                      "mac-clk-tx",
                      "mac-clk-rx",
                      "ethstp";
        clocks = <&rcc ETHMAC>,
                 '''<&rcc ETHCK_K>,'''                <&rcc ETHTX>,<&rcc ETHRX>, "mac-clk-tx",
                       "mac-clk-rx",
                       "eth-ck",
                       "ethstp";
        clocks = <&rcc ETHMAC>,<&rcc ETHTX>,<&rcc ETHRX>,<&rcc ETHCK_K>,<&rcc ETHSTP>;
        st,syscon = <&syscfg 0x4>;
        snps,mixed-burst;
        snps,pbl = <2>;
        snps,en-tx-lpi-clockgating;
        snps,axi-config = <&stmmac_axi_config_0>;
        snps,tso;
        power-domains = <&pd_core>;
        status = "disabled";
 };

    &ethernet0 {
        status = "okay";
        pinctrl-0 = <&ethernet0_rgmii_pins_a>;
        pinctrl-1 = <&ethernet0_rgmii_pins_sleep_a>;
        pinctrl-names = "default", "sleep";
        phy-mode = "rgmii";
        max-speed = <1000>;
        phy-handle = <&phy0>;
        mdio0 {
                #address-cells = <1>;
                #size-cells = <0>;
                compatible = "snps,dwmac-mdio";
                phy0: ethernet-phy@0 {
                        reg = <0>;
                };
        };
    };

+ update stm32mp15-pinctrl.dtsi to add ETHCK pin in ethernet0_rgmii_pins_* node:<br>

For example:<STM32_PINMUX('G', 8, AF2)>, /* ETH_RGMII_ETHCK */

+ Need also to update TFA to generate 25Mhz clock (from PLL4P or PLL3Q):<br>

for example if PLL4P in ed1 board:
update fdts/stm32mp15xx-edx.dtsi  
 st,pkcs = <
  CLK_CKPER_HSE
  CLK_FMC_ACLK
  CLK_QSPI_ACLK
  '''- CLK_ETH_DISABLED'''
  '''+ CLK_ETH_PLL4P'''
 ...
  /* VCO = 600.0 MHz => P = 25, Q = 50, R = 50 */
    pll4: st,pll@3 {
      compatible = "st,stm32mp1-pll";
      reg = <3>;
      '''cfg = < 1 49 23 11 11 PQR(1,1,1) >;'''
  };

==== RGMII with Crystal on PHY, no 125Mhz from PHY ====

    ethernet0: ethernet@5800a000 {
        compatible = "st,stm32mp1-dwmac", "snps,dwmac-4.20a";
        reg = <0x5800a000 0x2000>;
        reg-names = "stmmaceth";
        interrupts-extended = <&intc GIC_SPI 61 IRQ_TYPE_LEVEL_HIGH>,<&intc GIC_SPI 62 IRQ_TYPE_LEVEL_HIGH>,<&exti 70 1>;
        interrupt-names = "macirq",
                          "eth_wake_irq",
                          "stm32_pwr_wakeup";
        clock-names = "stmmaceth",'''"eth-ck",'''
                      "mac-clk-tx",
                      "mac-clk-rx",
                      "ethstp";
        clocks = <&rcc ETHMAC>,
                 '''<&rcc ETHCK_K>,'''                <&rcc ETHTX>,<&rcc ETHRX>, "mac-clk-tx",
                       "mac-clk-rx",
                       "eth-ck",
                       "ethstp";
        clocks = <&rcc ETHMAC>,<&rcc ETHTX>,<&rcc ETHRX>,<&rcc ETHCK_K>,<&rcc ETHSTP>;
        st,syscon = <&syscfg 0x4>;
        snps,mixed-burst;
        snps,pbl = <2>;
        snps,en-tx-lpi-clockgating;
        '''st,eth_clk_sel;'''               {{highlight|/* In case of U-Boot */}} 
       or
        '''st,eth-clk-sel;'''               {{highlight|/* In case of Linux Kernel */}} ext-phyclk;'''snps,axi-config = <&stmmac_axi_config_0>;
        snps,tso;
        power-domains = <&pd_core>;
        status = "disabled";
 };

    &ethernet0 {
        status = "okay";
        pinctrl-0 = <&ethernet0_rgmii_pins_a>;
        pinctrl-1 = <&ethernet0_rgmii_pins_sleep_a>;
        pinctrl-names = "default", "sleep";
        phy-mode = "rgmii";
        max-speed = <1000>;
        phy-handle = <&phy0>;
        mdio0 {
                #address-cells = <1>;
                #size-cells = <0>;
                compatible = "snps,dwmac-mdio";
                phy0: ethernet-phy@0 {
                        reg = <0>;
                };
        };
    };

+ update stm32mp15-pinctrl.dtsi to delete CLK125 pin (also no need of ETHCK pin) in ethernet0_rgmii_pins_* node:<br>


+ Need also to update TFA to generate 125Mhz clock (from PLL4P or PLL3Q):<br>

for example if PLL4P in ed1 board:
update fdts/stm32mp15xx-edx.dtsi 
 st,pkcs = <
  CLK_CKPER_HSE
  CLK_FMC_ACLK
  CLK_QSPI_ACLK
  '''- CLK_ETH_DISABLED'''
  '''+ CLK_ETH_PLL4P'''
 ...
  /* VCO = 750.0 MHz => P = 125, Q = 62.5, R = 62.5 */
  pll4: st,pll@3 {
      compatible = "st,stm32mp1-pll";
      reg = <3>;
      '''cfg = < 3 124 5 11 11 PQR(1,1,1) >;'''
  };

== How to configure Ethernet using a PHY reset signal ==
Some Ethernet PHY have possibility to drive PHY reset using GPIO

    &ethernet0 {
        status = "okay";
        pinctrl-0 = <&ethernet0_rgmii_pins_a>;
        pinctrl-1 = <&ethernet0_rgmii_pins_sleep_a>;
        pinctrl-names = "default", "sleep";
        phy-mode = "rgmii";
        max-speed = <1000>;
        phy-handle = <&phy0>;
        mdio0 {
                #address-cells = <1>;
                #size-cells = <0>;
                compatible = "snps,dwmac-mdio";
                phy0: ethernet-phy@0 {
                        '''compatible = "ethernet-phy-id0007.c131";'''
                        '''reset-gpios = <&gpioa 4 GPIO_ACTIVE_LOW>'''  
                        reg = <0>;
                };
        };
    };
{{ReviewsComments|-- [[User:Olivier Kaps|Olivier Kaps]] ([[User talk:Olivier Kaps|talk]]) 18:08, 9 July 2021 (CEST)<br />Would it be possible to add a weak pullup/pulldown as an argument,}}

You need to find and replace value '''0007.c131''' corresponding to your Ethernet PHY: this can be found in datasheet of the Ethernet PHY, and find '''PHY Identifier 1''' and '''PHY Identifier 2''' registers.

== How to configure Ethernet using CubeMX ==
The [[STM32CubeMX]] tool can be used to configure the STM32MPU device and get the corresponding [[Device_tree#STM32|platform configuration device tree]] files.<br />

The STM32CubeMX may not support all the properties described in the above [[#DT bindings documentation|DT bindings documentation]] paragraph. If so, the tool inserts '''user sections''' in the generated device tree. These sections can then be edited to add some properties and they are preserved from one generation to another. Refer to [[STM32CubeMX]] user manual for further information.

==References==<references />

<noinclude>

[[Category:Device tree configuration]]
[[Category:Ethernet]]
{{PublicationRequestId | 10170 | 2019-01-02 | BrunoB}}
{{ArticleBasedOnModel | Peripheral or framework device tree configuration model}}</noinclude>
(24 intermediate revisions by 5 users not shown)
Line 1: Line 1:
  +
{{ClonedFrom | stm32mpu}}
 
== Article purpose ==
 
== Article purpose ==
 
This article explains how to configure the [[ETH internal peripheral|Ethernet]] when it is assigned to the Linux<sup>&reg;</sup> OS. In that case, it is controlled by the [[Ethernet overview|Ethernet framework]]
 
This article explains how to configure the [[ETH internal peripheral|Ethernet]] when it is assigned to the Linux<sup>&reg;</sup> OS. In that case, it is controlled by the [[Ethernet overview|Ethernet framework]]
Line 10: Line 11:
 
* "Generic" Ethernet device tree bindings <ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/net/stmmac.txt}}</ref>
 
* "Generic" Ethernet device tree bindings <ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/net/stmmac.txt}}</ref>
 
* specific STM32 ETH device tree bindings<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/net/stm32-dwmac.txt}}</ref>
 
* specific STM32 ETH device tree bindings<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/net/stm32-dwmac.txt}}</ref>
 
+
{{ReviewsComments|-- [[User:Olivier Kaps|Olivier Kaps]] ([[User talk:Olivier Kaps|talk]]) 18:08, 9 July 2021 (CEST)<br />Could be a good idea to update the link to yaml directly?
  +
(1) This file has moved to snps,dwmac.yaml -> Documentation/devicetree/bindings/net/snps%2Cdwmac.yaml
  +
<br>
  +
(2) Link does not exist in 5.10 kernel version -> linux/Documentation/devicetree/bindings/net/stm32-dwmac.yaml
  +
}}
 
== DT configuration ==
 
== DT configuration ==
 
This hardware description is a combination of the '''STM32 microprocessor''' device tree files (''.dtsi'' extension) and '''board''' device tree files (''.dts'' extension). See the [[Device tree]] for an explanation of the device tree file split.  
 
This hardware description is a combination of the '''STM32 microprocessor''' device tree files (''.dtsi'' extension) and '''board''' device tree files (''.dts'' extension). See the [[Device tree]] for an explanation of the device tree file split.  
Line 18: Line 23:
 
Ethernet peripheral nodes are located in stm32mp151.dtsi <ref>{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp151.dtsi | arch/arm/boot/dts/stm32mp151.dtsi}}, STM32MP151 device tree file</ref> file with a disabled status and some required properties such as:
 
Ethernet peripheral nodes are located in stm32mp151.dtsi <ref>{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp151.dtsi | arch/arm/boot/dts/stm32mp151.dtsi}}, STM32MP151 device tree file</ref> file with a disabled status and some required properties such as:
 
* Physical base address and size of the device register map
 
* Physical base address and size of the device register map
* STMMAC interrupts
+
* STMMAC interrupts {{ReviewsComments|-- [[User:Olivier Kaps|Olivier Kaps]] ([[User talk:Olivier Kaps|talk]]) 18:08, 9 July 2021 (CEST)<br />STM32 DWMAC interrupts ?}}
 
* stmmaceth clock and Rx, Tx clocks
 
* stmmaceth clock and Rx, Tx clocks
   
Line 33: Line 38:
 
      "mac-clk-tx",
 
      "mac-clk-tx",
 
      "mac-clk-rx",
 
      "mac-clk-rx",
  +
      "eth-ck",
 
      "ethstp";
 
      "ethstp";
 
clocks = <&rcc ETHMAC>,
 
clocks = <&rcc ETHMAC>,
 
<&rcc ETHTX>,
 
<&rcc ETHTX>,
 
<&rcc ETHRX>,
 
<&rcc ETHRX>,
  +
<&rcc ETHCK_K>,
 
<&rcc ETHSTP>;
 
<&rcc ETHSTP>;
 
st,syscon = <&syscfg 0x4>;
 
st,syscon = <&syscfg 0x4>;
Line 49: Line 56:
   
 
The required and optional properties are fully described in the [[Ethernet device tree configuration#DT bindings documentation|bindings files]].
 
The required and optional properties are fully described in the [[Ethernet device tree configuration#DT bindings documentation|bindings files]].
{{Warning|This device tree part is related to STM32 microprocessors. It must be kept as is, without being modified by the end-user.}}
+
{{Warning|This device tree part is related to STM32 microprocessors. It must be kept as is, without being modified by the end-user. These DT are same between U-Boot and kernel OS}}
  +
{{ReviewsComments|-- [[User:Emmanuel Combette|Emmanuel Combette]] ([[User talk:Emmanuel Combette|talk]]) 11:27, 9 July 2021 (CEST)<br />"These DT are same between U-Boot and kernel OS", can you move this warning in chapter above  3 DT configuration . Misleading in this chapter, as we can consider this is apply only at STM32 level  and not at board level}}
   
 
=== Ethernet DT configuration (board level) ===
 
=== Ethernet DT configuration (board level) ===
Line 81: Line 89:
 
</pre>
 
</pre>
   
=== DT configuration examples ===
+
=== DT configuration examples at board level ===
The example below shows how to configure and enable an Ethernet instance at board level:
+
The example below shows how to configure and enable an Ethernet instance
{{ReviewsComments|-- 10 oct ECO <br /> in all the example <&rcc SYSCFG>; is missinh on the clock list , isn't it ?}}
+
 
 
  &ethernet0 {
 
  &ethernet0 {
 
     status = "okay";                            {{highlight|/* enable ethernet0 */}}  
 
     status = "okay";                            {{highlight|/* enable ethernet0 */}}  
Line 119: Line 127:
 
                       "mac-clk-tx",
 
                       "mac-clk-tx",
 
                       "mac-clk-rx",
 
                       "mac-clk-rx",
  +
                      "eth-ck",
 
                       "ethstp";
 
                       "ethstp";
 
         clocks = <&rcc ETHMAC>,
 
         clocks = <&rcc ETHMAC>,
 
                 <&rcc ETHTX>,
 
                 <&rcc ETHTX>,
 
                 <&rcc ETHRX>,
 
                 <&rcc ETHRX>,
  +
                <&rcc ETHCK_K>,
 
                 <&rcc ETHSTP>;
 
                 <&rcc ETHSTP>;
 
         st,syscon = <&syscfg 0x4>;
 
         st,syscon = <&syscfg 0x4>;
Line 133: Line 143:
 
         status = "disabled";
 
         status = "disabled";
 
  };
 
  };
  +
{{ReviewsComments|-- [[User:Olivier Kaps|Olivier Kaps]] ([[User talk:Olivier Kaps|talk]]) 18:08, 9 July 2021 (CEST)<br /> Are we still at board level or is it a merge of the stm32mp151.dtsi file above?  if it is the case then the comment in 3.1 not to touch the stm32mp151.dtsi file should be removed }}
   
 
     &ethernet0 {
 
     &ethernet0 {
Line 152: Line 163:
 
     };
 
     };
   
==== RMII with 25MHz on ETH_CLK (no PHY Crystal), REF_CLK from PHY (Reference clock (standard RMII clock name) is provided by a RCC SoC internal clock) ====
+
==== RMII with 25MHz on ETH_CLK (no PHY Crystal), REF_CLK from PHY (Reference clock (standard RMII clock name) is provided by a PHY) ====
   
 
     ethernet0: ethernet@5800a000 {
 
     ethernet0: ethernet@5800a000 {
Line 165: Line 176:
 
                           "stm32_pwr_wakeup";
 
                           "stm32_pwr_wakeup";
 
         clock-names = "stmmaceth",
 
         clock-names = "stmmaceth",
                      '''"eth-ck",'''
+
                      "mac-clk-tx",
                      "mac-clk-tx",
+
                      "mac-clk-rx",
                      "mac-clk-rx",
+
                      "eth-ck",
                      "ethstp";
+
                      "ethstp";
 
         clocks = <&rcc ETHMAC>,
 
         clocks = <&rcc ETHMAC>,
                '''<&rcc ETHCK_K>,'''               
+
                      <&rcc ETHTX>,
                <&rcc ETHTX>,
+
                      <&rcc ETHRX>,
                <&rcc ETHRX>,
+
                      <&rcc ETHCK_K>,
                <&rcc ETHSTP>;
+
                      <&rcc ETHSTP>;
 
         st,syscon = <&syscfg 0x4>;
 
         st,syscon = <&syscfg 0x4>;
 
         snps,mixed-burst;
 
         snps,mixed-burst;
Line 237: Line 248:
 
                           "stm32_pwr_wakeup";
 
                           "stm32_pwr_wakeup";
 
         clock-names = "stmmaceth",
 
         clock-names = "stmmaceth",
                      '''"eth-ck",'''
+
                      "mac-clk-tx",
                      "mac-clk-tx",
+
                      "mac-clk-rx",
                      "mac-clk-rx",
+
                      "eth-ck",
                      "ethstp";
+
                      "ethstp";
 
         clocks = <&rcc ETHMAC>,
 
         clocks = <&rcc ETHMAC>,
                '''<&rcc ETHCK_K>,'''               
+
                      <&rcc ETHTX>,
                <&rcc ETHTX>,
+
                      <&rcc ETHRX>,
                <&rcc ETHRX>,
+
                      <&rcc ETHCK_K>,
                <&rcc ETHSTP>;
+
                      <&rcc ETHSTP>;
 
         st,syscon = <&syscfg 0x4>;
 
         st,syscon = <&syscfg 0x4>;
 
         snps,mixed-burst;
 
         snps,mixed-burst;
 
         snps,pbl = <2>;
 
         snps,pbl = <2>;
 
         snps,en-tx-lpi-clockgating;
 
         snps,en-tx-lpi-clockgating;
         '''st,eth_ref_clk_sel;'''              {{highlight|/* In case of U-Boot */}}
+
         '''st,ext-phyclk;'''
      or
 
        '''st,eth-ref-clk-sel;'''               {{highlight|/* In case of Linux Kernel */}}
 
 
         snps,axi-config = <&stmmac_axi_config_0>;
 
         snps,axi-config = <&stmmac_axi_config_0>;
 
         snps,tso;
 
         snps,tso;
Line 311: Line 320:
 
                           "stm32_pwr_wakeup";
 
                           "stm32_pwr_wakeup";
 
         clock-names = "stmmaceth",
 
         clock-names = "stmmaceth",
                      "mac-clk-tx",
+
                      "mac-clk-tx",
                      "mac-clk-rx",
+
                      "mac-clk-rx",
                      "ethstp";
+
                      "eth-ck",
         clocks = <&rcc ETHMAC>,            
+
                      "ethstp";
                <&rcc ETHTX>,
+
         clocks = <&rcc ETHMAC>,
                <&rcc ETHRX>,
+
                      <&rcc ETHTX>,
                <&rcc ETHSTP>;
+
                      <&rcc ETHRX>,
  +
                      <&rcc ETHCK_K>,
  +
                      <&rcc ETHSTP>;
 
         st,syscon = <&syscfg 0x4>;
 
         st,syscon = <&syscfg 0x4>;
 
         snps,mixed-burst;
 
         snps,mixed-burst;
Line 359: Line 370:
 
                           "stm32_pwr_wakeup";
 
                           "stm32_pwr_wakeup";
 
         clock-names = "stmmaceth",
 
         clock-names = "stmmaceth",
                      '''"eth-ck",'''
+
                      "mac-clk-tx",
                      "mac-clk-tx",
+
                      "mac-clk-rx",
                      "mac-clk-rx",
+
                      "eth-ck",
                      "ethstp";
+
                      "ethstp";
 
         clocks = <&rcc ETHMAC>,
 
         clocks = <&rcc ETHMAC>,
                '''<&rcc ETHCK_K>,'''               
+
                      <&rcc ETHTX>,
                <&rcc ETHTX>,
+
                      <&rcc ETHRX>,
                <&rcc ETHRX>,
+
                      <&rcc ETHCK_K>,
                <&rcc ETHSTP>;
+
                      <&rcc ETHSTP>;
 
         st,syscon = <&syscfg 0x4>;
 
         st,syscon = <&syscfg 0x4>;
 
         snps,mixed-burst;
 
         snps,mixed-burst;
Line 430: Line 441:
 
                           "stm32_pwr_wakeup";
 
                           "stm32_pwr_wakeup";
 
         clock-names = "stmmaceth",
 
         clock-names = "stmmaceth",
                      '''"eth-ck",'''
+
                      "mac-clk-tx",
                      "mac-clk-tx",
+
                      "mac-clk-rx",
                      "mac-clk-rx",
+
                      "eth-ck",
                      "ethstp";
+
                      "ethstp";
 
         clocks = <&rcc ETHMAC>,
 
         clocks = <&rcc ETHMAC>,
                '''<&rcc ETHCK_K>,'''               
+
                      <&rcc ETHTX>,
                <&rcc ETHTX>,
+
                      <&rcc ETHRX>,
                <&rcc ETHRX>,
+
                      <&rcc ETHCK_K>,
                <&rcc ETHSTP>;
+
                      <&rcc ETHSTP>;
 
         st,syscon = <&syscfg 0x4>;
 
         st,syscon = <&syscfg 0x4>;
 
         snps,mixed-burst;
 
         snps,mixed-burst;
 
         snps,pbl = <2>;
 
         snps,pbl = <2>;
 
         snps,en-tx-lpi-clockgating;
 
         snps,en-tx-lpi-clockgating;
         '''st,eth_clk_sel;'''              {{highlight|/* In case of U-Boot */}}
+
         '''st,ext-phyclk;'''
      or
 
        '''st,eth-clk-sel;'''               {{highlight|/* In case of Linux Kernel */}}
 
 
         snps,axi-config = <&stmmac_axi_config_0>;
 
         snps,axi-config = <&stmmac_axi_config_0>;
 
         snps,tso;
 
         snps,tso;
Line 488: Line 497:
 
       '''cfg = < 3 124 5 11 11 PQR(1,1,1) >;'''
 
       '''cfg = < 3 124 5 11 11 PQR(1,1,1) >;'''
 
   };
 
   };
  +
  +
== How to configure a PHY reset signal ==
  +
Some Ethernet PHY have possibility to drive PHY reset using GPIO
  +
  +
    &ethernet0 {
  +
        status = "okay";
  +
        pinctrl-0 = <&ethernet0_rgmii_pins_a>;
  +
        pinctrl-1 = <&ethernet0_rgmii_pins_sleep_a>;
  +
        pinctrl-names = "default", "sleep";
  +
        phy-mode = "rgmii";
  +
        max-speed = <1000>;
  +
        phy-handle = <&phy0>;
  +
        mdio0 {
  +
                #address-cells = <1>;
  +
                #size-cells = <0>;
  +
                compatible = "snps,dwmac-mdio";
  +
                phy0: ethernet-phy@0 {
  +
                        '''compatible = "ethernet-phy-id0007.c131";'''
  +
                        '''reset-gpios = <&gpioa 4 GPIO_ACTIVE_LOW>''' 
  +
                        reg = <0>;
  +
                };
  +
        };
  +
    };
  +
{{ReviewsComments|-- [[User:Olivier Kaps|Olivier Kaps]] ([[User talk:Olivier Kaps|talk]]) 18:08, 9 July 2021 (CEST)<br />Would it be possible to add a weak pullup/pulldown as an argument,}}
  +
  +
You need to find and replace value '''0007.c131''' corresponding to your Ethernet PHY: this can be found in datasheet of the Ethernet PHY, and find '''PHY Identifier 1''' and '''PHY Identifier 2''' registers.
   
 
== How to configure Ethernet using CubeMX ==
 
== How to configure Ethernet using CubeMX ==