From b7dbb74d9fbc159a60f69f1da6b8fe5cab79db16 Mon Sep 17 00:00:00 2001 From: Marcelo Roberto Jimenez Date: Thu, 13 Nov 2025 22:28:42 -0300 Subject: [PATCH] drivers: ethernet: stm32hal: Fixes source address control The default configuration for all STM32 microcontrollers in HAL is to replace the ehternet MAC address with the address configured in replace address zero. In "modules/hal", Grep for: macDefaultConf.SourceAddrControl = ETH_SOURCEADDRESS_REPLACE_ADDR0; But this is a bad thing for bridging. Since Zephyr ethernet LL code always writes the source address, this patch has no impact on normal operation. And has the benefit of maintaining the source MAC address of bridged packets. Signed-off-by: Marcelo Roberto Jimenez --- drivers/ethernet/eth_stm32_hal_v1.c | 5 +++++ drivers/ethernet/eth_stm32_hal_v2.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/drivers/ethernet/eth_stm32_hal_v1.c b/drivers/ethernet/eth_stm32_hal_v1.c index 3fa8dfd0a6561..4335195e01537 100644 --- a/drivers/ethernet/eth_stm32_hal_v1.c +++ b/drivers/ethernet/eth_stm32_hal_v1.c @@ -239,6 +239,11 @@ void eth_stm32_set_mac_config(const struct device *dev, struct phy_link_state *s heth->Init.Speed = PHY_LINK_IS_SPEED_100M(state->speed) ? ETH_SPEED_100M : ETH_SPEED_10M; + /* The default configuration is ETH_SOURCEADDRESS_REPLACE_ADDR0, + * which is bad for bridging. + */ + mac_config.SourceAddrControl = ETH_SOURCEADDRESS_DISABLE; + hal_ret = HAL_ETH_ConfigMAC(heth, NULL); if (hal_ret != HAL_OK) { LOG_ERR("HAL_ETH_ConfigMAC: failed: %d", hal_ret); diff --git a/drivers/ethernet/eth_stm32_hal_v2.c b/drivers/ethernet/eth_stm32_hal_v2.c index 018131bf1e616..6a551ebd01ac5 100644 --- a/drivers/ethernet/eth_stm32_hal_v2.c +++ b/drivers/ethernet/eth_stm32_hal_v2.c @@ -664,6 +664,11 @@ void eth_stm32_set_mac_config(const struct device *dev, struct phy_link_state *s PHY_LINK_IS_SPEED_1000M(state->speed) ? ETH_SPEED_1000M :) PHY_LINK_IS_SPEED_100M(state->speed) ? ETH_SPEED_100M : ETH_SPEED_10M; + /* The default configuration is ETH_SOURCEADDRESS_REPLACE_ADDR0, + * which is bad for bridging. + */ + mac_config.SourceAddrControl = ETH_SOURCEADDRESS_DISABLE; + hal_ret = HAL_ETH_SetMACConfig(heth, &mac_config); if (hal_ret != HAL_OK) { LOG_ERR("HAL_ETH_SetMACConfig failed: %d", hal_ret);