Skip to content

Commit

Permalink
Stub already running detection (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkendall64 authored May 31, 2024
1 parent 22e115b commit 67e327a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/esploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export class ESPLoader {
private terminal?: IEspLoaderTerminal;
private romBaudrate = 115200;
private debugLogging = false;
private syncStubDetected = false;

/**
* Create a new ESPLoader to perform serial communication
Expand Down Expand Up @@ -576,6 +577,10 @@ export class ESPLoader {

try {
const resp = await this.command(0x08, cmd, undefined, undefined, 100);
// ROM bootloaders send some non-zero "val" response. The flasher stub sends 0.
// If we receive 0 then it probably indicates that the chip wasn't or couldn't be
// reset properly and esptool is talking to the flasher stub.
this.syncStubDetected = this.syncStubDetected && resp[0] === 0;
return resp;
} catch (e) {
this.debug("Sync err " + e);
Expand Down Expand Up @@ -617,6 +622,7 @@ export class ESPLoader {
await this._sleep(50);
}
this.transport.slipReaderEnabled = true;
this.syncStubDetected = true;
i = 7;
while (i--) {
try {
Expand Down Expand Up @@ -1140,6 +1146,11 @@ export class ESPLoader {
* @returns {ROM} The Chip ROM
*/
async runStub(): Promise<ROM> {
if (this.syncStubDetected) {
this.info("Stub is already running. No upload is necessary.");
return this.chip;
}

this.info("Uploading stub...");
let decoded = atob(this.chip.ROM_TEXT);
let chardata = decoded.split("").map(function (x) {
Expand Down

0 comments on commit 67e327a

Please sign in to comment.