Skip to content
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

eth: stm32: Provide functions to abstract "st,stm32h7-ethernet" compat specific registers #86406

Open
erwango opened this issue Feb 27, 2025 · 0 comments
Assignees
Labels
area: Ethernet Enhancement Changes/Updates/Additions to existing features platform: STM32 ST Micro STM32

Comments

@erwango
Copy link
Member

erwango commented Feb 27, 2025

Is your enhancement proposal related to a problem? Please describe.
STM32 eth driver starts to be cluttered with #if DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_ethernet) directives when it comes to accessing directly some registers.
For instance:

#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_ethernet)
		if (config->promisc_mode) {
			heth->Instance->MACPFR |= ETH_MACPFR_PR;
		} else {
			heth->Instance->MACPFR &= ~ETH_MACPFR_PR;
		}
#else
		if (config->promisc_mode) {
			heth->Instance->MACFFR |= ETH_MACFFR_PM;
		} else {
			heth->Instance->MACFFR &= ~ETH_MACFFR_PM;
		}
#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_ethernet) */

This is because IP matching this compatible has a set of register which naming differs from the other STM32 IPs, but are otherwise functionally compatible.

Describe the solution you'd like
Provide abstraction functions to access these registers to relieve the code from these cluttered pieces.
For instance:

__STATIC_INLINE void stm32_eth_set_promisc_mode(ETH_HandleTypeDef *heth, bool promisc_mode_on)
{
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_ethernet)
		if (promisc_mode_on) {
			heth->Instance->MACPFR |= ETH_MACPFR_PR;
		} else {
			heth->Instance->MACPFR &= ~ETH_MACPFR_PR;
		}
#else
		if (promisc_mode_on) {
			heth->Instance->MACFFR |= ETH_MACFFR_PM;
		} else {
			heth->Instance->MACFFR &= ~ETH_MACFFR_PM;
		}
#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_ethernet) */
}

Describe alternatives you've considered
Split the driver in 2 between H7 compatible and non H7 compatible. Though, this will likely double the maintenance burden and doesn't prevent the case of occur again with a next series providing new set of register names, while the abstraction functions could easily deal with that.

Additional context
See https://github.com/zephyrproject-rtos/zephyr/pull/86315/files as a PR adding more matter to this topic.

@erwango erwango added Enhancement Changes/Updates/Additions to existing features platform: STM32 ST Micro STM32 area: Ethernet labels Feb 27, 2025
@erwango erwango self-assigned this Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Ethernet Enhancement Changes/Updates/Additions to existing features platform: STM32 ST Micro STM32
Projects
None yet
Development

No branches or pull requests

1 participant