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

Add ethernet driver for M5Core2 #3085

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Conversation

networkfusion
Copy link
Member

@networkfusion networkfusion commented Jan 30, 2025

Description

This PR adds the required "ESP32_ETHERNET_SUPPORT": "ON", to CMakePresets.json so that it is possible to use them for M5Core2.

Currently needs to consider support dependent on actual boad, e.g.
M5Core2 for AWS seems to have a different pin map (when using the compatibility calculator in https://docs.m5stack.com/en/base/lan_poe_v12 ):

                "ESP32_ETHERNET_SPI_MISO_GPIO": "38",
                "ESP32_ETHERNET_SPI_MOSI_GPIO": "23",
                "ESP32_ETHERNET_SPI_SCLK_GPIO": "18",
                "ESP32_ETHERNET_SPI_INT_GPIO": "34",
                "ESP32_ETHERNET_SPI_HOST": "HSPI_HOST",
                "ESP32_ETHERNET_SPI_CS": "26",
                "ETH_PHY_RST_GPIO": "19",

Motivation and Context

The M5Core2 supports ethernet through modules including the LAN-W5500 derivatives:

How Has This Been Tested?

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dev Containers (changes related with Dev Containers, has no impact on code or features)
  • Dependencies/declarations (update dependencies or assembly declarations and changes associated, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).

Summary by CodeRabbit

  • New Features
    • Added Ethernet support for M5Core2, ESP32_LILYGO, ESP32_OLIMEX, and ESP32_OLIMEX_WROVER configurations.
    • Specified Ethernet interface type for M5Core2 configuration.
    • Enhanced configuration with additional GPIO pin assignments for Ethernet connectivity.

Add ethernet driver to CMakePresets
Copy link

coderabbitai bot commented Jan 30, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request modifies the CMakePresets.json file for ESP32 targets, introducing several new cache variables to enhance Ethernet support. Specifically, it adds ESP32_ETHERNET_SUPPORT, ESP32_ETHERNET_INTERFACE, and various GPIO settings for the M5Core2 preset. Similar additions are made to the ESP32_LILYGO, ESP32_OLIMEX, and ESP32_OLIMEX_WROVER presets, maintaining the same settings for Ethernet support. No existing variables were removed or altered.

Changes

File Change Summary
targets/ESP32/CMakePresets.json Added new cache variables to multiple presets:
- ESP32_ETHERNET_SUPPORT="ON" to M5Core2, ESP32_LILYGO, ESP32_OLIMEX, ESP32_OLIMEX_WROVER
- ESP32_ETHERNET_INTERFACE="W5500" to M5Core2
- GPIO variables for Ethernet SPI interface in M5Core2: ESP32_ETHERNET_SPI_MISO_GPIO, ESP32_ETHERNET_SPI_MOSI_GPIO, ESP32_ETHERNET_SPI_SCLK_GPIO, ESP32_ETHERNET_SPI_INT_GPIO, ESP32_ETHERNET_SPI_CS, ETH_PHY_RST_GPIO

Possibly related PRs

Suggested labels

Platform: ESP32


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
targets/ESP32/CMakePresets.json (1)

487-487: Consider adding documentation for Ethernet configurations.

To improve maintainability and help future contributors, consider adding comments explaining:

  1. The supported PHY chips and their configurations
  2. The required GPIO pins and their purposes
  3. References to hardware documentation

Example documentation to add at the top of the file:

+# Ethernet Configuration Guide
+# ---------------------------
+# ESP32_ETHERNET_SUPPORT: Enable Ethernet support
+# ESP32_ETHERNET_INTERFACE: PHY chip (supported: LAN8720, IP101, RTL8201)
+# ETH_PHY_RST_GPIO: Reset pin for PHY chip
+# ETH_RMII_CLK_OUT_GPIO: RMII clock output pin
+# ETH_RMII_CLK_IN_GPIO: RMII clock input pin (alternative to _OUT_)
+# ETH_PHY_ADDR: PHY chip address (usually 0 or 1)
+#
+# For more details, see: <link-to-docs>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbf11b2 and a947770.

📒 Files selected for processing (1)
  • targets/ESP32/CMakePresets.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: nf-interpreter (Check_Code_Style)
  • GitHub Check: nf-interpreter (Nightly build) (Check_Build_Options)
  • GitHub Check: nf-interpreter (Check_Build_Options)
🔇 Additional comments (1)
targets/ESP32/CMakePresets.json (1)

487-487: Verify the Ethernet module type and interface.

The PR description mentions LAN-W5500 derivatives, but the configuration suggests standard RMII Ethernet. The W5500 typically uses SPI interface, not RMII.

Please clarify:

  1. Is the target module a W5500-based board or a standard RMII Ethernet module?
  2. If it's W5500:
    • Should we use SPI interface instead?
    • Do we need different GPIO configurations?
  3. If it's RMII:
    • Which PHY chip is being used?
    • What are the correct GPIO pins?

targets/ESP32/CMakePresets.json Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a947770 and 03b72a5.

📒 Files selected for processing (1)
  • targets/ESP32/CMakePresets.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: nf-interpreter (Check_Code_Style)
  • GitHub Check: nf-interpreter (Nightly build) (Check_Build_Options)
  • GitHub Check: nf-interpreter (Check_Build_Options)

targets/ESP32/CMakePresets.json Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
targets/ESP32/CMakePresets.json (1)

487-488: Add SPI host configuration for W5500.

Consider adding the SPI host configuration to specify which SPI peripheral the W5500 module should use:

 "ESP32_ETHERNET_SUPPORT": "ON",
 "ESP32_ETHERNET_INTERFACE": "W5500",
+"ESP32_ETHERNET_SPI_HOST": "SPI2_HOST",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 03b72a5 and 71a9a1b.

📒 Files selected for processing (1)
  • targets/ESP32/CMakePresets.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_ETHERNET_KIT_1.2)
  • GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_S3_ALL)
  • GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_H2_THREAD)
  • GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_C6_THREAD)
  • GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_C3)
  • GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_BLE_REV0)
  • GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_PSRAM_REV0)
  • GitHub Check: nf-interpreter (Check_Code_Style)
  • GitHub Check: nf-interpreter (Nightly build) (Check_Build_Options)
  • GitHub Check: nf-interpreter (Check_Build_Options)
🔇 Additional comments (1)
targets/ESP32/CMakePresets.json (1)

487-494: Verify GPIO pin assignments for M5Core2 W5500 module.

The Ethernet configuration for W5500 looks good with all required SPI configurations. However, please verify that the GPIO pin assignments match your M5Core2's W5500 module hardware layout:

  • MISO: GPIO19
  • MOSI: GPIO23
  • SCLK: GPIO18
  • INT: GPIO34
  • CS: GPIO26
  • RST: GPIO13

@networkfusion networkfusion marked this pull request as draft January 30, 2025 22:51
@josesimoes josesimoes added Status: in progress Platform: ESP32 Everything related specifically with ESP32 platform labels Jan 30, 2025
@tbibre
Copy link

tbibre commented Feb 10, 2025

I'm not able to send a commit, but here are some changes I did in NF_ESP32_Ethernet.cpp :

Moved

eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG();

to

'#if ESP32_ETHERNET_INTERNAL == TRUE

As I understand this doesn't apply to SPI Ethernet.

Changed all
CONFIG_EXAMPLE_ETH_SPI_HOST and a lone SPI2_HOST to ESP32_ETHERNET_SPI_HOST
As it is expecting the enumeration of the SPI channel.

I guess a variable ESP32_ETHERNET_SPI_MODE would be welcome.
And some refactoring too because each of the 3 SPI ethernet are tested differently.

Everything is compiling, I've seen references to W5500 in the nanoCLR.bin file, but when running GetAllNetworkInterfaces, it's not there.
I don't know what's missing.

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.

4 participants