MCPcopy Index your code
hub / github.com/Moddable-OpenSource/moddable / beginProgramming

Method beginProgramming

tools/xsbug/esptool.js:391–458  ·  view source on GitHub ↗
(timeout = 20_000, doFlash = function(){})

Source from the content-addressed store, hash-verified

389 return result;
390 }
391 async beginProgramming(timeout = 20_000, doFlash = function(){}) {
392 const stop = timeout + Date.now();
393 let baud = this.#baudDownload ?? 921600;
394 let reset = this.#reset;
395
396 for (let pass = 0; pass < 2; pass++) {
397 await this.buildSerial(this.#baud);
398
399 const syncPayload = new Uint8Array(4 + 32);
400 syncPayload[0] = 0x07;
401 syncPayload[1] = 0x07;
402 syncPayload[2] = 0x12;
403 syncPayload[3] = 0x20;
404 for (let i = 0; i < 32; i++)
405 syncPayload[i + 4] = 0x55;
406 let synced = false;
407
408 syncLoop:
409 for (let retry = 0; retry < 5; retry++) {
410 if (reset) {
411 await doFlash(true);
412 this.#serial.set({DTR: false, RTS: true});
413
414 await delay(100);
415
416 this.#serial.set({DTR: true, RTS: false});
417
418 await doFlash(false);
419
420 await delay(50);
421
422 this.#serial.set({DTR: false});
423 }
424
425 for (let i = 0; i < 4; i++) {
426 if (Date.now() > stop)
427 break syncLoop;
428 this.#serial.purge();
429 this.command(Bootloader.SYNC, syncPayload.buffer);
430 const received = await this.getReply();
431 if (received && this.parseReply(received, Bootloader.SYNC)) {
432 synced = true;
433 break syncLoop;
434 }
435 }
436 }
437 if (!synced)
438 throw new Error("Unable to enter programming mode");
439
440 await this.deployStub(this.#loader);
441 console.log("change to baud rate of " + baud);
442 await this.changeBaud(baud, this.#baud);
443
444 if (("esp32" !== this.#mcu) || (undefined !== this.#baudDownload))
445 break;
446
447 try {
448 const DR_REG_SYSCON_BASE = 0x3ff66000;

Callers 1

DebugBehavior.jsFile · 0.80

Calls 12

buildSerialMethod · 0.95
commandMethod · 0.95
getReplyMethod · 0.95
parseReplyMethod · 0.95
deployStubMethod · 0.95
changeBaudMethod · 0.95
readRegisterMethod · 0.95
doFlashFunction · 0.85
delayFunction · 0.85
setMethod · 0.65
purgeMethod · 0.65
logMethod · 0.65

Tested by

no test coverage detected