Autonegotiation in PHY_Init() hangs

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Autonegotiation in PHY_Init() hangs

1,716 Views
mastupristi
Senior Contributor I

PHY driver provided with KSDK 2.2 has the function PHY_Init() that need to be explained:

in particular line 102:

result = PHY_Write(base, phyAddr, PHY_BASICCONTROL_REG,
    (PHY_BCTL_AUTONEG_MASK | PHY_BCTL_RESTART_AUTONEG_MASK));
if (result == kStatus_Success)
{
    /* Check auto negotiation complete. */
    while (counter --)
    {
        result = PHY_Read(base, phyAddr, PHY_BASICSTATUS_REG, &bssReg);
        if ( result == kStatus_Success)
        {
            if ((bssReg & PHY_BSTATUS_AUTONEGCOMP_MASK) != 0)
            {
                break;
            }
        }

        if (!counter)
        {
            return kStatus_PHY_AutoNegotiateFail;
        }
    }
}

If the link is down (eg. ethernet cable disconnected) it loops until count is not 0. count is initialize to 1048575, so it loops for many seconds.

This results, in an hands of many seconds at startup.

I wonder why the check is done without check link state.

best regards

Max

Labels (1)
0 Kudos
2 Replies

1,010 Views
gustavocosta
Contributor III

Hi there,

I'm trying to implement the lwIP on TWR-K64 alongside my project. When I tested lwIP example from KSDK2.0 it worked fine, but when I port it into my own project it gets stuck in the autonegotiation part. 

It's like the there is no cable connected, but it is...

By emulating, I could see that the PHY_Init() function always reads variable "bssReg" as  0, as shown in the code below:

result = PHY_Write(base, phyAddr, PHY_BASICCONTROL_REG,
    (PHY_BCTL_AUTONEG_MASK | PHY_BCTL_RESTART_AUTONEG_MASK));
if (result == kStatus_Success)
{
    /* Check auto negotiation complete. */
    while (counter --)
    {
        result = PHY_Read(base, phyAddr, PHY_BASICSTATUS_REG, &bssReg);
        if ( result == kStatus_Success)
        {
            if ((bssReg & PHY_BSTATUS_AUTONEGCOMP_MASK) != 0)
            {
                break;
            }
        }

        if (!counter)
        {
            return kStatus_PHY_AutoNegotiateFail;
        }
    }
}

Here's my project: Dropbox - TWR-K64 

I've looked everywhere for a solution, but I didn't find one. If anyone could help I'd be extremely thankful.

Best regards

Gustavo Costa

1,010 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Massimiliano Cialdi 

Regards your question,
I wonder why the check is done without check link state.

The value for this PHY_TIMEOUT_COUNT is a standard time to have enough time for the autonegotiation, this is why this value is this big, you could change it if you don't need it so big.

Unfortunately MCU cannot give you the state of the connection until you have successfully initialized the stack, and as long as this part of the code is below to the initialization, you don't have a method to know this state.

This functions should not be called until the physical connection is already set. My recommendation is that if you don't need to initialize the stack (you don't have connected ethernet cable) then you don't initialized.

Hope this information could help you

Best Regards

Jorge Alcala

0 Kudos