This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C129DNCPDT with external phy through MII?

Other Parts Discussed in Thread: TM4C1294NCPDT, TM4C129DNCPDT, TM4C129XNCZAD, TIDM-TM4C129XSDRAM

Hi all,

   I'm using the tm4c129dncpdt in my project.It is connected to KSZ8765CLX trough MII interface.I once use the TM4C1294NCPDT in my project.The 1294 chip has internal phy in it and have ti-rtos example software support.But how can I get the ethernet example for the 129D chip?How can I developement the chip that has no phy in it?Can I use the NDK products in the tirtos_tivac_2_16_01_14 software and how?I don't have any idea of it.

  • Hello Nancy

    The next TivaWare release 2.1.4 is having the updates for integrating via MII interface an external PHY.

    However to get you started, the main changes that must be made are in the lwIP porting file under third_party/lwip-1.4.1/ports/ and in lwiplib.c/.h in utils directory of TivaWare to start with.
  • Hi Amit,

    I'm actually working on a similar project as Nancy, in that we're trying to use an external PHY.  I was using the RTOS project as a start and I was looking at the lwipopts.h file where I would need to make changes to use an external PHY instead of an internal one.  The two defines that I see that I need to change are EMAC_PHY_CONFIG and PHY_PHYS_ADDR.  Can you let me know if there are any additional items that needs to be modified in order to work with an external PHY?  Or do you have an expected release date of the TivaWare 2.1.4?

    Thanks!

  • Hello SL

    The TivaWare 2.1.4 is planned by end of Dec-mid of Jan time frame (considering holidays are around the corner). There are quite some changes that need to be done. If you can start the same, I can help guide you and Nancy.
  • Hi Amit,

    Unfortunately, we can't wait until the 2.1.4 is release so any guidance you can provide would be greatly appreciated.  As I mentioned earlier, I am changing the lwipopts.h where the changes are:

    // Original
    #define EMAC_PHY_CONFIG (EMAC_PHY_TYPE_INTERNAL | EMAC_PHY_INT_MDIX_EN | EMAC_PHY_AN_100B_T_FULL_DUPLEX)
    #define PHY_PHYS_ADDR      0
    
    // Change to
    #define EMAC_PHY_CONFIG (EMAC_PHY_TYPE_EXTERNAL | EMAC_PHY_INT_MDIX_EN | EMAC_PHY_AN_100B_T_FULL_DUPLEX)
    #define PHY_PHYS_ADDR      3

    But you mentioned other files that also need to be changed, can you provide which files they are and I can take an initial look to see if I can determine what needs to be changed in those files.

    Thanks!

  • Hello SL,

    In the file utils/lwiplib.c

    Replace Line 451:
    bHaveLink = MAP_EMACPHYRead(EMAC0_BASE, 0, EPHY_BMSR) & EPHY_BMSR_LINKSTAT;

    with
    bHaveLink = MAP_EMACPHYRead(EMAC0_BASE, PHY_PHYS_ADDR, EPHY_BMSR) &
    EPHY_BMSR_LINKSTAT;

    Replace Line 870:
    MAP_EMACPHYConfigSet(EMAC0_BASE, EMAC_PHY_CONFIG);

    with
    EMACPHYConfigSet(EMAC0_BASE, EMAC_PHY_CONFIG);

    in the file third_party/lwip-1.4.1/ports/tiva-tm4c129/netif/tiva-tm4c129.c

    Add the following lines at line 319 after InitDMADescriptors function call


    #if defined(EMAC_PHY_IS_EXT_MII) || defined(EMAC_PHY_IS_EXT_RMII)
    /* If PHY is external then reset the PHY before configuring it */
    EMACPHYWrite(EMAC0_BASE, PHY_PHYS_ADDR, EPHY_BMCR,
    EPHY_BMCR_MIIRESET);

    while((EMACPHYRead(EMAC0_BASE, PHY_PHYS_ADDR, EPHY_BMCR) &
    EPHY_BMCR_MIIRESET) == EPHY_BMCR_MIIRESET);
    #endif

    and replace
    EMACPHYWrite(EMAC0_BASE, PHY_PHYS_ADDR, EPHY_BMCR, (EPHY_BMCR_ANEN |
    EPHY_BMCR_RESTARTAN));

    with
    #if defined(EMAC_PHY_IS_EXT_MII) || defined(EMAC_PHY_IS_EXT_RMII)
    EMACPHYWrite(EMAC0_BASE, PHY_PHYS_ADDR, EPHY_BMCR, (EPHY_BMCR_SPEED |
    EPHY_BMCR_DUPLEXM | EPHY_BMCR_ANEN | EPHY_BMCR_RESTARTAN));
    #else
    EMACPHYWrite(EMAC0_BASE, PHY_PHYS_ADDR, EPHY_BMCR, (EPHY_BMCR_ANEN |
    EPHY_BMCR_RESTARTAN));
    #endif

    Do make sure to add the define EMAC_PHY_IS_EXT_MII in the CCS Project Settings. These changes will make sure that when 2.1.4 release comes out, the software will still work (though there are more changes)
  • Hi Amit,

    Thanks for that. You mention that there are more changes, but will the changes above be all that's needed for me to start communicating with the external PHY?

    Thanks!
  • Hello SL

    The changes mentioned above should help you make it work with the external PHY as seen by TM4C129x devices as long as the connections are correct and the external PHY does not expect any special feature that may be bootstrapped to it.
  • Hi Amit,

    Ok, perfect. We'll give those code changes a try.
  • Hi Amit,

    We've made the changes above and we're still not able to establish a link. I've verified that we can communicate with the PHY at the correct address. Is there something in the EMAC registers or somewhere else that I can check to ensure that the uC and the PHY are indeed linking?

    Thanks!
  • Hello SL,

    The lwiopts.h should have the following as the define

    #define EMAC_PHY_CONFIG EMAC_PHY_TYPE_EXTERNAL_MII
  • Hi Amit,

    I have this in the lwipopts.h

    #define EMAC_PHY_CONFIG (EMAC_PHY_TYPE_EXTERNAL_RMII | EMAC_PHY_INT_MDIX_EN | EMAC_PHY_AN_100B_T_FULL_DUPLEX)

    We are using a RMII instead of a MII. Should I remove the other options, MDIX and DUPLEX?

    Thanks.
  • Hello SL,

    I have only tested it with MII and not RMII, so I think it should be just

    #define EMAC_PHY_CONFIG EMAC_PHY_TYPE_EXTERNAL_RMI
  • Hi Amit,

    Ok, we'll try this. I'm also looking at the datasheet and it looks like there's some additional items that might need to change when using a RMII instead of a MII so I'll go through these and see if the changes you mention above covers the changes mention in the datasheet or if those are additional changes that I need to make.

    Thanks!
  • Hello SL

    Yes, it could be. We have tested the MII with a TI external PHY so I am very sure that the settings provided should work for MII.
  • Hi Amit,

    It looks like we have things configured correctly to use RMII except for one item. In the datasheet, it mentions that the ECEXT and CLKEN bit in the Ethernet Clock Configuration (EMACCC) register needs to be set. However, I can't seem to find anything on the ECEXT bit. I search the whole document and I can't find any other reference of the ECEXT bit except on this page, which is page 1653 of the Tiva TM4C129XNCZAD Microcontroller datasheet. I took a look at the EMACCC register and it doesn't have a ECEXT bit. Can you provide any additional detail about the ECEXT bit?

    Thanks.
  • Hello SL,

    Only CLKEN bit is required. The ECEXT is incorrectly documented (I can double check the same)
  • Hi Amit,

    In that case, it looks like everything is setup properly. Do you know if the uC will work with a Micrel RMII PHY? Just as a reference, we're using the Micrel KSZ8091RNACA PHY.

    Thanks.
  • Hello SL

    I have not worked with the Micrel KSZ8091RNACA PHY over the RMII interface. As I said, this post was about MII and that I have tested with a TI DP83822 PHY and it works with the software updates. So as to debug the issue, can you check

    1. The pin mapping for the TM4C device
    2. Share the pin connectivity of the external PHY with the TM4C device.
  • Hi Amit,

    I was looking at the DK-TM4C129X Development Kit and it mentions that it supports a booster pack with external MII/RMII, do you happen to know what booster pack that is? We have the development kit and we might be interested in getting that booster pack to see if we can get an external RMII working with the development kit.

    Thanks.
  • Hello SL,

    No. There is no mention that there is a boosterpack for external PHY exists in the User Guide of DK-TM4C129x. Can you please point me to which page-para in the document states the same.
  • Hi Amit,

    Looks like I misread it.  It stated that there's available I/O expansion interface headers for external PHY.

    Thanks.

  • Hello SL,

    Exactly. The expansion header is where the SDRAM board from TIDM-TM4C129XSDRAM is connected and similar can be done for ULPI (USBHS) and external PHY.
  • Hello,

    I guess I am working on the same type of issue. I am trying to interface an external PHY to the TM4C129X dev board. I can connect using MII, but when I configure RMII, I crash whenever I hit this line in lwiplib.c:

    //
    // Initialize the MAC and set the DMA mode.
    //
    MAP_EMACInit(EMAC0_BASE, ui32SysClkHz, EMAC_BCONFIG_MIXED_BURST | EMAC_BCONFIG_PRIORITY_FIXED, 4, 4, 0);

    I am using a DP83822 for 100FX support, but a lot of my registers were messed up on reset because the Tiva was holding the bootstrap lines on the PHY in an unknown state. I manually write all the regs to the DP83822 and everything appears to be setup correctly on my PHY. The issue is that the lwip examples and RMII examples dont seem to run.

    Are there any Tiva and RMII examples that are verified and tested with real hardware?

    -Joe
  • Hello Joe,

    I have used DP83822 with MII interface and the Boot Strap pins were not an issue. Did you make the changes that have been mentioned in the post earlier for lwiplib.c, port file and lwipopts.h which ought to be similar for RMII?
  • I have made the changes mentioned in the earlier post. Like you, I have the DP83822 working with the Tiva with MII, but RMII seems to be what I and the original thread owner are seeking. Should we configure our PHYs in master or slave mode? Does the Tiva example software expect the 50MHz ref clk on the refclk pin? I am using RXD3 from the DP83822 to send that 50MHz signal.

    -Joe
  • Hello Joe,

    The MAC expects the 50MHz clock on the REFCLK pin and not the Software. I am not sure about the Master/Slave mode as I did never do any configuration and relied on the boot strap method to load the registers for most of the operation.

    I will need to rebuild the setup I had to test the RMII mode.
  • Ok. Great. We have 30+ Tivas in our system with 30+ DP83822s and RMII is something that I think many are interested. A working RMII example would be great.

    -Joe
  • Hi Amit,

    Just to provide some additional information here, I was able to establish a link between the PHY and a switch.  I had to make one more change in the tiva-tm4c129.c file.  When i added the #if defined (EMAC_PHY_IS_EXT) on line 321 after the InitDMADescriptiors.  I also had to make sure that I don't execute the code for the PHY interrupts, so that portion of the code became:

    #if defined(EMAC_PHY_IS_EXT_MII) || defined(EMAC_PHY_IS_EXT_RMII)
      /* If PHY is external then reset the PHY before configuring it */
      EMACPHYWrite(EMAC0_BASE, PHY_PHYS_ADDR, EPHY_BMCR, EPHY_BMCR_MIIRESET);
    
      while((EMACPHYRead(EMAC0_BASE, PHY_PHYS_ADDR, EPHY_BMCR) & EPHY_BMCR_MIIRESET) == EPHY_BMCR_MIIRESET);
    #else
      /* Clear any stray PHY interrupts that may be set. */
      ui16Val = EMACPHYRead(EMAC0_BASE, PHY_PHYS_ADDR, EPHY_MISR1);
      ui16Val = EMACPHYRead(EMAC0_BASE, PHY_PHYS_ADDR, EPHY_MISR2);
    
      /* Configure and enable the link status change interrupt in the PHY. */
      ui16Val = EMACPHYRead(EMAC0_BASE, PHY_PHYS_ADDR, EPHY_SCR);
      ui16Val |= (EPHY_SCR_INTEN_EXT | EPHY_SCR_INTOE_EXT);
      EMACPHYWrite(EMAC0_BASE, PHY_PHYS_ADDR, EPHY_SCR, ui16Val);
      EMACPHYWrite(EMAC0_BASE, PHY_PHYS_ADDR, EPHY_MISR1, (EPHY_MISR1_LINKSTATEN |
                   EPHY_MISR1_SPEEDEN | EPHY_MISR1_DUPLEXMEN | EPHY_MISR1_ANCEN));
    
      /* Read the PHY interrupt status to clear any stray events. */
      ui16Val = EMACPHYRead(EMAC0_BASE, PHY_PHYS_ADDR, EPHY_MISR1);
    #endif

    This is so because the Micrel PHY that we're using doesn't have register 0x12 as defined by EPHY_MISR1.  It's a reserved register in the Micrel PHY.  Once I did this, then I was able to establish a link.  However, I'm still not able to ping the device and I wonder if it has something to do with this or something along the line of interrupts.  Can you provide any guidance on this or should it just work if I'm able to establish a link?  If it should just work, then I'll look into the signals to see if we happen to cross the lines.

    Thanks!

  • Hello SL

    Well that was not the case with DP83822 which we have been using. So yes, any custom changes needs to be done by the application developer.

    How is the interrupt connected from the PHY to the TM4C device, its polarity?
  • Hi Amit,

    Yes, I figured there was something else with configuration that I was missing so that's why I started to dig a little deeper into the whole initialization process and found that, so no problem there. I understand that custom changes will have to be done.

    As for the interrupt, we actually don't connect the interrupt from the PHY to the TM4C device. We figure that the interrupt was mainly only used for waking up the uC if we used that option. But is this something that's required? We saw on the datasheet that the interrupt is optional. If we need this, then we can connect it.

    Thanks!
  • Hi Amit,

    I have one question with regards to the EMACTXCNTGB and EMACRXCNTGB. When I ping the device, shouldn't these counters increase if the packet was received by the uC?

    Thanks!
  • Hello SL

    RX packet will increment as it gets packets over the network. TX count will increment only when requested by the lwIP stack.
  • Hi Amit,

    In debugging the issue, we tried a different route in that we had the uC send a UDP broadcast message to a connecting computer. We see the activity LED on the PHY so we see that the uC is trying to send data out but we're not seeing the data on the computer. We used WireShark to see if we received anything on the Ethernet connection. In looking at the signal, it looks like the clock might not be correct. Is it possible for you to let me know which registers I should look at to ensure that the MAC is set correctly? I've gone through the data sheet multiple times now and I can't seem to find anything that appears to be incorrectly set.

    Also, were you working on getting a setup with an external RMII? I know that it won't be the exact same setup that I have here but at least it would verify that the TM4C129X works with an external RMII.

    Thanks!
  • Hello SL

    The clock registers are setup based on the interface configuration and the EMACCC register should be a sufficient criteria to visualize the same. The DP83822 board I have is designed for MII interface. I have to find the layout plot so that I know which traces to cut to set up the RMII mode. So that is going to take some time.
  • Hi Joseph,
    I'm working with the TM4C129DNCPDT MII interface. I just want to test the emac and phy initialization.So I only test : lwIPInit(g_ui32SysClock, pui8MACArray, 0, 0, 0, IPADDR_USE_DHCP).But the code block at EMACPHYConfigSet() or EMACInit().The resoult seems like your woking with your RGMII interface.
    You said that can connect using MII.Could kindly share your code?So I can solve my proble more easily.And I want plant the ethertnet hardware driver into my TI-rtos project.I connect the tm4c with external switch chip though its external MII interface.
    Thanks a lot!
  • Hi Amit,
    I'm working with the tm4c129dncpdt external MII interface debug again. I use the enet_liwp example.
    I have changed EMAC_PHY_CONFIG to:(EMAC_PHY_TYPE_EXTERNAL_MII | EMAC_PHY_INT_MDIX_EN |EMAC_PHY_AN_100B_T_FULL_DUPLEX).
    When I run the program : lwIPInit(g_ui32SysClock, pui8MACArray, 0, 0, 0, IPADDR_USE_DHCP),the code block at EMACPHYConfigSet() or EMACInit().Could kindly give me some suggestions to solve the problem?
  • Hello Amit

    I have made the changes in various posts of yours regarding RMII on the TM4C and the DP83822. I have been using this combo successfully on our custom hardware. I am attempting to get the TM4C129X development board working with the DP83822 development board with RMII and none of these examples and posts seem to work. This is the combination that I used to get the MII interface working, but I would much rather RMII. Have you had time to test RMII with this combination? I am waiting for the new TivaWare to be released, but I'm hoping to get RMII working before then if possible. 

    -Joe

  • Hi Amit,

    Does current TivaWare release 2.1.4 have any update for integrating via MII interface an external PHY ?

    Thanks and Regards,

    Dileep

  • Dileep,

    The current revision works just fine with MII with no editing besides enabling the pin muxing for the MII interface. I also have it working with RMII if you need any assistance with that. 

    -Joe

  • Hello Dileep

    Yes. The just released 2.1.4 has the code integrated for MII interface for an external PHY. There are some other changes as well. However for using MII interface you need to place the define EMAC_PHY_IS_EXT_MII during compilation.
  • Hi I am using tm4cdncpdt and wanted to interface that with knz8081rnb. I have downloaded the SW-TM4C-2.1.4.178 in that just wanted to check with interfacing of external phy (RMII). So used the enet_uip project for my reference.But the code is getting in looped in EMACPHYConfigSet.
    SW-TM4C-2.1.4.178\examples\boards\dk-tm4c129x\enet_uip.
  • Hello Harish

    The update for external PHY has been provided in the lwIP stack and not in uIP stack.
  • Hi Amit
    I have added the below in pinout.c of enet_lwip project
    ROM_GPIOPinConfigure(GPIO_PG3_EN0TXEN);
    ROM_GPIOPinConfigure(GPIO_PG5_EN0TXD1);
    ROM_GPIOPinConfigure(GPIO_PG4_EN0TXD0);
    ROM_GPIOPinConfigure(GPIO_PG7_EN0RXDV);
    ROM_GPIOPinConfigure(GPIO_PQ5_EN0RXD0);
    ROM_GPIOPinConfigure(GPIO_PQ6_EN0RXD1);
    ROM_GPIOPinConfigure(GPIO_PK4_EN0INTRN);
    ROM_GPIOPinConfigure(GPIO_PF2_EN0MDC);
    ROM_GPIOPinConfigure(GPIO_PF3_EN0MDIO);
    ROM_GPIOPinConfigure(GPIO_PM4_EN0RREF_CLK);


    ROM_GPIOPinConfigure(GPIO_PF1_EN0LED2);
    ROM_GPIOPinConfigure(GPIO_PK4_EN0LED0);
    ROM_GPIOPinConfigure(GPIO_PK6_EN0LED1);
    GPIOPinTypeEthernetLED(GPIO_PORTF_BASE, GPIO_PIN_1);
    GPIOPinTypeEthernetLED(GPIO_PORTK_BASE, GPIO_PIN_4);
    GPIOPinTypeEthernetLED(GPIO_PORTK_BASE, GPIO_PIN_6);
    and after this I have defined the macro EMAC_PHY_TYPE_EXTERNAL_RMII..
    The code is getting looped in EMACPHYConfigSet function.
  • Selecting and enabling the external clock from the RMII PHY is failing in EMACPhyConfigSet.

    When I use EMACPHYConfigSet(EMAC0_BASE, EMAC_PHY_CONFIG);

    where EMAC_PHY_CONFIG is defined as EMAC_PHY_TYPE_EXTERNAL_RMII

    Regards

    Harish

  • Joseph,

    Can you assist me in interfacing external PHY with RMII.

    1. Does external PHY starts giving 50MHz ref_clk to MAC on reset or we have to configure any PHY regs to generate 50MHz. We have connected 25MHz to PHY.

    2. I have probed MDIO MDC lines. I am able to capture data. PHY responds with 16 bits data when in read PHY regs with API EMACPHYREAD, but return value of this API is always zero for any register read.

    Please let me know the changes required, I am refering to enet_lwip project in TivaWare-2.1.4.178

    Thanks and Regards,
    Dileep
  • Hello Dileep,

    You will need to give the external PHY and the Tiva a 50MHz reference clock if you are using RMII. In my particular case, I prototyped this with a function generator. I am using the DP83822. 

    Once you connect all the RMII signal pins, you will need to enable them in the pinmux file for your project. After that, in lwipopts.h, you will need to set the #define to use external phy rmii instead of the internal phy. Those are basically the only changes needed to get the external phy working.

    //#define EMAC_PHY_CONFIG (EMAC_PHY_TYPE_INTERNAL | EMAC_PHY_INT_MDIX_EN | \
    // EMAC_PHY_AN_100B_T_FULL_DUPLEX)
    #define EMAC_PHY_CONFIG EMAC_PHY_TYPE_EXTERNAL_RMII

    The return value will be a zero because you probably dont have the phy address correct. I would suggest changing the address in lwipopts.h to the correct address of your phy. 

    #define PHY_PHYS_ADDR      0

    If you need help, with the address, let me know. You could also run through a loop to find it. 

              int phy_reg;

    for (i = 0; i < 31; i++)
    {
         phy_reg = EMACPHYRead(EMAC0_BASE, i, EPHY_BMCR);
    }

    if phy_reg is not 0xFFFF or 0x0000, you probably have a phy on that address. It is not a robust method to detect a phy, but it might help you find what you are looking for. I suggest reading the phy datasheet and finding the correct phy address. It most likely will have address pins. 

    -Joe

  • Hello Joseph,

    Thank you for your input. After connecting 50Mhz i am able configure MAC and read all EXT PHY registers. But still Link is down and no IP is assigned. Please help in resolving this issue.

    Best Regards,

    Dileep