cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f746 switching static IP to DHCP in run time with LWIP FREERTOS

rdurs.1
Associate

when I press an external interrupt button, I want to switch to static IP, press again want to switch to DHCP, how can I get this? because in CubeMX it just defines once for LWIP_DHCP macro and how can I use this for static IP or vice versa ?

1 REPLY 1
Bob S
Principal

In general you need to take down the interface including dhcp_release() and dhcp_stop() [***] if you WERE using DHCP, change the IP address settings, then bring the interface back up, calling dhcp_start() if you need dhcp. If using CubeMX then configure it for fixed IP, gen the code and save the lwip.c file (with MX_LWIP_Init()). Then change CubeMX for DHCP and re-gen the code. look at the differences in MX_LWIP_Init() to see how to start each type. Should be able to use netif_XXXX() functions like netif_set_up() and netif_set_down() for all these changes once you are up and running.

[***] I'm not SURE you need to stop DHCP when changing to fixed IP. Probably can start it once in MX_LWIP_Init() and keep it running.