Add ethernet driver for M5Core2
Description
This PR adds the required "ESP32_ETHERNET_SUPPORT": "ON", to CMakePresets.json so that it is possible to use them for M5Core2.
It also adjusts the esp32_ethernet_options.h.in file to allow the parameters to be set in the cmake file.
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": "13",
So a new target has been added called "M5Core2-AWS".
Motivation and Context
The M5Core2 supports ethernet through modules including the LAN-W5500 derivatives:
- https://docs.m5stack.com/en/base/lan_base
- https://docs.m5stack.com/en/base/w5500PoE
- https://docs.m5stack.com/en/base/lan_poe_v12
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)
- [x] New feature (non-breaking change which adds functionality to code)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [x] 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.
[!IMPORTANT]
Review skipped
Draft detected.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein 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
- #2952: The main PR and this PR both introduce the
ESP32_ETHERNET_SUPPORTvariable in theESP32_OLIMEX_WROVERpreset, indicating a direct connection in enhancing Ethernet support for the same target configuration.
Suggested labels
Platform: ESP32
✨ Finishing touches
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
- [ ] Commit unit tests in branch
m5core2-lan-w5500
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
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.
I got it working, I tweaked a bit the spi initialization:
// Initialise SPI bus
gpio_install_isr_service(ESP_INTR_FLAG_IRAM);
spi_bus_config_t buscfg = {0};
buscfg.miso_io_num = ESP32_ETHERNET_SPI_MISO_GPIO;
buscfg.mosi_io_num = ESP32_ETHERNET_SPI_MOSI_GPIO;
buscfg.sclk_io_num = ESP32_ETHERNET_SPI_SCLK_GPIO;
buscfg.quadwp_io_num = -1;
buscfg.quadhd_io_num = -1;
buscfg.data4_io_num = -1;
buscfg.data5_io_num = -1;
buscfg.data6_io_num = -1;
buscfg.data7_io_num = -1;
buscfg.intr_flags = ESP_INTR_FLAG_IRAM;
buscfg.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO;
buscfg.max_transfer_sz = 0;
ESP_ERROR_CHECK(spi_bus_initialize(ESP32_ETHERNET_SPI_HOST, &buscfg, SPI_DMA_CH_AUTO));
But...
For some reason, ESP32_ETHERNET_SPI_* variables don't seem to take their values from the json file. So I had to hardcode all of them (MISO, MOSI, SCLK, CS, INT, RST), maybe it's the same for ESP32_ETHERNET_SPI_HOST.
But at least, it works.
(With --masserase when flashing firmware)