2021-07-26 06:30 AM
Hello!
Please advise on the proper way to change IP and MAC address during runtime.
Are there any standard ways of doing this? Are there any reinitilizations needed? which functions to use?
thanks in advance!
2021-07-26 09:54 AM
MAC address is provided in parameters for HAL_ETH_Init(). So the simplest way is to do HAL_ETH_DeInit then HAL_ETH_Init with new address.
2021-07-26 11:35 PM
thanks for the response,
understood. i guess the same goes for IP address...?
2021-07-27 01:52 PM
The IP address is assigned and used by software layer such as LwIP.
The MAC (ETH) has some offloads that use the IP address, but this is advanced stuff.
Especially, the ARP offload (automatic reply to ARP) is broken in STM32H7 and should be disabled (see errata).
So after change of the MAC address, make sure that higher layer refreshes its ARP cache or whatever.
-- pa
2021-08-08 03:54 PM
// Change IP addresses
LOCK_TCPIP_CORE();
if (hDHCP->state == DHCP_STATE_OFF) {
netif_set_ipaddr(hNetif, (ip4_addr_t*)puData);
netif_set_netmask(hNetif, (ip4_addr_t*)puData);
netif_set_gw(hNetif, (ip4_addr_t*)puData);
dns_setserver(0, (ip_addr_t*)puData);
dns_setserver(1, (ip_addr_t*)puData);
}
UNLOCK_TCPIP_CORE();
// Change MAC address
LOCK_TCPIP_CORE();
bool fLink = netif_is_link_up(hNetif);
netif_set_link_down(hNetif);
memcpy(hNetif->hwaddr, puData, hNetif->hwaddr_len);
DRV_ETH_MACAddrSet(hNetif->hwaddr); // Set MAC address on ETH peripheral
if (fLink) {
netif_set_link_up(hNetif);
}
UNLOCK_TCPIP_CORE();
The rest of the ARP and DHCP things will be done by the lwIP stack automatically.
2021-08-09 12:44 AM
Hi, thank you for answering!
i am working with static IP and the DHCP is disabled.
how might that change your answer?