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

Allow entering safe mode from DFU #111

Merged
merged 7 commits into from
Jun 20, 2024
Merged

Conversation

sergeuz
Copy link
Member

@sergeuz sergeuz commented Jun 18, 2024

Extend the enterSafeMode() method to use a custom DfuSe command for entering safe mode when the device is in DFU mode.

Test app:

const { getDevices } = require('particle-usb');

async function run() {
  let dev;
  try {
    // Open the first found USB device
    const devs = await getDevices();
    if (!devs.length) {
      throw new Error('No devices found');
    }
    dev = devs[0];
    if (!dev.isInDfuMode) {
      throw new Error('Device is not in DFU mode');
    }
    await dev.open();

    await dev.enterSafeMode();

  } catch (err) {
    console.error(err);
    process.exit(1);
  } finally {
    if (dev) {
      await dev.close();
    }
  }
}

run();

@sergeuz sergeuz marked this pull request as ready for review June 18, 2024 21:19
async _checkDfuseCommandSupported(cmd) {
if (!this._supportedDfuseCommands.length) {
await this._goIntoIdleState({ uploadIdle: true });
const data = await this._sendUploadReqest(DEFAULT_TRANSFER_SIZE, 0 /* value */); // Get command
Copy link
Member

Choose a reason for hiding this comment

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

This is already a part of the DFU implementation in Device OS so it will work on old devices, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this command is part of the DfuSe spec.

@sergeuz sergeuz merged commit d98eec3 into main Jun 20, 2024
4 checks passed
@sergeuz sergeuz deleted the enter-safe-mode-from-dfu/sc-127946 branch June 20, 2024 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants