lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Randomly delayed frame (STM32070 package including LwIP


From: address@hidden
Subject: Re: [lwip-users] Randomly delayed frame (STM32070 package including LwIP v1.4.1)
Date: Wed, 2 Jan 2019 20:20:41 +0100
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.3.3

Am 02.01.2019 um 20:14 schrieb stevestrong:
I finally managed to get DHCP working, I get a valid IP address assigned by
the router.

Well, the holidays and new year is a bit of a bad time to ask ;-)


I post here the working version from netconf.c, not sure if it is really ok:
********************************************
void LwIP_Periodic_Handle(__IO uint32_t localtime)
{
     /* Cyclic lwIP timers check */
     sys_check_timeouts(); // v2

#ifdef USE_DHCP
   /* Fine DHCP periodic process every 500ms */
   if ( (localtime - DHCPfineTimer) >= DHCP_FINE_TIMER_MSECS)
   {
     DHCPfineTimer = localtime;
      if ((DHCP_state != DHCP_ADDRESS_ASSIGNED) &&
         (DHCP_state != DHCP_TIMEOUT) &&
           (DHCP_state != DHCP_LINK_DOWN))
     {
       /* toggle LED1 to indicate DHCP on-going process */
          ToggleLED(); // STM_EVAL_LEDToggle(LED1);

       /* process DHCP state machine */
       LwIP_DHCP_Process_Handle();
     }
   }
#else
        (void)(localtime);
#endif
}
********************************************
void LwIP_DHCP_Process_Handle()
{
   struct ip4_addr ipaddr;
   struct ip4_addr netmask;
   struct ip4_addr gw;

   switch (DHCP_state)
   {
   case DHCP_START:
     {
       DHCP_state = DHCP_WAIT_ADDRESS;
          PRINTF(". DHCP_WAIT_ADDRESS .\n");
       dhcp_start(&gnetif);
       /* IP address should be set to 0 every time we want to assign a new
DHCP address */
       IPaddress = 0;
     }
     break;

   case DHCP_WAIT_ADDRESS:
     {
       /* Read the new IP address */
       IPaddress = gnetif.ip_addr.addr;

       if (IPaddress!=0)
       {
         DHCP_state = DHCP_ADDRESS_ASSIGNED;    

            PRINTF(". DHCP_ADDRESS_ASSIGNED .\n");
         /* Stop DHCP */
         dhcp_stop(&gnetif);

                LEDOn(1); // STM_EVAL_LEDOn(LED1);
       }
       else
       {
                struct dhcp * dhcp;
                dhcp = netif_get_client_data(&gnetif, 
LWIP_NETIF_CLIENT_DATA_INDEX_DHCP);
         /* DHCP timeout */
         if (dhcp->tries > MAX_DHCP_TRIES)
         {
           DHCP_state = DHCP_TIMEOUT;

              PRINTF(". DHCP_TIMEOUT .\n");
           /* Stop DHCP */
           dhcp_stop(&gnetif);

           /* Static address used */
           IP4_ADDR(&ipaddr, IP_ADDR0 ,IP_ADDR1 , IP_ADDR2 , IP_ADDR3 );
           IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2,
NETMASK_ADDR3);
           IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
           netif_set_addr(&gnetif, &ipaddr , &netmask, &gw);

                  LEDOff(1); // STM_EVAL_LEDOn(LED1);
         }
       }
     }
     break;
   default: break;
   }
}
********************************************

Basicaly, I added sys_check_timeouts() in the periodic handler and removed
the DHCP fine and course timeout routines from DHCP handler because they are
anyway executed by the newly added timeout check function.

I have seen threading issues in the way ST does this DHCP thing. However, if you're using one big main loop only without interrupts, you should be fine...


However, I am not sure whether the DHCP process is standard conform.
It is weird that the gratuitous ARP request comes after the IP has been
assigned by the router. Is that OK?

Yes, the gratuitous ARP is expected.


I made a wireshark and debug log capture.
dhcp3.jpg <http://lwip.100.n7.nabble.com/file/t2167/dhcp3.jpg>

Except for not seeing the DHCP server'ss responses, that looks ok.

dhcp3.log <http://lwip.100.n7.nabble.com/file/t2167/dhcp3.log>

I cannot commen on the board specific logs but lwip output seems ok.


It would be nice if someone could have a look on it.

Regards,
Simon



reply via email to

[Prev in Thread] Current Thread [Next in Thread]