cancel
Showing results for 
Search instead for 
Did you mean: 

How do you detect an ethernet cable disconnection?

Kostas Anemos
Associate II
Posted on December 26, 2017 at 11:39

Hi,

Iam using an stm32F746 nucleo board and run the web server example with Netconn RTOS.

Working fine, IP is given and samples html files are loaded.

However the ethernet cable disconnection is not being detected (shouldnt the red led be ON?) and the worst thing is that when the cable is back the software is stuck and needs restart.

Any ideas how to overcome this deadlock?

9 REPLIES 9
Jan Waclawek
Senior II
Posted on December 26, 2017 at 12:19

How do you detect an ethernet cable disconnection?

By polling the PHY regularly.

JW

Posted on December 26, 2017 at 16:40

Thanks, no doubt that I should poll regurarly

However seems that after initializations for RTOS, TCP/IP etc the main never executes....It is stated on the code also.

Why is that?

int main(void)

{

....

.....

 osThreadDef(Start, StartThread, osPriorityNormal, 0, configMINIMAL_STACK_SIZE * 5); 

 osThreadCreate (osThread(Start), NULL);

  /* Start scheduler */

  osKernelStart();

 

  /* We should never get here as control is now taken by the scheduler */    <------

  for( ;; ){

   User_notification(&gnetif);         <------this never executes......

  };

}
Posted on December 27, 2017 at 03:46

I am new to all this stuff too..

I am having some aberrations on Ethernet as you are; locking up the Ethernet functions until hard reset.

I started with the cube.

my code is like yours;

We never exit the RTOS task sharing program called osStartKernel();

    //Create user task

    task = osCreateTask('run HTTP Tasks', httpTask, NULL, 8*1024, OS_TASK_PRIORITY_NORMAL);

    //Failed to create the task?

    if (task == OS_INVALID_HANDLE)

    {

        // osCreateTask httpTask has failed with OS_INVALID_HANDLE

        // Error();

    }

    //Start the execution of tasks

    osStartKernel();

    // Error: 1st osStartKernel shouldn't ever exit, but it did. We should never get here

    // This function should never get here

    for (;;)

    ;
Posted on December 28, 2017 at 22:09

I have a similar issue,

as per your suggestion, I have tried to read the phy, but getting the wrong answer.

 PHY BSR          : 0x782d

 PHY BCR          : 0x3100

 PHY SR           : 0x0002

 MAC Address      : 02:AB:CD:EF:07:67

 Rx mode          : Interrupts

 Negotiation      : Disabled

 Speed            : undefined

 Duplex           : Half

 LAN84710A status : READY

 Link status      : Up

is this correct ?

    uint32_t phyBSR;

    HAL_ETH_ReadPHYRegister(heth, PHY_BSR, &phyBSR);

    sprintf(etherString, ' PHY BSR          : 0x%04x\r\n', phyBSR);

how can I read the BSR directly, without the HAL ReadPHYRegister  function ?

Posted on December 29, 2017 at 08:08

Is the cable disconnected?

If yes i assume the answer is not correct

I will check it this afternoon on my board and let you know

Στις 28 Δεκ 2017 23:10, ο χ�?ήστης 'marsh.nick' <

st-microelectronics@jiveon.com> έγ�?αψε:

STMicroelectronics Community

<https://community.st.com/?et=watches.email.thread>

Re: How do you detect an ethernet cable disconnection?

reply from marsh.nick

<

MCUs Forum* - View the full discussion

<https://community.st.com/0D70X000006SvwMSAS

Posted on December 29, 2017 at 20:20

Hi Nick,

At my case I always get a LinkStatus =0 (down) even if the cable is connected.

The code that is working in my case is as follows, check better the phyreg , works like a ''charm'' in my Nucleo board.

Don't ask me if I can get UP the Ethernet interface, I am just playing with indication Leds at the moment.

Regards

/Kostas

static void MonitorThread(void const * argument)

{

   for(;;){

    EthHandlefGlobal=get_ethernet_handle();  

    heth=&EthHandlefGlobal; //pointer to Global Variable  

    /* We wait for linked status */

      HAL_Delay(PHY_RESET_DELAY);

      HAL_ETH_ReadPHYRegister(heth, PHY_BSR, &phyreg);

      if((phyreg & PHY_LINKED_STATUS) != PHY_LINKED_STATUS){      

        //link is down, red light

        BSP_LED_On(LED3);

        BSP_LED_Off(LED1);}

      else {

      //link is up, green light

        BSP_LED_Off(LED3);

        BSP_LED_On(LED1);

      }

  }

}
Posted on December 30, 2017 at 21:34

I tried to read the PHY, but I am getting the wrong values.

how would you read it?

this doesn't work..

    uint32_t phyBSR;

    HAL_ETH_ReadPHYRegister(heth, PHY_BSR, &phyBSR);

    sprintf(etherString, ' PHY BSR          : 0x%04x\r\n', phyBSR);

reporting : PHY BSR          : 0x782d   <- this does not seem correct

:(

Posted on December 31, 2017 at 08:50

hi,

In my board I am getting these values:

   connected ethernet cable: phyreg=0x780d

   disconnected ethernet cable: phyreg=0x7809

I have the NUCLEO-F746ZG  mb 1137 rev b

the PHY should be LAN8742A_PHY_ADDRESS (i don't know where exactly in the board is..)

set a breakpoint inside stm32f7xx_hal_eth.c at line

 317   } while (((phyreg & PHY_LINKED_STATUS) != PHY_LINKED_STATUS));

and check the phyreg with and without the cable.

T J
Lead
Posted on January 01, 2018 at 05:50

I have found a problem in my code and fixed it, I am using the LAN8710A

you should check this in your code;

stm32f7xx_hal_conf.h

#define PHY_SR            ((uint16_t)31)        /*!< PHY status register Offset                      */ //this is now corrected

#define PHY_SR            ((uint16_t)0x31)    /*!< PHY status register Offset                      */ //this is wrong

finally, I can confirm MII mode and 100MHz operation,

but only one led stays on, I dont see any flickers.