2024-07-14 08:36 PM
Hi there,
I am using cubeMx to config the LwIP project which is based on STM32F429BI;
I connect the MCU to the route and ping the MCU by PC successfully in DHCP or static IP mode.
I can normally get the MCU IPv4 address in static IP mode but fail in DHCP mode.
my code for getting the IP address is below:
#if LWIP_DHCP
if(ip4_addr_isany_val(*netif_ip4_addr(&gnetif))) {
LOG_DBG("DHCP enabled, check the IP in route\n"); // in DHCP mode, always print this line
} else {
LOG_DBG(" IP : %s\n", ip4addr_ntoa(netif_ip4_addr(&gnetif)));
LOG_DBG("Mask: %s\n", ip4addr_ntoa(netif_ip4_netmask(&gnetif)));
LOG_DBG(" GW : %s\n", ip4addr_ntoa(netif_ip4_gw(&gnetif)));
}
#else
LOG_DBG(" IP : %s\n", ip4addr_ntoa(netif_ip4_addr(&gnetif)));
LOG_DBG("Mask: %s\n", ip4addr_ntoa(netif_ip4_netmask(&gnetif)));
LOG_DBG(" GW : %s\n", ip4addr_ntoa(netif_ip4_gw(&gnetif)));
#endif
I don't know why this code always gets the DHCP IP address 0.
Any information is welcome, thank you!
2024-07-14 08:50 PM
more info: