device-os icon indicating copy to clipboard operation
device-os copied to clipboard

Makes the Ethernet reset pin optional.

Open XuGuohui opened this issue 7 months ago • 0 comments

NOTE: this PR is targeting the feature/auxiliary-power-control branch

Problem

The Ethernet reset pin on Muon is controlled by a reset IC, instead of GPIO. The reset IC will delay up to 200ms after the Ethernet interface is powered up to reset the Ethernet, which is too late to add the Ethernet interface.

Solution

  1. Makes the reset pin of Ethernet optional, so that user can set the reset pin to PIN_INVALID
  2. Does retries to detect the Ethernet interface so that we can detect it after the reset IC resets it.

Steps to Test

Build and run the test app on MSoM/B5SoM/BSoM that is installed on the Muon.

Example App

#include "application.h"

SYSTEM_MODE(SEMI_AUTOMATIC);

Serial1LogHandler l(115200, LOG_LEVEL_ALL);

uint8_t auxPwrPin = D7;

STARTUP(System.enableFeature(FEATURE_ETHERNET_DETECTION));

STARTUP({
    System.setPowerConfiguration(SystemPowerConfiguration().auxPowerControlPin(auxPwrPin).feature(SystemPowerFeature::PMIC_DETECTION));

    System.enableFeature(FEATURE_ETHERNET_DETECTION);

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

void setup() {
    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;
            }
            default: break;
        }
    }
}

References

N/A


Completeness

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

XuGuohui avatar Jun 28 '24 16:06 XuGuohui