Hi. I've been chasing a problem for hours. DHCP works fine but the static IP is screwed up (and I need both to work).
I'm even using the latest and greatest tivaware 2.1.4.178.
I do have #define LWIP_DHCP 1 because the customer will be able to use DHCP or assign a static ip.
I finally traced what appears to be the problem to a little function called lwIPLinkDetect();
It wipes out the IP address (this is in lwiplib.c):
//
// 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);
I added this right above as a fix: if (g_ui32IPMode == IPADDR_USE_STATIC) return;
I'm not sure if I was just doing something wrong or what was going on but for anybody that has the same problem I'm posting the complete function below with the fix in it.
//*****************************************************************************
//
// This function performs a periodic check of the link status and responds
// appropriately if it has changed.
//
//*****************************************************************************
#if LWIP_AUTOIP || LWIP_DHCP
static void
lwIPLinkDetect(void)
{
bool bHaveLink;
struct ip_addr ip_addr;
struct ip_addr net_mask;
struct ip_addr gw_addr;
//
// See if there is an active link.
//
bHaveLink = MAP_EMACPHYRead(EMAC0_BASE, PHY_PHYS_ADDR, EPHY_BMSR) &
EPHY_BMSR_LINKSTAT;
//
// Return without doing anything else if the link state hasn't changed.
//
if(bHaveLink == g_bLinkActive)
{
return;
}
//
// Save the new link state.
//
g_bLinkActive = bHaveLink;
if (g_ui32IPMode == IPADDR_USE_STATIC) return;
//
// 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);
//
// See if there is a link now.
//
if(bHaveLink)
{
//
// Start DHCP, if enabled.
//
#if LWIP_DHCP
if(g_ui32IPMode == IPADDR_USE_DHCP)
{
dhcp_start(&g_sNetIF);
}
#endif
//
// Start AutoIP, if enabled and DHCP is not.
//
#if LWIP_AUTOIP
if(g_ui32IPMode == IPADDR_USE_AUTOIP)
{
autoip_start(&g_sNetIF);
}
#endif
}
else
{
//
// Stop DHCP, if enabled.
//
#if LWIP_DHCP
if(g_ui32IPMode == IPADDR_USE_DHCP)
{
dhcp_stop(&g_sNetIF);
}
#endif
//
// Stop AutoIP, if enabled and DHCP is not.
//
#if LWIP_AUTOIP
if(g_ui32IPMode == IPADDR_USE_AUTOIP)
{
autoip_stop(&g_sNetIF);
}
#endif
}
}
#endif