zephyr icon indicating copy to clipboard operation
zephyr copied to clipboard

xtensa: esp32: Add Ethernet Support

Open grantramsay opened this issue 2 years ago • 5 comments

Hey, I had a go at adding EPS32 Ethernet support.

Depends on this hal_espressif PR: https://github.com/zephyrproject-rtos/hal_espressif/pull/141

Major additions:

  • Added support for the ESP32-Ethernet-Kit V1.2 board
  • Added ESP32 MDIO Driver
  • Added ESP32 Ethernet Driver
  • Added ESP32 Ethernet Sample (possibly should be consolidated into existing networking samples?)

Ethernet and MDIO samples are working well. I've only tested on the ESP32-Ethernet-Kit.

Example output:

  • Wait for successful DHCP
  • Ping router
  • DNS lookup google.com
  • Ping google.com IP address
uart:~$ *** Booting Zephyr OS build zephyr-v3.1.0-4878-gda842a17fc57  ***
[00:00:00.525,000] <inf> phy_mii: PHY (1) ID 2430C54
[00:00:00.536,000] <inf> net_config: Initializing network
[00:00:00.536,000] <inf> net_config: Running dhcpv4 client...
[00:00:05.331,000] <inf> phy_mii: PHY (1) Link speed 100 Mb, full duplex
[00:00:08.351,000] <inf> net_dhcpv4: Received: 192.168.1.2
[00:00:08.351,000] <inf> net_config: IPv4 address: 192.168.1.2
[00:00:08.351,000] <inf> net_config: Lease time: 86400 seconds
[00:00:08.351,000] <inf> net_config: Subnet: 255.255.255.0
[00:00:08.351,000] <inf> net_config: Router: 192.168.1.1
uart:~$ net ping 192.168.1.1
PING 192.168.1.1
28 bytes from 192.168.1.1 to 192.168.1.2: icmp_seq=0 ttl=64 time=1 ms
28 bytes from 192.168.1.1 to 192.168.1.2: icmp_seq=1 ttl=64 time=0 ms
28 bytes from 192.168.1.1 to 192.168.1.2: icmp_seq=2 ttl=64 time=0 ms
uart:~$ net dns google.com
Query for 'google.com' sent.
dns: 172.217.167.110
dns: All results received
uart:~$ net ping 172.217.167.110
PING 172.217.167.110
28 bytes from 172.217.167.110 to 192.168.1.2: icmp_seq=0 ttl=119 time=41 ms
28 bytes from 172.217.167.110 to 192.168.1.2: icmp_seq=1 ttl=119 time=41 ms
28 bytes from 172.217.167.110 to 192.168.1.2: icmp_seq=2 ttl=119 time=41 ms
uart:~$ 

Not yet supported:

  • RMII clock output
  • Flow control (emac_hal_enable_flow_ctrl/emac_ll_pause_frame_enable)
  • CONFIG_NET_VLAN/ETHERNET_DUPLEX_SET/ETHERNET_PROMISC_MODE
  • Possibly other overlooked features

grantramsay avatar Sep 12 '22 01:09 grantramsay

Just realized I've missed setting the net_if link up/down when Ethernet is connected/disconnected. Adding a small commit to add this functionality...

grantramsay avatar Sep 20 '22 04:09 grantramsay

@grantramsay Just some comments, LGTM.

sylvioalves avatar Sep 20 '22 12:09 sylvioalves

The following west manifest projects have been modified in this Pull Request:

Name Old Revision New Revision Diff
hal_espressif https://github.com/zephyrproject-rtos/hal_espressif/commit/2cb20ac6c5b25f3c91b35e7997451db47030b7cb https://github.com/zephyrproject-rtos/hal_espressif/commit/f3e7e90a61cbbdd27d5f25f975e2810b68c0e850 zephyrproject-rtos/[email protected]

Note: This message is automatically posted and updated by the Manifest GitHub Action.

zephyrbot avatar Sep 21 '22 04:09 zephyrbot

Hey could you rework the board images, reduce the resolution a bit and convert the photo ones to jpg? Trying to keep the repo size under control

fabiobaltieri avatar Sep 21 '22 18:09 fabiobaltieri

Hey could you rework the board images, reduce the resolution a bit and convert the photo ones to jpg? Trying to keep the repo size under control

@fabiobaltieri I carried out these steps and forced pushed the old images out of the git history:

$ cd boards/xtensa/esp32_ethernet_kit/doc/img
$ du -d0 -h
1.1M   .
$ mogrify -resize 50% *.jpg
$ # Set transparent background to white
$ mogrify -background white -alpha remove -alpha off -resize 50% -format jpg *.png
$ rm *.png
$ du -d0 -h
236K    .

Edit: https://launchpad.net/ is down at the moment (503) which is causing the build to fail... Edit2: Back up now, re-based onto main to re-trigger rebuild

grantramsay avatar Sep 21 '22 20:09 grantramsay

@sylvioalves could you give this another review? Just reduced image sizes and corresponding readme updates since last review

grantramsay avatar Sep 27 '22 06:09 grantramsay

Cool, I think this is ready to merge. I'm not authorized to do so. Can someone with permissions merge it?

grantramsay avatar Sep 30 '22 22:09 grantramsay