Skip to main content
Explorer
December 19, 2024
Question

static/DHCP networking with LWIP

  • December 19, 2024
  • 1 reply
  • 907 views

I generally want to support both static/auto/dhcp in software config. This is most easily done by changing LWIP.c

Around line 62:

 

/* IP addresses initialization with DHCP (IPv4) */
ipaddr.addr = gstate.ipaddr; // NOT 0
netmask.addr = gstate.netmask; // NOT 0
gw.addr = gstate.gwaddr; // NOT 0

 

Around 92

 

 if (gstate.dhcp) {
 dhcp_start(&gnetif);
 }
 else
 {
 ipaddr.addr = gstate.ipaddr;
 netmask.addr = gstate.netmask;
 gw.addr = gstate.gwaddr;
 dhcp_stop(&gnetif);
 netif_set_down(&gnetif);

 netif_set_addr(&gnetif, &ipaddr, &netmask, &gw);

 if (netif_is_link_up(&gnetif))
 {
 /* When the netif is fully configured this function must be called */
 netif_set_up(&gnetif);
 }
 }

 

However such changed keep getting trampled on by code generation when I update STM32Cube. Is there any way to protect changes so they don't get overwritten?

I appreciate that to support either Static or DHCP this is a config option in the code generator, but I generally want to support everything I can!

Alan

    This topic has been closed for replies.

    1 reply

    Super User
    December 19, 2024

    A good idea, but should be more or less easy to do this with the "user code areas"  and ifdefs.

     

    alanbAuthor
    Explorer
    December 19, 2024

    It _so nearly_ is, but unfortunately the call to 

     dhcp_start(&gnetif);

    is just before the /* USER CODE BEGIN 3 */

    block which makes it hard to bypass and the init of ipaddr/netmask/gwneeds to be done before this and there isn't a user code block available.

     

    Alan

     

    Super User
    December 24, 2024
    // something like this ...
    #ifdef USE_STATIC
    #define dhcp_start(x) /*nothing*/
    #endif