-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: ethernet: stm32: remove phy specific code #87593
base: main
Are you sure you want to change the base?
drivers: ethernet: stm32: remove phy specific code #87593
Conversation
maass-hamburg
commented
Mar 24, 2025
•
edited
Loading
edited
- enable mdio also on legacy devices
- remove phy specific code from stm32 ethernet driver
- setting the phy-handle of the ethernac mac is now mandatory
- phys, that don't use mdio or the standard registers can now be used.
44412ae
to
24d4c5b
Compare
24d4c5b
to
60cc0af
Compare
60cc0af
to
ac5451d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I had something similar in stock (but not upstreamed); I have published the branch here if you want to take a look: https://github.com/mathieuchopstm/zephyr/tree/stm32_ethernet_rework
This branch is more conservative in terms of changes to the ETH driver, but uses some macrobatics in the MDIO driver to share the ETH_HandleTypeDef
with its parent controller (saves RAM as the structure is quite large, but inhibits usage as a general-purpose MDIO; maybe an in-between solution could be found).
Another change I did was rename all "MDIO"-related stuff to clearly emphasize that this driver is for the MDIO controller built into the Ethernet IP (as opposed to the dedicated "general-purpose" MDIO controllers found on STM32H7) - this could be appreciated, but is mostly cosmetic, so not that important.
a215d4f
to
b8091e7
Compare
Tested OK on Nucleo-F207ZG with Not 100% related but the call to |
The thing is, that |
I didn't look at the implementation but assumed it was something like that, so makes sense. |
dts/arm/st/f1/stm32f107.dtsi
Outdated
clocks = <&rcc STM32_CLOCK(AHB1, 14)>; | ||
mac: ethernet { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To improve readability, please add a newline between the properties and the child nodes:
clocks = <&rcc STM32_CLOCK(AHB1, 14)>; | |
mac: ethernet { | |
clocks = <&rcc STM32_CLOCK(AHB1, 14)>; | |
mac: ethernet { |
Ditto for all DTSI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
drivers/mdio/mdio_stm32_hal.c
Outdated
#ifdef CONFIG_ETH_STM32_HAL_API_V2 | ||
HAL_ETH_SetMDIOClockRange(heth); | ||
#else /* CONFIG_ETH_STM32_HAL_API_V1 */ | ||
/* The legacy V1 HAL API does not provide a way to set the MDC clock range | ||
* via a separated function call. | ||
*/ | ||
uint32_t tmpreg1 = 0U; | ||
|
||
/* Get the ETHERNET MACMIIAR value */ | ||
tmpreg1 = (heth->Instance)->MACMIIAR; | ||
/* Clear CSR Clock Range CR[2:0] bits */ | ||
tmpreg1 &= ETH_MACMIIAR_CR_MASK; | ||
|
||
/* Set CR bits depending on CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC value */ | ||
#ifdef SOC_SERIES_STM32F1X | ||
if ((CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= 20000000U) && | ||
(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC < 35000000U)) { | ||
/* CSR Clock Range between 20-35 MHz */ | ||
tmpreg1 |= (uint32_t)ETH_MACMIIAR_CR_DIV16; | ||
} else if ((CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= 35000000U) && | ||
(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC < 60000000U)) { | ||
/* CSR Clock Range between 35-60 MHz */ | ||
tmpreg1 |= (uint32_t)ETH_MACMIIAR_CR_DIV26; | ||
} else { | ||
/* CSR Clock Range between 60-72 MHz */ | ||
tmpreg1 |= (uint32_t)ETH_MACMIIAR_CR_DIV42; | ||
} | ||
#else /* SOC_SERIES_STM32F2X */ | ||
if ((CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= 20000000U) && | ||
(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC < 35000000U)) { | ||
/* CSR Clock Range between 20-35 MHz */ | ||
tmpreg1 |= (uint32_t)ETH_MACMIIAR_CR_Div16; | ||
} else if ((CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= 35000000U) && | ||
(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC < 60000000U)) { | ||
/* CSR Clock Range between 35-60 MHz */ | ||
tmpreg1 |= (uint32_t)ETH_MACMIIAR_CR_Div26; | ||
} else if ((CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= 60000000U) && | ||
(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC < 100000000U)) { | ||
/* CSR Clock Range between 60-100 MHz */ | ||
tmpreg1 |= (uint32_t)ETH_MACMIIAR_CR_Div42; | ||
} else { | ||
/* CSR Clock Range between 100-120 MHz */ | ||
tmpreg1 |= (uint32_t)ETH_MACMIIAR_CR_Div62; | ||
} | ||
#endif /* SOC_SERIES_STM32F2X */ | ||
|
||
/* Write to ETHERNET MAC MIIAR: Configure the ETHERNET CSR Clock Range */ | ||
(heth->Instance)->MACMIIAR = (uint32_t)tmpreg1; | ||
#endif /* CONFIG_ETH_STM32_HAL_API_V1 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please split out to a dedicated function somewhere else in this file:
#ifdef CONFIG_ETH_STM32_HAL_API_V2 | |
HAL_ETH_SetMDIOClockRange(heth); | |
#else /* CONFIG_ETH_STM32_HAL_API_V1 */ | |
/* The legacy V1 HAL API does not provide a way to set the MDC clock range | |
* via a separated function call. | |
*/ | |
uint32_t tmpreg1 = 0U; | |
/* Get the ETHERNET MACMIIAR value */ | |
tmpreg1 = (heth->Instance)->MACMIIAR; | |
/* Clear CSR Clock Range CR[2:0] bits */ | |
tmpreg1 &= ETH_MACMIIAR_CR_MASK; | |
/* Set CR bits depending on CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC value */ | |
#ifdef SOC_SERIES_STM32F1X | |
if ((CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= 20000000U) && | |
(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC < 35000000U)) { | |
/* CSR Clock Range between 20-35 MHz */ | |
tmpreg1 |= (uint32_t)ETH_MACMIIAR_CR_DIV16; | |
} else if ((CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= 35000000U) && | |
(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC < 60000000U)) { | |
/* CSR Clock Range between 35-60 MHz */ | |
tmpreg1 |= (uint32_t)ETH_MACMIIAR_CR_DIV26; | |
} else { | |
/* CSR Clock Range between 60-72 MHz */ | |
tmpreg1 |= (uint32_t)ETH_MACMIIAR_CR_DIV42; | |
} | |
#else /* SOC_SERIES_STM32F2X */ | |
if ((CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= 20000000U) && | |
(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC < 35000000U)) { | |
/* CSR Clock Range between 20-35 MHz */ | |
tmpreg1 |= (uint32_t)ETH_MACMIIAR_CR_Div16; | |
} else if ((CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= 35000000U) && | |
(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC < 60000000U)) { | |
/* CSR Clock Range between 35-60 MHz */ | |
tmpreg1 |= (uint32_t)ETH_MACMIIAR_CR_Div26; | |
} else if ((CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= 60000000U) && | |
(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC < 100000000U)) { | |
/* CSR Clock Range between 60-100 MHz */ | |
tmpreg1 |= (uint32_t)ETH_MACMIIAR_CR_Div42; | |
} else { | |
/* CSR Clock Range between 100-120 MHz */ | |
tmpreg1 |= (uint32_t)ETH_MACMIIAR_CR_Div62; | |
} | |
#endif /* SOC_SERIES_STM32F2X */ | |
/* Write to ETHERNET MAC MIIAR: Configure the ETHERNET CSR Clock Range */ | |
(heth->Instance)->MACMIIAR = (uint32_t)tmpreg1; | |
#endif /* CONFIG_ETH_STM32_HAL_API_V1 */ | |
#ifdef CONFIG_ETH_STM32_HAL_API_V2 | |
HAL_ETH_SetMDIOClockRange(heth); | |
#else /* CONFIG_ETH_STM32_HAL_API_V1 */ | |
/* The legacy V1 HAL API does not provide a way to set the MDC clock range | |
* via a separated function call. Implement an equivalent function ourselves | |
* based on what the V1 HAL performs in HAL_ETH_Init(). | |
*/ | |
eth_set_mdio_clock_range_for_hal_v1(heth); | |
#endif /* CONFIG_ETH_STM32_HAL_API_V1 */ |
(function name is a suggestion, feel free to use something else if it feels better to you)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
b8091e7
to
f4d8759
Compare
45c454a
to
f333bf5
Compare
#85679 seems to be merged soon, have to apply changes to their new boards/st/nucleo_f439zi/nucleo_f439zi.dts too, when it's merged |
f333bf5
to
6950734
Compare
add mdio for legacy stm32 api Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
The api takes care, if the mdio bus_enable and bus_disable are not needed, so there is no need to have tis in the driver. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
6950734
to
f89f9aa
Compare
add mdio and phy node to every stm32board that supports ethernet. Also set the phy-handle for every ethernet mac. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
mac and mdio are now on the same level, this way phy-handle can be used. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
move stmmaceth clock to parent, so it can also be used by mdio and rename it to ``stm-eth``. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
rewirte code and remove code that use internal phy functions. A few Kconfig options got removed, that are now set by the phy via the DT. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
make stm32 mdio driver more independent Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
unfortunatly HAL_ETH_SetMDIOClockRange() isn't available in the V1 API, so I had to copy the parts from the hal. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
update migration guide for changes of the stm32 ethernet driver. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
f89f9aa
to
d20d92f
Compare
Done |