Skip to main content
Visitor II
February 17, 2020
Solved

STM32F7 MAC-to-MAC possible? With HAL?

  • February 17, 2020
  • 3 replies
  • 3943 views

The STM32F7 supports Ethernet with MAC (and DMA), according to doc en.DM00224583.pdf.

I try to connect it to a KSZ9896 (ethernet switch) that provides a direct MAC interface in RMII.

The KSZ provides configuration bits similar to the STM32 ETH_MACxxx.

I wonder if the connection between the 2 RMIIs needs any PHY.

STM32 MAC <--> KSZ MAC
OR
STM32 MAC <--> PHY <--> KSZ MAC
OR
STM32 MAC <--> PHY1 <--> PHY2 <--> KSZ MAC
  • Theoretically, does a MAC-to-MAC connection requires any PHY? 0, 1 or 2? (my guess: 0)
  • Does the STM32F7 specifically requires any PHY with its MAC layer?
  • Is it possible to customize the HAL to bypass the PHY related code, and use only the MAC related code?

Thanks in advance for your comments and answers!

    This topic has been closed for replies.
    Best answer by OFAUR.1763

    I've a better answer !

    In the code generated by the cube, there is a

    ETH_HandleTypeDef heth;

    In the code, you need to set the adress of the PHY :

    heth.Init.PhyAddress = 0; // or 1, or...

    There is a default values for DP83848, for example, but you need to use the one corresponding to your PHY.

    LAZY TIP: if you're lazy, try 0 and 1, there are usually the good guess :face_with_tears_of_joy:

    BUT there is more for the KSZ9896C !

    You don't have one PHY but... 5 !

    According to the doc, with PhyAddress=0, you configure general settings.

    If you want to configure all the PHY, you need to set the correct PhyAddress before using HAL_ETH_(Read|Write)Register()

    Here an example of code for setting all the PHY to 100Mb/s full-duplex :

     for(unsigned int i=1; i<=5; i++) // for all ports
     {
    	 // Needed, as this the base for PHY access in HAL_ETH_Read/Write
    	 heth.Init.PhyAddress = (uint16_t)i;
     
     // all zeroes, except for 13 (100Mb/s) and 8 (full duplex)
    	 HAL_ETH_WritePHYRegister(&heth, 0x0100, 0x2100);
    }

    With this setup, perhaps you can get the LINKED_STATUS and AUTONEGO_COMPLETE for the PHY you need.

    Hope this helps !

    3 replies

    Visitor II
    February 18, 2020

    Auto-answer, resolved !

    MAC-to-MAC is possible without PHY on a STM32F7.

    You need to customize the HAL to bypass the status bits that can block the startup.

    Usually it's code like this one :

     do
     {
     HAL_ETH_ReadPHYRegister(heth, PHY_BSR, &phyreg);
     phyreg |= PHY_LINKED_STATUS; // I ADDED THIS LINE TO BY PASS THE CHECK
     
     /* SOME CODE */
     } while (((phyreg & PHY_LINKED_STATUS) != PHY_LINKED_STATUS));

    As you can, I forced the bit to be set.

    You need to do this for the PHY_LINKED_STATUS, and for the PHY_AUTONEGO_COMPLETE.

    Depending on your setup, you might need to "disable" HAL_ETH_(Read|Write)PHYRegister().

    Hope this will help someone!

    Visitor II
    March 11, 2020

    Thanks for sharing! I have almost exactly the same problem. Using an KSZ9893 and F767ZI. It is really a relief to see that you managed to connect without any extra phys. I tried to bypass the autonegotiation but my CPU doesn't write a single bit on the ETH_TXDx anyways. The ETH_RXDx is showing on the oscilloscope and I have a 50MHz clock from the switch. Did you do any other things to get it started? Thanks!

    Visitor II
    September 10, 2020

    No, I only modified the 2 parts for the LINKED_STATUS and the AUTONEGO_COMPLETE.

    There is also this : "you might need to "disable" HAL_ETH_(Read|Write)PHYRegister()."

    Graduate II
    May 22, 2021
    OFAUR.1763AuthorAnswer
    Visitor II
    July 2, 2021

    I've a better answer !

    In the code generated by the cube, there is a

    ETH_HandleTypeDef heth;

    In the code, you need to set the adress of the PHY :

    heth.Init.PhyAddress = 0; // or 1, or...

    There is a default values for DP83848, for example, but you need to use the one corresponding to your PHY.

    LAZY TIP: if you're lazy, try 0 and 1, there are usually the good guess :face_with_tears_of_joy:

    BUT there is more for the KSZ9896C !

    You don't have one PHY but... 5 !

    According to the doc, with PhyAddress=0, you configure general settings.

    If you want to configure all the PHY, you need to set the correct PhyAddress before using HAL_ETH_(Read|Write)Register()

    Here an example of code for setting all the PHY to 100Mb/s full-duplex :

     for(unsigned int i=1; i<=5; i++) // for all ports
     {
    	 // Needed, as this the base for PHY access in HAL_ETH_Read/Write
    	 heth.Init.PhyAddress = (uint16_t)i;
     
     // all zeroes, except for 13 (100Mb/s) and 8 (full duplex)
    	 HAL_ETH_WritePHYRegister(&heth, 0x0100, 0x2100);
    }

    With this setup, perhaps you can get the LINKED_STATUS and AUTONEGO_COMPLETE for the PHY you need.

    Hope this helps !