Re: Problems setting up ethernet mac address on STM32H753ZI

Jukka Rissanen

Hi Bernd,

when chaning the MAC from the application, you should use the net_mgmt API so that the Ethernet driver knows that the link address is changed.
See for example tests/net/ethernet_mgmt/src/main.c and test_change_mac_when_down() function how it is doing the change.


On Fri, 2022-03-04 at 12:10 +0000, Weiberg, Bernd wrote:

Dear Users,

currently I have some trouble setting the ethernet MAC Address on an NUCLEO-H753ZI Board.

After setting the MAC address I got some strange behavior:

When I try to ping my notebook from the nucleo board using net ping <ip> I can see (with Wireshark) that the ping requests from the nucleo board are still be send with the old mac address as Source. The response from the notebook is then send back to the new mac address.

This behavior is the result of the following wrong arp request/response procedure ( is my NUCLEO Board and is my notebook):

1:        ICMP Echo (ping) request

2:   08:00:27:bc:26:03    ff:ff:ff:ff:ff:ff    Who has Tell

3:   02:80:e1:2c:24:31    08:00:27:bc:26:03 is at 00:19:28:ab:cd:ef


After resolving the mac address of the notebook using ARP the NUCLEO send a ping request to the notebook (1).

The Notebook (08:00:27:bc:26:03) is asking the NUCLEO for its mac address (2).

The NUCLEO answers, with the correct mac address in the arp response (00:19:28:ab:cd:ef) but still uses the old one as source address (02:80:e1:2c:24:31).


I used the following code for changing the mac address:


* Set mac address


int set_mac(uint8_t *p_mac, uint8_t len)


     int result = 0;

     struct net_if *p_iface = net_if_get_default();


     // Check, if we have got a valid network interface

     if (p_iface == NULL) {

          LOG_WRN("No network interface defined");

          return -ENODEV;



     // The API documentation for net_if_set_link_addr() says that the address

     // must be valid throughout interface lifetime, so we will copy it to our

     // local variable. But at first we will check the size.

     if (len != sizeof(mac)) {

          LOG_WRN("Invalid size for mac address %u (expected %u)",

                     len, sizeof(mac));

          return -EINVAL;


     memcpy(mac, p_mac, sizeof(mac));


     // Before we can setup the mac address, we have to bring the interface down

     if (net_if_down(p_iface) != 0) {

          LOG_WRN("Failed to bring network interface down");

          return -EACCES;



     // Try to change the mac address now

     if ((result = net_if_set_link_addr(p_iface, mac, sizeof(mac),

                NET_LINK_ETHERNET)) != 0)


          LOG_WRN("Failed to setup mac address: %d", result);

          result = -EACCES;



     // Bring the interface up again (even if we failed to setup the mac address)

     if (net_if_up(p_iface) != 0) {

          LOG_WRN("Failed to bring network interface up again");

          return -EACCES;


     return result;



As pointed out by the API documentation is stored the mac address in a variable which is on the heap and

doesn’t change through the lifetime of the interface.

I also brought the interface down before changing the mac address.


Any Ideas?







Join to automatically receive all group messages.