Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed the week of November 23.

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.

TMS320F28386D: driverlib_cm Ethernet issues

Part Number: TMS320F28386D
Other Parts Discussed in Thread: C2000WARE, , TMS320F28388D, TMDSCNCD28388D

Dear support team,

Since we have some troubles getting the Ethernet interface up and running on our prototype board, I had to deep dive into the features of the Ethernet driver library for the TMS230F28388x. To my surprise I did not only encounter unimplemented functions, but also some straight bugs, that are apparently already present for many years.

I will discuss the issues in separate sections, all referring to the same:

  • used driver software: C2000Ware_26_01_00_00
  • used Cortex-M4 (CM) application: enet_lwip example
  • prototype board: TMS320F28386D EMAC connected in RMII mode to an ADIN1200 PHY
  • demo board: TMDSCNCD28388D (TMS320F28388D connected in MII mode to an DP83822 PHY)

Note that we have the enet_lwip example running on the demo board and are debugging the prototype board (hardware), but the issues mentioned are only driverlib_cm related.

MDIO Clause 45 support (incomplete)

The Ethernet_configureMDIO() function offers the option to select Clause 45 MDIO communication with the PHY. However, the API has no function to specify the Device Address that is required for Clause 45 communication, in addition to the register address. For reading and writing the "Clause 45 registers" of the ADIN1200 it is therefore useless to select Clause 45 communication mode and you have to fallback on the Clause 22 access mode for the extended registers of the PHY. Or write your own driver, since the EMAC of the microcontroller does have the Clause 45 support.

MAC_MDIO_Address register overwrites (bug)

The Ethernet_configureMDIO() and Ethernet_configurePHYAddress() functions both set fields of the MAC_MDIO_Address register. Unfortunately, both functions do this by assignment rather than bitmask operations. This means that the settings of the one are reset to zero by the other. This needs to be fixed.

Ethernet_getStatistics() (bug?)

The Ethernet_getStatistics() function implementation seems to assume that the counter registers in the EMAC can be reset to zero by writing the read value to the register, as a kind of acknowledge. However, according to the spruii0f.pdf TRM these registers are read-only, and when stepping through this function, one sees no change to the register by the write action. The result is that each time you call Ethernet_getStatistics() without a reset of the whole EMAC, all values are counted multiple times. It depends of course of your product requirements if this is the behaviour you want. To me, this function is currently implementing the https://en.wikipedia.org/wiki/Lies,_damned_lies,_and_statistics behaviour.

  • Hi, 

    Thank you for the Thread. I acknowledge that these issues are Valid.

    Work for these bug fix is going on and the patch can be given within a day.

  • diff --git a/driverlib_cm/ethernet.c b/driverlib_cm/ethernet.c
    index 0f64d39..7c218ff 100644
    --- a/driverlib_cm/ethernet.c
    +++ b/driverlib_cm/ethernet.c
    @@ -1731,9 +1731,11 @@ uint32_t Ethernet_getStatistics(Ethernet_Handle hEMAC,
         statAddrPtr = (uint32_t *)statisticsPtr;
         for (i = 0U; i < ETHERNET_NUMSTATS; i++)
         {
    +        /* Read the register (Reset on read is Enabled on init) */
             statval = *regAddrPtr;
    -        *regAddrPtr = statval;
             regAddrPtr = regAddrPtr + 1U;
    +
    +        /* Find the accumulated value  and write into statPtr*/
             statval += *statAddrPtr;
             *statAddrPtr = statval;
             statAddrPtr = statAddrPtr + 1U;
    @@ -1858,6 +1860,10 @@ uint32_t Ethernet_getHandle(Ethernet_Handle handleApplication,
                                 1U, 0U, 0U);
         Ethernet_configurePHYAddress(Ethernet_device_struct.baseAddresses.enet_base,
                                       0U);
    +
    +    /* Enable reset on read for MMC counters. Use Ethernet_getStatistics() to get stats*/
    +    HWREG(Ethernet_device_struct.baseAddresses.enet_base + ETHERNET_O_MMC_CONTROL) |= ETHERNET_MMC_CONTROL_RSTONRD;
    +
         Ethernet_device_struct.devMagic = ETHERNET_DRV_DEVMAGIC;
         *ethernetHandlePtr = &Ethernet_device_struct;
         return(ETHERNET_RET_SUCCESS);
    @@ -4770,10 +4776,17 @@ void Ethernet_configureMDIO(uint32_t base,
     void Ethernet_configurePHYAddress(uint32_t base,
                                       uint8_t phyAddr)
     {
    -    HWREG(base + ETHERNET_O_MAC_MDIO_ADDRESS) =
    -                        ((uint32_t)phyAddr <<
    -                         (uint32_t) ETHERNET_MAC_MDIO_ADDRESS_PA_S);
    +    HWREG(base + ETHERNET_O_MAC_MDIO_ADDRESS) |=
    +    ((uint32_t)phyAddr << (uint32_t) ETHERNET_MAC_MDIO_ADDRESS_PA_S) & ETHERNET_MAC_MDIO_ADDRESS_PA_M;
     }
    +
    +void Ethernet_configureMMDAddress(uint32_t base,
    +                                  uint8_t mmdAddr)
    +{
    +    HWREG(base + ETHERNET_O_MAC_MDIO_ADDRESS) |= 
    +    ((uint32_t)mmdAddr << (uint32_t) ETHERNET_MAC_MDIO_ADDRESS_RDA_S) & ETHERNET_MAC_MDIO_ADDRESS_RDA_M;
    +}
    +
     uint8_t Ethernet_getPHYMode(uint32_t base)
     {
         uint8_t clause45enable;
    diff --git a/driverlib_cm/ethernet.h b/driverlib_cm/ethernet.h
    index 226437e..e425e01 100644
    --- a/driverlib_cm/ethernet.h
    +++ b/driverlib_cm/ethernet.h
    @@ -3092,7 +3092,9 @@ extern uint16_t Ethernet_readPHYRegister(uint32_t base,
     extern void Ethernet_writePHYRegister(uint32_t base,
                                    uint8_t regAddress,
                                    uint16_t writeData);
    -
    +/* Applicable only on Clause 45 - Used to write Device Address*/
    +extern void Ethernet_configureMMDAddress(uint32_t base,
    +                                  uint8_t mmdAddr);
     //*************************************************************************
     //
     // Ethernet_setMACAddr

    Fix Includes -

    1. Added one more API Ethernet_writeMMDAddress API to configure Device Address before initiating MDIO operation

    2. MAC_MDIO_Address register overwrite issue have been Fixed

    3. There was mistake in assuming re-writing the register content back to MMC register will reset it to zero. This have been modified. During initialization itself we configure all MMC register to Reset On Read. Once register is read from Ethernet_getStatistics API, the MMC registers gets cleared.

    You may use this Patch and will reflect the same on Upcoming C2000ware release

  • Thanks Gouri for the quick response and solution!

    Just after posting I noticed the RSTONRD bit in the MMC_Control register of the EMAC that controls the Reset on Read function. It takes a while before you get acquainted with all the bits in a controller like this. It shows that if you are dealing with statistics without enough knowledge, like I did in this case, you can expect troubles.