@9wick/esptool.js 中文文档教程

发布于 3年前 浏览 9 项目主页 更新于 3年前

esptool.js

npmnpm“类型文档”GitHub

esptool 的 TypeScript 端口。

esptool 最初是用 python 编写的,我们在这里将其移植到 TypeScript。

此实现用于 Toit 控制台,以允许用户刷写和监控 ESP32:

Flash ESP32 with web serial

关于原因的博 文我们开始了这个项目:使用 Web Serial 从浏览器刷写 ESP32

Example

代码是作为一个库编写的,这里有一个示例展示了如何使用该库来刷新 ESP32:

export type Partition = {
  name: string;
  data: Uint8Array;
  offset: number;
};

// TODO: Here you have to specify the partitions you want to flash to the ESP32.
const partitions: Partition[] = [];

const port = new EsptoolSerial("/dev/tty.SLAB_USBtoUART", {
  baudRate: 115200,
  autoOpen: false,
});
await port.open();
try {
  const loader = new EspLoader(port, { debug: true, logger: console });
  options.logger.log("connecting...");
  await loader.connect();
  try {
    options.logger.log("connected");
    options.logger.log("writing device partitions");
    const chipName = await loader.chipName();
    const macAddr = await loader.macAddr();
    await loader.loadStub();
    await loader.setBaudRate(options.baudRate, 921600);

    if (options.erase) {
      options.logger.log("erasing device flash...");
      await loader.eraseFlash();
      options.logger.log("successfully erased device flash");
    }

    for (let i = 0; i < partitions.length; i++) {
      options.logger.log("\nWriting partition: " + partitions[i].name);
      await loader.flashData(partitions[i].data, partitions[i].offset, function (idx, cnt) {
        if (options.progressCallback) {
          options.progressCallback(partitions[i].name, idx, cnt);
        }
      });
      await sleep(100);
    }
    options.logger.log("successfully written device partitions");
    options.logger.log("flashing succeeded");
  } finally {
    await loader.disconnect();
  }
} finally {
  await port.close();
}

Development

要自动检查版权和 MIT 通知,请运行

$ git config core.hooksPath .githooks

如果文件不需要版权/MIT 通知,请使用以下命令跳过 检查:

git commit --no-verify

Similar projects

  • Espressif esptool-js:具有类似目的的新项目,但仍未编写为合适的库。

  • Adafruit Adafruit ESPTool:我们的灵感之源,非常感谢带头努力。 该实现是作为应用程序编写的,很难作为库使用。

esptool.js

npmnpmtypedocGitHub

TypeScript port of the esptool.

The esptool is originally written in python, and we have here ported it to TypeScript.

This implementation is used in the Toit Console to allow users to flash and monitor ESP32:

Flash ESP32 with web serial

Blog post on why we started this project: Flash your ESP32 from the browser using Web Serial.

Example

The code is written as a library, here is an examples showcasing how you can flash an ESP32 using the library:

export type Partition = {
  name: string;
  data: Uint8Array;
  offset: number;
};

// TODO: Here you have to specify the partitions you want to flash to the ESP32.
const partitions: Partition[] = [];

const port = new EsptoolSerial("/dev/tty.SLAB_USBtoUART", {
  baudRate: 115200,
  autoOpen: false,
});
await port.open();
try {
  const loader = new EspLoader(port, { debug: true, logger: console });
  options.logger.log("connecting...");
  await loader.connect();
  try {
    options.logger.log("connected");
    options.logger.log("writing device partitions");
    const chipName = await loader.chipName();
    const macAddr = await loader.macAddr();
    await loader.loadStub();
    await loader.setBaudRate(options.baudRate, 921600);

    if (options.erase) {
      options.logger.log("erasing device flash...");
      await loader.eraseFlash();
      options.logger.log("successfully erased device flash");
    }

    for (let i = 0; i < partitions.length; i++) {
      options.logger.log("\nWriting partition: " + partitions[i].name);
      await loader.flashData(partitions[i].data, partitions[i].offset, function (idx, cnt) {
        if (options.progressCallback) {
          options.progressCallback(partitions[i].name, idx, cnt);
        }
      });
      await sleep(100);
    }
    options.logger.log("successfully written device partitions");
    options.logger.log("flashing succeeded");
  } finally {
    await loader.disconnect();
  }
} finally {
  await port.close();
}

Development

To have automatic checks for copyright and MIT notices, run

$ git config core.hooksPath .githooks

If a file doesn't need a copyright/MIT notice, use the following to skip the check:

git commit --no-verify

Similar projects

  • Espressif esptool-js: new project with similar purpose, but still not written as a proper library.

  • Adafruit Adafruit ESPTool: the source of inspration for us, big shout-out thanks for spearheading the effort. The implementation is written as a application and hard to use as a library.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文