Skip to content

Commit

Permalink
drivers: ethernet: stm32_hal: Centralize mac address configuration
Browse files Browse the repository at this point in the history
Get the mac address be set in a central function rather than split
between 2 places.

Signed-off-by: Erwan Gouriou <[email protected]>
  • Loading branch information
erwango authored and carlescufi committed Jan 9, 2023
1 parent ddb457a commit eee1d7f
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions drivers/ethernet/eth_stm32_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1010,12 +1010,19 @@ void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth_handle)
k_sem_give(&dev_data->rx_int_sem);
}

#if defined(CONFIG_ETH_STM32_HAL_RANDOM_MAC)
static void generate_mac(uint8_t *mac_addr)
{
#if defined(CONFIG_ETH_STM32_HAL_RANDOM_MAC)
gen_random_mac(mac_addr, ST_OUI_B0, ST_OUI_B1, ST_OUI_B2);
}
#else
mac_addr[0] = ST_OUI_B0;
mac_addr[1] = ST_OUI_B1;
mac_addr[2] = ST_OUI_B2;
mac_addr[3] = CONFIG_ETH_STM32_HAL_MAC3;
mac_addr[4] = CONFIG_ETH_STM32_HAL_MAC4;
mac_addr[5] = CONFIG_ETH_STM32_HAL_MAC5;
#endif
}

static int eth_initialize(const struct device *dev)
{
Expand Down Expand Up @@ -1066,9 +1073,8 @@ static int eth_initialize(const struct device *dev)

heth = &dev_data->heth;

#if defined(CONFIG_ETH_STM32_HAL_RANDOM_MAC)
generate_mac(dev_data->mac_addr);
#endif

heth->Init.MACAddr = dev_data->mac_addr;

#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(CONFIG_ETH_STM32_HAL_API_V2)
Expand Down Expand Up @@ -1369,16 +1375,6 @@ static struct eth_stm32_hal_dev_data eth0_data = {
#endif
},
},
.mac_addr = {
ST_OUI_B0,
ST_OUI_B1,
ST_OUI_B2,
#if !defined(CONFIG_ETH_STM32_HAL_RANDOM_MAC)
CONFIG_ETH_STM32_HAL_MAC3,
CONFIG_ETH_STM32_HAL_MAC4,
CONFIG_ETH_STM32_HAL_MAC5
#endif
},
};

ETH_NET_DEVICE_DT_INST_DEFINE(0, eth_initialize,
Expand Down

0 comments on commit eee1d7f

Please sign in to comment.