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

Supports auxiliary power control. #2774

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

Conversation

XuGuohui
Copy link
Member

@XuGuohui XuGuohui commented May 23, 2024

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

Example App

#include "application.h"

SYSTEM_MODE(SEMI_AUTOMATIC);

#define M2_BREAKOUT_BOARD   1

Serial1LogHandler l(115200, LOG_LEVEL_ALL);

#if M2_BREAKOUT_BOARD
uint8_t auxPwrPin = D23;
#else // Muon
uint8_t auxPwrPin = D7;
#endif

STARTUP(
    System.enableFeature(FEATURE_ETHERNET_DETECTION);

    SystemPowerConfiguration conf;
    conf.powerSourceMinVoltage(3880)
        .powerSourceMaxCurrent(3000)
        .batteryChargeVoltage(4200)
        .batteryChargeCurrent(900)
        .auxPowerControlPin(auxPwrPin)
        .feature(SystemPowerFeature::PMIC_DETECTION);
        // .feature(SystemPowerFeature::DISABLE);
    System.setPowerConfiguration(conf);

    if_wiznet_pin_remap remap = {};
    remap.base.type = IF_WIZNET_DRIVER_SPECIFIC_PIN_REMAP;
#if M2_BREAKOUT_BOARD
    remap.cs_pin = HAL_PLATFORM_ETHERNET_WIZNETIF_CS_PIN_DEFAULT; // default
    remap.reset_pin = HAL_PLATFORM_ETHERNET_WIZNETIF_RESET_PIN_DEFAULT; // default
    remap.int_pin = PIN_INVALID;
#else // Muon
    remap.cs_pin = A3;
    remap.reset_pin = PIN_INVALID;
    remap.int_pin = A4;
#endif
    if_request(nullptr, IF_REQ_DRIVER_SPECIFIC, &remap, sizeof(remap), nullptr);
);

void setup() {
    Log.info("Application started");
}

void loop() {
    if (Serial1.available()) {
        char c = Serial1.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;
        }
    }
}

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
  • 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 08:43
Copy link
Member

@scott-brust scott-brust left a comment

Choose a reason for hiding this comment

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

I tested MSOM on an old EVB, with the onboard wiznet chip (just to make things easier)

I confirmed that the D23 / aux power pin is asserted on boot before setup() completes, and that the en2 netif is populated (because the EVB already powers it on by default).

I confirmed that when pulling the ethernet jumpers, and breaking ethernet communication to the msom, that the en2 netif is removed from the list of lwip IFs after boot.

I think the PR as currently written can be used for muon / m2 breakout to control the aux power at boot

hal/src/b5som/network/network.cpp Show resolved Hide resolved
system/src/main.cpp Show resolved Hide resolved
system/src/system_power_manager.cpp Show resolved Hide resolved

#if HAL_PLATFORM_POWER_MANAGEMENT_OPTIONAL
if (!detect()) {
return;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe Log a warning here to make it clear PMIC isnt detected?

Copy link
Member

Choose a reason for hiding this comment

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

Also, previously this would call self->deinit();
Do we need to call this still in this case or if we are exiting during init, there is nothing to de-init at this point? (maybe just unconfigure the aux power control pin?)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the previous goto exit, in which it calls self->deinit() is mainly for calling os_thread_exit() to exit the thread. But here is the very begining of the init() function, if the PMIC is not detected we can simply return. As for the aux power control pin, it is required when the power module for DC power supply is installed, on which there is no PMIC, but we still need to enable the aux power control pin.

system/src/system_power_manager.cpp Show resolved Hide resolved
hal/inc/power_hal.h Show resolved Hide resolved
@XuGuohui XuGuohui force-pushed the feature/auxiliary-power-control branch from c40accc to ab943f2 Compare June 25, 2024 13:46
@XuGuohui XuGuohui changed the base branch from develop to feature/muon-som-evb June 25, 2024 14:20
…epeated reset when powered by PC's USB-C to DC jack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants