2024-12-18 04:26 PM - last edited on 2024-12-19 05:24 AM by SofLit
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
2024-12-18 05:16 PM
A good idea, but should be more or less easy to do this with the "user code areas" and ifdefs.
2024-12-18 05:25 PM
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