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

Makes the Ethernet interrupt pin optional. #2775

Open
wants to merge 1 commit into
base: feature/muon-som-evb
Choose a base branch
from

Conversation

XuGuohui
Copy link
Member

@XuGuohui XuGuohui commented May 24, 2024

NOTE: this PR is targeting the feature/muon-som-evb branch

Problem

Currently W5500 interrupt pin is essential for Ethernet to be functional. However, for the Ethernet feather wing from Adafruit doesn't expose the interrupt pin to side headers, indicating that the interrupt pin is optional to the Ethernet interface.

Solution

Allow the int_pin in WizNetifConfigData to be PIN_INVALID and use query scheme in WizNetif when the interrupt pin is not present.

Steps to Test

  1. Use the M.2 SoM breakout board and install the Ethernet feather wing from Adafruit. Do not fly wire the IRQ pin on the wing to any of the Particle SoM's IOs.
  2. Run the following test app.

Example App

#include "application.h"

SYSTEM_MODE(SEMI_AUTOMATIC);

SerialLogHandler l(LOG_LEVEL_ALL);

STARTUP(
    System.enableFeature(FEATURE_ETHERNET_DETECTION);

    if_wiznet_pin_remap remap = {};
    remap.base.type = IF_WIZNET_DRIVER_SPECIFIC_PIN_REMAP;
    remap.cs_pin = PIN_INVALID; // default
    remap.reset_pin = PIN_INVALID; // default
    remap.int_pin = PIN_INVALID;
    if_request(nullptr, IF_REQ_DRIVER_SPECIFIC, &remap, sizeof(remap), nullptr);
);

void setup() {
    while (!Serial.isConnected()) {
        delay(100);
    }
    Log.info("Application started");
}

void loop() {
    if (Serial.available()) {
        char c = Serial.read();
        switch (c) {
            case 'i': {
                if_list* ifs = nullptr;
                if_get_list(&ifs);
                for (if_list* iface = ifs; iface != nullptr; iface = iface->next) {
                    if (iface->iface) {
                        uint8_t idx;
                        if_get_index(iface->iface, &idx);
                        Log.info("Interface %d: %s", idx, iface->iface->name);
                    }
                }
                if_free_list(ifs);
                break;
            }
            case 'p': {
                Log.info("Connecting to Particle Cloud...");
                Particle.connect();
                break;
            }
            case 'e': {
                Log.info("Connecting to Ethernet...");
                Ethernet.connect();
                break;
            }
            case 'd': {
                Log.info("Connecting to Particle Cloud...");
                Particle.disconnect();
                break;
            }
            default: break;
        }
    }
}

References

N/A


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • (REQUIRED) Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

@XuGuohui XuGuohui marked this pull request as ready for review May 24, 2024 19:08
@XuGuohui XuGuohui added the 6.x label May 24, 2024
@mrlambchop
Copy link
Contributor

How does this work in safe mode when the app can't reconfigure the ethernet interface?

@XuGuohui
Copy link
Member Author

How does this work in safe mode when the app can't reconfigure the ethernet interface?

The Ethernet config data is stored in system cache, which is a file in littlefs.

@eberseth
Copy link
Contributor

Does this Ethernet remaping interface already address this PR? https://docs.particle.io/reference/device-os/api/ethernet/ethernet/#pin-configuration-ethernet

@XuGuohui
Copy link
Member Author

Does this Ethernet remaping interface already address this PR? https://docs.particle.io/reference/device-os/api/ethernet/ethernet/#pin-configuration-ethernet

No, that feature requires the INT pin to be a valid pin. This PR removes the constraint based on that feature and also makes minor changes to the WizNetif to make sure Ethernet can receive packets without relying on interrupt.

@XuGuohui XuGuohui force-pushed the feature/auxiliary-power-control branch from c40accc to ab943f2 Compare June 25, 2024 13:46
@XuGuohui XuGuohui force-pushed the feature/ethernet-int-optional branch from b767169 to ef300c8 Compare June 25, 2024 14:28
@XuGuohui XuGuohui changed the base branch from feature/auxiliary-power-control to feature/muon-som-evb June 25, 2024 14:29
@@ -147,9 +147,6 @@ int WizNetifConfig::getConfigData(WizNetifConfigData* configData) {
if (configData->reset_pin == PIN_INVALID) {
configData->reset_pin = HAL_PLATFORM_ETHERNET_WIZNETIF_RESET_PIN_DEFAULT;
}
if (configData->int_pin == PIN_INVALID) {
configData->int_pin = HAL_PLATFORM_ETHERNET_WIZNETIF_INT_PIN_DEFAULT;
}
Copy link
Member

Choose a reason for hiding this comment

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

NOTE: We will have to update the docs to spell out the fact that if you want to set the INT pin back to it's default value, you must know what it is and set it explicitly.

See here: "If you want to restore one or more pins as their default value, use PIN_INVALID, and the default will be used for that pin."
https://docs.particle.io/reference/device-os/api/ethernet/pin-configuration-ethernet/

Copy link
Member Author

Choose a reason for hiding this comment

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

Cc. @rickkas7

@technobly
Copy link
Member

How does this work in safe mode when the app can't reconfigure the ethernet interface?

It is important to note that if a custom configuration is required, the correct system parts need to be flashed to the device so that it does not rely on booting into Safe Mode for the first connection to the Cloud.

This NOTE should also be added to the Docs.
https://docs.particle.io/reference/device-os/api/ethernet/pin-configuration-ethernet/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants