Skip to main content
Associate
March 19, 2024
Question

Autonegotiation fails after sometime Using LAN8742 Ethernet PHY & STM32F429ZI.

  • March 19, 2024
  • 5 replies
  • 2682 views

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

Billy OWEN
ST Employee
March 19, 2024

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 II
March 19, 2024

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 II
March 19, 2024

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.

PreetiAuthor
Associate
March 21, 2024

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

PreetiAuthor
Associate
March 21, 2024

Also I cross checked the connection, all are perfect.

 

CLake.2
Associate II
December 6, 2024

Did you find a solution to this issue?