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.

TMS570LC4357: Issue in Dp83640LinkStatusGet() if PHY address is greater than 15

Part Number: TMS570LC4357
Other Parts Discussed in Thread: HALCOGEN, DP83640

Hi,

I encountered an issue with the code of HL_phy_dp83640.c generated by HALCoGen (04.06 and 04.07 / TI and GCC modes) when trying to initialize a PHY with an address greater than 15 (in my case 17).

The issue is located in the Dp83640LinkStatusGet() function.

volatile uint16 linkStatus = 0U;

/* Check if MDIO LINK register is updated */
linkStatus = (uint16)MDIOPhyLinkStatusGet(mdioBaseAddr);

/*SAFETYMCUSW 134 S MR:12.2 <APPROVED> "LDRA Tool issue" */
if((linkStatus & (uint16)((uint16)1U << phyAddr)) != 0U)
{
   break;
}
else
{
   <retry>
}

The call to MDIOPhyLinkStatusGet() reads the register "PHY Link Status Register (LINK)" and returns an UINT32 value (with the 16 bits MSB used for the MDIO Link State of devices with a PHY address between 16 and 31.

The function Dp83640LinkStatusGet() then casts this value as an UINT16, losing the MDIO Link State bit information for any PHY with an address over 15. As a result, the subsequent test fails and the device initialization is aborted.

I have patched my code to use an UINT32 variable for the MDIO Link Status (separate from the UINT16 value used for storing the content of the DP86340 Basic Mode Status Register (BMSR) and the device initialization now works.

--- a/source/hal/HL_phy_dp83640.c
+++ b/source/hal/HL_phy_dp83640.c
@@ -109,22 +109,23 @@ boolean Dp83640LinkStatusGet(uint32 mdioBaseAddr,
                                    uint32 phyAddr,
                                    volatile uint32 retries)
 {
-    volatile uint16 linkStatus = 0U;
+    volatile uint16 phyBsr = 0U;
+    volatile uint32 linkStatus = 0U;
     boolean retVal = TRUE;
 
     while (retVal == TRUE)
     {
         /* First read the BSR of the PHY */
-        (void)MDIOPhyRegRead(mdioBaseAddr, phyAddr, (uint32)PHY_BSR, &linkStatus);
+        (void)MDIOPhyRegRead(mdioBaseAddr, phyAddr, (uint32)PHY_BSR, &phyBsr);
 
                /*SAFETYMCUSW 134 S MR:12.2 <APPROVED> "LDRA Tool issue" */
-        if((linkStatus & PHY_LINK_STATUS) != 0U)
+        if((phyBsr & PHY_LINK_STATUS) != 0U)
         {
             /* Check if MDIO LINK register is updated */
-            linkStatus = (uint16)MDIOPhyLinkStatusGet(mdioBaseAddr);
+            linkStatus = (uint32)MDIOPhyLinkStatusGet(mdioBaseAddr);
        
                        /*SAFETYMCUSW 134 S MR:12.2 <APPROVED> "LDRA Tool issue" */
-            if((linkStatus & (uint16)((uint16)1U << phyAddr)) != 0U)
+            if((linkStatus & (uint32)((uint32)1U << phyAddr)) != 0U)
             {
                break;
             }

Regards,

Bastien Continsouzas