drivers: ethernet: stm32_hal: Centralize mac address configuration
Get the mac address be set in a central function rather than split
between 2 places.
@@ -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)
{
@@ -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)
@@ -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,
