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.

lwIP Init with disconnected ethernet

Other Parts Discussed in Thread: AM3359

Hi,

Anyone have any sense as to how difficult it will be to modify lwIP to 1) startup without an Ethernet cable connected and 2) detect when a connected cable is removed and re-initialize?  I'm guessing I can setup an interrupt to detect the cable connect/disconnect easily enough, but will lwIP handle multiple calls to 'lwIPInit'?  It would need to handle getting a new IP address via DHCP and basically starting over any time the cable is plugged in.

-ed

  • Hi Edward, 

    I dont think any interrupt is there for the cable insertion detection. The PHY will have a register to get the link status. And lwIPInit() shall be called only once. 

    If you want to detect the link status, you need to call MDIOInit() and then check the PHY register. This is anyway done in lwIPInit(). (cpswif_phylink_config() under /third_party/lwip_.../ports/cpsw/netif/cpswif.c)

    Kindly refer to examples/beaglebone/demo/ in StarterWare_02.00.00.07 for the usage example.  

    Regards,

    Sujith.

  • Hello Edward,

    I have the same problems.

    1) Initialize the Lwip stack without an Ethernet cable connected
    2) Detect a removed Ethernet cable
    3) Re-initialize the Lwip stack when Ethernet cable is re-connected

    Hardware: AM3359
    Operation System: NO, only one cycle task
    LWIP: 1.4.1

    Test 1:
    I use the DEMO example from Starterware as reference code. When no ethernet cable is connected the Lwip initialization is not successful and "EnetIfIsUp()" function returns always 0.

    Test 2:
    I implemented two functions:
    LWIP_BaseInit()
    {
        CPSW_init();
        CPSW_selectGMIImode();
        /* Interrupt registration */
        CPSW_getMacAddress(lwipIfPort.macArray);
       lwIPInit(&lwipIfPort);
    }

    LWIP_Cycle()
    {
        if ((EnetPort1LinkIsUp()) && (!EnetPort1IfIsUp()))
        {
           CPSW_getMacAddress(lwipIfPort.macArray);
          lwIPInit(&lwipIfPort);
        }
    }

    The function LWIP_BaseInit() is only called during system initialization.
    Acquiring IP Address for Port 1...
    PHY found at address 0 for  Port 1 of Instance 0.
    Performing Auto-Negotiation...
    Auto-Negotiation Not Successful.
    PHY link connectivity failed for Port 1 of Instance 0.


    The function LWIP_Cycle() is called during the cycle task.
    When I connect an Ethernet cable, then the Lwip stack initialization was successful.
    Acquiring IP Address for Port 1...
    PHY found at address 0 for  Port 1 of Instance 0.
    Performing Auto-Negotiation...
    Auto-Negotiation Successful.
    Transfer Mode : 10/100 Mbps Full Duplex.
    PHY link verified for Port 1 of Instance 0.
    PHY found at address 0 for  Port 2 of Instance 0.
    Performing Auto-Negotiation...
    Auto-Negotiation Successful.
    Transfer Mode : 10/100 Mbps Full Duplex.
    PHY link verified for Port 2 of Instance 0.
    Port 1 IP Address Assigned: 192.168.2.2

    But don't get a response, when I send a ping request.

    What can I do to fix this problem?

    Best regards,

    Philip Hertweck

  • Hello,


    is there no solution for this problem? The Starterware demo application with beaglebone hardware also do not detect ethernet after start-up is completed. I'm astonished, because this is really a normal behavior of network able devices.

    Regards,

    Andreas

  • Hi,

    I've the same problem, does someone know why the program enetEcho from the starterware doesnt work ?

  • Hello ,

             in the cpswif.c(ports/cpsw/netif) of starterware we have an API called cpswif_autoneg_config. in the current starterware examples, during link detection it will wait for some time and will out of the loop whether it is connected or not. Replace the following piece of code, it will work as u expected.

       //while(aut_neg_cnt) {
        while(1) {
          delay(50);
          auto_stat = PhyAutoNegStatusGet(cpswinst->mdio_base,
                                          cpswinst->port[port_num -1].phy_addr);
          if(TRUE == auto_stat) {
            break;
          }
          aut_neg_cnt--;
        }

    Regards

    Rama krishna

  • Ok, and I tried, but I don't get outside of the loop .....

    more precision here : Thread Link

  • @rama krishna: This solution amazingly does not fit anyhow to the question asked: so how can one poll PHY/Ethernet during runtime and without delay to check if a cable is connected?
  • I'm not using an OS, and I'm using an Atmel processor. It seems that the drivers don't poll the PHY status register, so you have to do that. I set up something in the main loop that polls every four seconds, mod 0x00080000... here's some Atmel-ese, it won't be directly applicable to your system:

    while (1)
    {
    /* Check for input packet and process it. */
    ethernet_task();

    sys_check_timeouts();// includes sntp stuff

    loopCounter++;
    if (!(loopCounter%0x00080000))
    {
    gmac_enable_management(GMAC, true);
    uc_rc = gmac_phy_read(GMAC, BOARD_GMAC_PHY_ADDR, GMII_BMSR, &ul_stat1);// get status from PHY

    if ((ul_stat1 & GMII_LINK_STATUS) == 0) // change status LED for no link
    {
    // do something here so LED is different
    LED_Bad();
    }
    else
    LED_OK();// normal status

    gmac_enable_management(GMAC, false);
    }

    }

    Obviously I'm polling to set a status LED showing link up/down.

    Examine your GMAC low-level init routine for the basics to fill this out for your system. I also had the problem above, with the timeout on init... fixed it same way, with an infinite loop... everything else is interrupt-driven, so I don't care if I don't make it to my main loop, that's the only way that can work well (I have serial-port-based config stuff going on too).