cancel
Showing results for 
Search instead for 
Did you mean: 

Autonegotiation fails after sometime Using LAN8742 Ethernet PHY & STM32F429ZI.

Preeti
Associate II

Hi everyone, I'm using STM32F429ZI with LAN8742A PHY. Once I start the MCU Ethernet communication works properly, After sometime netif link goes down and ping stops.

Only when I resets the MCU communication starts.

After debugging further it is observed that, Whenever link status updates it goes into ethernetif_Update_config callback function. But autonegotiation processes not completing there and goes into error.(refer below code.)

void ethernetif_update_config(struct netif *netif)
{
__IO uint32_t tickstart = 0;
uint32_t regvalue = 0;

if(netif_is_link_up(netif))
{
/* Restart the auto-negotiation */
if(heth.Init.AutoNegotiation != ETH_AUTONEGOTIATION_DISABLE)
{

/* Enable Auto-Negotiation */
HAL_ETH_WritePHYRegister(&heth, PHY_BCR, PHY_AUTONEGOTIATION);

/* Get tick */
tickstart = HAL_GetTick();

/* Wait until the auto-negotiation will be completed */
do
{
HAL_ETH_ReadPHYRegister(&heth, PHY_BSR, &regvalue);

/* Check for the Timeout ( 1s ) */
if((HAL_GetTick() - tickstart ) > 5000)
{
/* In case of timeout */
goto error;
}
} while (((regvalue & PHY_AUTONEGO_COMPLETE) != PHY_AUTONEGO_COMPLETE));

 

Any suggestions to avoid Autonegotiation timeout in this callback?

5 REPLIES 5
Billy OWEN
ST Employee

Hi @Preeti 

 

The forum moderator had marked your post as needing a little more investigation and direct support. An online support case has been created on your behalf, please stand by for just a moment and you will hear from us.

 

Regards,

Billy

LCE
Principal

EDIT: my mistake, auto negotiation complete bit is in BSR, so partly disregard the stuff below.

 

You are reading the wrong register, auto-neg. result is in register SSR (31d), can't remember which bit.

Might be the old HAL bug.

/* Wait until the auto-negotiation will be completed */
...
HAL_ETH_ReadPHYRegister(&heth, PHY_BSR, &regvalue);

Might still be another problem.

 

Never take the HAL or Cube stuff for granted, if in doubt check registers of STM32 and external hardware.

LCE
Principal

So, next try...

I found my ethernetif_update_config().

if( netif_is_link_up(pNetIf) ), I completely re-init the STM32's MAC interface (incl. auto-neg start and all the PHY stuff), then call ethernetif_notify_conn_changed(pNetIf).

But you should find out why you lose the connection in the first place.

Preeti
Associate II

Hello,

First of all thanks for your support

 

When I disconnect the ethernet cable manually in that case only it is completely re-init the STM32's MAC interface (incl. auto-neg start and all the PHY stuff).

But here we are generating noise purposefully,  And in that case when link goes down & try to reconnect. But not it is reconnecting, continuously hitting timeout that's why autonegotiation processes not completing there and goes into error.

BSR Reg values are as bellow :

when link is up and stable:  0x782d

when link not stable (not reconnecting): 0x780d

Preeti
Associate II

Also I cross checked the connection, all are perfect.