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.

Error in lwiplib.c and can't get Static IP to work in lwIP

Using the TM4C129X Eval kit, the enet_lwip example works great using DHCP. Changing the call to lwIPInit from

    lwIPInit(g_ui32SysClock, pui8MACArray, 0, 0, 0, IPADDR_USE_DHCP);    to

    lwIPInit(g_ui32SysClock, pui8MACArray, 0xC0A8A831, 0xFFFFFF00, 0xC0A8A801, IPADDR_USE_STATIC);

does not work. It eventually times out and assigns 169.254.1.0 for the IP Address.

If the DHCP server is left running even when  IPADDR_USE_STATIC is specified, the the DHCP server assigns an address and the Eval kit accepts it.

BTW, this works just fine using a Stellaris part with the latest version of StellarisWare.

Please help!

Thanks,

Jeff

Also, there is an error at line 439 in lwiplib.c:

#if LWIP_AUTIP || LWIP_DHCP  should be   #if LWIP_AUTOIP || LWIP_DHCP

  • Jeff,

    Here is what I did to get the enet_lwip example working with a STATIC IP address on the DK-TM4C129X.

    1)  In 'lwipopts.h' I changed the two defines below to 0:

    #define LWIP_DHCP    0

    #define LWIP_AUTOIP  0

    2) In 'enet_lwip.c' I changed the call to lwIPInit to (screenshot below).  This format also makes it easy to read and change the IP, Subnet, and Gateway addresses.

    Since I'm testing on our LAN, I first ran the example in DHCP mode to verify a safe IP address to use.  I then plugged that IP, Subnet, and Gateway into the lwIPInit call used in static mode.

    Let me know if this helps.

    -Joel

    p.s. thanks for bringing the error to our attention, this has been corrected.

  • That did the trick!

    Thanks Joel!

  • Here is a better solution to support both static and dynamic IP addressing at runtime.

    in file lwiplib.h:

    #define LWIP_DHCP                       1 // %GLA was 1           // default is 0

    #define LWIP_AUTOIP                     0 // %GLA was 1           // default is 0

     

    Make these chances to file lwiplib.c

    in function lwIPServiceTimers()


    //
    // Service the DCHP Coarse Timer.
    //
    #if LWIP_DHCP
    if((g_ui32LocalTimer - g_ui32DHCPCoarseTimer) >= DHCP_COARSE_TIMER_MSECS)
    {
      g_ui32DHCPCoarseTimer = g_ui32LocalTimer;


      // %GLA do only for DHCP
      if (g_ui32IPMode == IPADDR_USE_DHCP)
        dhcp_coarse_tmr();
    }
    #endif

    //
    // Service the DCHP Fine Timer.
    //
    #if LWIP_DHCP
    if((g_ui32LocalTimer - g_ui32DHCPFineTimer) >= DHCP_FINE_TIMER_MSECS)
    {
      g_ui32DHCPFineTimer = g_ui32LocalTimer;

      // %GLA do only for DHCP
      if (g_ui32IPMode == IPADDR_USE_DHCP)
        dhcp_fine_tmr();
    }
    #endif

    //
    // Service the link timer.
    //
    #if LWIP_AUTOIP || LWIP_DHCP
    if((g_ui32LocalTimer - g_ui32LinkTimer) >= LINK_TMR_INTERVAL)
    {
      g_ui32LinkTimer = g_ui32LocalTimer;

      // %GLA do only for DHCP
      if (g_ui32IPMode == IPADDR_USE_DHCP)
        lwIPLinkDetect();
    }
    #endif

    in function lwIPServiceTimers()

    lwIPLocalIPAddrGet(void)
    {
    #if LWIP_AUTOIP || LWIP_DHCP

      // %GLA do only for DHCP
      if (g_ui32IPMode == IPADDR_USE_STATIC)
        return((uint32_t)g_sNetIF.ip_addr.addr);

      if(g_bLinkActive)
      {
        return((uint32_t)g_sNetIF.ip_addr.addr);
      }
      else
      {
        return(0xffffffff);
      }
    #else
      return((uint32_t)g_sNetIF.ip_addr.addr);
    #endif

    }

  • I know it's a useless and whiny thing to say, but it seems that the Tiva lwIP port was done hastily. Pretty much every deviation from the original lwipopts.h that I tried breaks the stack (things I tried: enabling ICMP, enabling stats display).

  • This is still an issue with even in the TivaWare 2.1.0.12573 examples, downloaded just two days ago.
  • Hello Jeff,

    This would be fixed in the new TivaWare release.

    Regards
    Amit
  • Hi Amit,
    About 10 seconds after my earlier post, I realized there wasn't any intrinsic problem with the demo -- it was simply a matter of needing to know how to deal with LWIP -- if one is going to change the lwIPInit() call use IPADDR_USE_STATIC, it kind of makes sense to need to mod lwipopts.h to turn off LWIP_AUTOIP and LWIP_DHCP. Granted it's not obvious to the un-initiated, but there isn't really an 'issue' with the demo.
    -J
  • Hello Jeff,

    Checks and balances. We would need to still check.

    Regards
    Amit
  • I am SO PISSED! This was a STUPID BUG!! There's no reason you should have to recompile your code just to support STATIC IP or not! What if I want a device that could be configured STATIC, DYNAMIC or AUTOIP at run time? I wasted HOURS trying to figure out why my stack would have an IP address for a while, and then it was zeroed!?!

    Here is my suggested fix for this situation when you're using a static IP address but have AUTOIP and/or DHCP compiled in as well:

    Change this:

    //
    // Clear any address information from the network interface.
    //
    ip_addr.addr = 0;
    net_mask.addr = 0;
    gw_addr.addr = 0;
    netif_set_addr(&g_sNetIF, &ip_addr, &net_mask, &gw_addr);

    To this:

    //
    // Clear any address information from the network interface.
    //
    if ((g_ui32IPMode == IPADDR_USE_STATIC) && (g_bLinkActive))
    {
    // link went up
    ip_addr.addr = htonl(g_ui32IPAddr);
    net_mask.addr = htonl(g_ui32NetMask);
    gw_addr.addr = htonl(g_ui32GWAddr);
    }
    else
    {
    // link went down (or not static IP)
    ip_addr.addr = 0;
    net_mask.addr = 0;
    gw_addr.addr = 0;
    }
    netif_set_addr(&g_sNetIF, &ip_addr, &net_mask, &gw_addr);
  • I agree, this TCP/IP stack is trash.  Convoluted code, attempting to be everything to everyone it ends up being a mess.


    We've decided to write our own.

  • This older method of bool test works nicely, can be updated for the newer Ethernet clients. So either yes or no DHCP server exists. Watch out for the Active link variable it never seems to change state when the link drops so we made it bool too.

     // Initialize LWIP, ask to use DHCP or Static IP.
    
    void
    EthClientInitBLDC(uint32_t ui32SysClock, bool bUseDHCP)
    {
        lwIPInit(ui32SysClock, pucMACArray, //0, 0, 0,
                 DEF_IPADDR, DEF_GATEWAY_ADDR, DEF_NET_MASK,
                 (bUseDHCP ? IPADDR_USE_DHCP : IPADDR_USE_STATIC));
    
      }
    

     

        //
        // See if there is an active link.
        // PHY basic mode status REG73:MR1(EPYBMSR)
        bHaveLink = ROM_EMACPHYRead(EMAC0_BASE, 0, EPHY_BMSR) & EPHY_BMSR_LINKSTAT;
    
    
        // Return without doing anything if the link state hasn't changed.
        // The bLinkActive=false until swtiched true
        if(bHaveLink == bLinkActive)
        {
           return;
        }
    
        // Save the new link state switch
        bLinkActive = true;