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

drivers: ethernet: stm32: add support for DT pinctrl #29246

Merged
merged 2 commits into from
Oct 30, 2020
Merged

drivers: ethernet: stm32: add support for DT pinctrl #29246

merged 2 commits into from
Oct 30, 2020

Conversation

gmarull
Copy link
Member

@gmarull gmarull commented Oct 15, 2020

  • Add support for configuring Ethernet pins using DT pinctrl entries. Note that F1 series pinctrl support is not handled as the driver does not support F1.
  • Move Ethernet pinmux settings to DT pinctrl on all boards based on STM32.

Copy link
Collaborator

@KozhinovAlexander KozhinovAlexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lochej
Copy link
Collaborator

lochej commented Oct 16, 2020

LGTM, but need to add nucleo_h743zi please 😄

I have tested dumb_http_server and ping works perfectly.

boards/nucleo_h743zi/nucleo_h743zi.dts

&mac {
	status = "okay";
	pinctrl-0 = <&eth_mdc_pc1
		     &eth_rxd0_pc4
		     &eth_rxd1_pc5
		     &eth_ref_clk_pa1
		     &eth_mdio_pa2
		     &eth_crs_dv_pa7
		     &eth_tx_en_pg11
		     &eth_txd0_pg13
		     &eth_txd1_pb13>;
};

image

Without the DTS node we have an error on ETH init:

*** Booting Zephyr OS build zephyr-v2.4.0-646-ga182787ccd70  ***
[00:00:00.501,000] <err> eth_stm32_hal: HAL_ETH_Init failed: 1
[00:00:00.506,000] <inf> net_config: Initializing network
[00:00:00.506,000] <inf> net_config: Waiting interface 1 (0x24004a94) to be up...

With the DTS node, it starts normally:

*** Booting Zephyr OS build zephyr-v2.4.0-646-ga182787ccd70  ***
[00:00:00.006,000] <inf> net_config: Initializing network
[00:00:00.006,000] <inf> net_config: Waiting interface 1 (0x24004a94) to be up...
Single-threaded dumb HTTP server waits for a connection on port 8080...
[00:00:01.538,000] <err> eth_stm32_hal: Failed to enqueue frame into RX queue: -115
[00:00:01.538,000] <inf> net_config: Interface 1 (0x24004a94) coming up
[00:00:01.538,000] <inf> net_config: IPv4 address: 192.0.2.1

@KozhinovAlexander
Copy link
Collaborator

KozhinovAlexander commented Oct 16, 2020

@lochej Thank you for active participating. Strange stuff, that nucleo-h743zi were not listed here. I found the reasons: You have no mac module in nucleo_h743zi.dts and no netif:eth in nucleo_h743zi.yaml. You can take a look at my nucleo-h745zi-q. Moreover, both boards and SoCs have almost same pins definitions and peripherals!

@KozhinovAlexander
Copy link
Collaborator

KozhinovAlexander commented Oct 16, 2020

@gmarull Take a look at my previous comment. It looks like we may have loosed also some more boards within this PR. For example stm32h747-disco definitely has Ethernet but not listed here. What script / method / criteria have you used to determine which board has eth?

@lochej
Copy link
Collaborator

lochej commented Oct 16, 2020

@gmarull Take a look at my previous comment. It looks like we may have loosed also some more boards within this PR. For example stm32h747-disco definitely has Ethernet but not listed here. What script / method / criteria have you used to determine which board has eth?

@Nukersson I think @gmarull checked for existance of mac in pinmux.c just like I did with a small script for uart dac and adc DT pinctrl migrations.

We might need something more clever, why not check the pinctrl dtsi include of each STM32 boards and seeing if the pinctrl dtsi contains any eth pin declaration nodes ?

At least we could get the list of each boards using a SOC compatible with STM32 ethernet.

@KozhinovAlexander
Copy link
Collaborator

KozhinovAlexander commented Oct 16, 2020

@gmarull Take a look at my previous comment. It looks like we may have loosed also some more boards within this PR. For example stm32h747-disco definitely has Ethernet but not listed here. What script / method / criteria have you used to determine which board has eth?

@Nukersson I think @gmarull checked for existance of mac in pinmux.c just like I did with a small script for uart dac and adc DT pinctrl migrations.

We might need something more clever, why not check the pinctrl dtsi include of each STM32 boards and seeing if the pinctrl dtsi contains any eth pin declaration nodes ?

At least we could get the list of each boards using a SOC compatible with STM32 ethernet.

@lochej Good idea. Or we can control, which *.xml files from STM32CubeMX have eth as regex and choose corresponding SoC. With this list of SoCs we can match SoCs from zephyr supported STM32 boards. Same idea, but other way around😄

@erwango
Copy link
Member

erwango commented Oct 16, 2020

LGTM, but need to add nucleo_h743zi please
For example stm32h747-disco definitely has Ethernet but not listed here

@Nukersson, @lochej I don't think we should mix conversions with additions. Only the boards that have eth support within Zephyr today should be part of such coinversion PR.
In order to track properly additions they deserve dedicated PRs.

@KozhinovAlexander
Copy link
Collaborator

KozhinovAlexander commented Oct 16, 2020

LGTM, but need to add nucleo_h743zi please
For example stm32h747-disco definitely has Ethernet but not listed here

@Nukersson, @lochej I don't think we should mix conversions with additions. Only the boards that have eth support within Zephyr today should be part of such coinversion PR.
In order to track properly additions they deserve dedicated PRs.

Ok. You're right: why we should add something, if it is not here 😄 But @lochej - you can add ethernet support to your Nucleo-h743zi same way as h745, cause both SoCs and pinouts are very very very identical, as I said before.

@lochej
Copy link
Collaborator

lochej commented Oct 16, 2020

@gmarull Take a look at my previous comment. It looks like we may have loosed also some more boards within this PR. For example stm32h747-disco definitely has Ethernet but not listed here. What script / method / criteria have you used to determ

LGTM, but need to add nucleo_h743zi please
For example stm32h747-disco definitely has Ethernet but not listed here

@Nukersson, @lochej I don't think we should mix conversions with additions. Only the boards that have eth support within Zephyr today should be part of such coinversion PR.
In order to track properly additions they deserve dedicated PRs.

I'm ok with this principle and will sure help with this. I was surprised to not see nucleo_h743zi since it is with it that i had previously worked on H7 series ethernet. I did the necessary adjustments to try out this PR on the only ethernet enabled board i have. I think @Nukersson and I didn't properly add nucleo_h743zi when we added H7 support.

Btw sorry for closing and reopening this PR (missclick), I probably shouldn't use my phone to discuss here 🙃

@lochej lochej closed this Oct 16, 2020
@lochej lochej reopened this Oct 16, 2020
@lochej
Copy link
Collaborator

lochej commented Oct 17, 2020

@lochej Good idea. Or we can control, which *.xml files from STM32CubeMX have eth as regex and choose corresponding SoC. With this list of SoCs we can match SoCs from zephyr supported STM32 boards. Same idea, but other way around😄

@Nukersson @erwango Dear all, here is the little script I was talking about. It lists all STM32 boards using an ethernet enabled SOC.

#!/bin/bash
stm_pinctrl_dir=../modules/hal/stm32/dts
boards_dir=./boards/arm

deviceTrees=$(find $boards_dir -regex ".*/*\.dts")

for dts in $deviceTrees; do
	board=$(basename $(dirname $dts))
	stm_pinctrl=$(cat $dts | grep -oP "st/.*/.*-pinctrl.dtsi")
	
	if [ -z $stm_pinctrl ]
	then 
		#Not an STM32 board.
		continue
	fi
	stm_pinctrl_file=$stm_pinctrl_dir/$stm_pinctrl

	has_stm32_eth=$(cat $stm_pinctrl_file | grep -cP "eth_.*")
	if [ $has_stm32_eth -eq 0 ]
	then
		#Not an STM32 eth compatible SOC
		continue
	fi
	#Display the board name using an ETH compatible SOC
	echo $board
done

Here is the output of the script for now:

* stm32f746g_disco
* nucleo_f756zg
- black_f407zg_pro
* nucleo_f767zi
- olimex_stm32_h407
* nucleo_f207zg
- black_f407ve
- 96b_aerocore2
* nucleo_h745zi_q
- stm32f429i_disc1
+ nucleo_h743zi
+ stm3210c_eval
+ stm32h747i_disco
+ stm32h747i_disco
* nucleo_f746zg
- stm32f4_disco
* stm32f769i_disco
- stm32f469i_disco
* nucleo_f429zi
* olimex_stm32_e407

All boards with a * are present in this PR. Note that this only means the SOC used in those boards have ethernet capabilities, not that it is available on the board. Each one of this list might need its own PR to have ethernet support.

EDIT: After checking, I marked as '+' each board having a PHY and RJ45 port on it and as '-' if the board doesn't have RJ45 port nor PHY.
Looks like only 2 boards could have ethernet enabled right now:

+ nucleo_h743zi -> missed it when adding H7 eth support 
+ stm32h747i_disco -> same reason

But this one cannot be added without a support for F1 ethernet:

+ stm3210c_eval

This was in case this script could help targeting work for support 😄

@KozhinovAlexander
Copy link
Collaborator

@lochej Good idea. Or we can control, which *.xml files from STM32CubeMX have eth as regex and choose corresponding SoC. With this list of SoCs we can match SoCs from zephyr supported STM32 boards. Same idea, but other way around😄

@Nukersson @erwango Dear all, here is the little script I was talking about. It lists all STM32 boards using an ethernet enabled SOC.

#!/bin/bash
stm_pinctrl_dir=../modules/hal/stm32/dts
boards_dir=./boards/arm

deviceTrees=$(find $boards_dir -regex ".*/*\.dts")

for dts in $deviceTrees; do
	board=$(basename $(dirname $dts))
	stm_pinctrl=$(cat $dts | grep -oP "st/.*/.*-pinctrl.dtsi")
	
	if [ -z $stm_pinctrl ]
	then 
		#Not an STM32 board.
		continue
	fi
	stm_pinctrl_file=$stm_pinctrl_dir/$stm_pinctrl

	has_stm32_eth=$(cat $stm_pinctrl_file | grep -cP "eth_.*")
	if [ $has_stm32_eth -eq 0 ]
	then
		#Not an STM32 eth compatible SOC
		continue
	fi
	#Display the board name using an ETH compatible SOC
	echo $board
done

Here is the output of the script for now:

* stm32f746g_disco
* nucleo_f756zg
- black_f407zg_pro
* nucleo_f767zi
- olimex_stm32_h407
* nucleo_f207zg
- black_f407ve
- 96b_aerocore2
* nucleo_h745zi_q
- stm32f429i_disc1
+ nucleo_h743zi
+ stm3210c_eval
+ stm32h747i_disco
+ stm32h747i_disco
* nucleo_f746zg
- stm32f4_disco
* stm32f769i_disco
- stm32f469i_disco
* nucleo_f429zi
* olimex_stm32_e407

All boards with a * are present in this PR. Note that this only means the SOC used in those boards have ethernet capabilities, not that it is available on the board. Each one of this list might need its own PR to have ethernet support.

EDIT: After checking, I marked as '+' each board having a PHY and RJ45 port on it and as '-' if the board doesn't have RJ45 port nor PHY.
Looks like only 2 boards could have ethernet enabled right now:

+ nucleo_h743zi -> missed it when adding H7 eth support 
+ stm32h747i_disco -> same reason

But this one cannot be added without a support for F1 ethernet:

+ stm3210c_eval

This was in case this script could help targeting work for support 😄

Good work as usual. As only H7 series eth support left for now, let's add it in a separate PR, after this PR were merged. We both can do it, you can take h743 and I h747 for example.

@gmarull gmarull removed the block: HW Test Testing on hardware required before merging label Oct 23, 2020
@erwango erwango requested a review from carlescufi October 27, 2020 09:48
@gmarull gmarull requested a review from erwango October 27, 2020 20:12
Add support for configuring Ethernet pins using DT pinctrl entries. Note
that F1 series pinctrl support is not handled as the driver does not
support F1.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
Move Ethernet pinmux settings to DT pinctrl on all boards based on
STM32.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
Copy link
Collaborator

@lochej lochej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !

@carlescufi carlescufi merged commit fc9f905 into zephyrproject-rtos:master Oct 30, 2020
@gmarull gmarull deleted the feature/stm32-eth-pinctrl branch October 30, 2020 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HAL STM32 Missing ETH pin control configurations in DT files
6 participants