Merge pull request #54 from liux-pro/main

support build-in USB-JTAG-Serial
This commit is contained in:
Ivan Grokhotkov 2023-01-12 17:55:39 +01:00 committed by GitHub
commit ce8f8da11a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 19 deletions

View File

@ -11,7 +11,7 @@
/> />
<link rel="icon" href="favicon.ico" /> <link rel="icon" href="favicon.ico" />
<script src="https://cdn.jsdelivr.net/npm/xterm@4.19.0/lib/xterm.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/xterm@4.19.0/lib/xterm.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/crypto-js@4.1.1/index.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/crypto-js@4.1.1/crypto-js.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head> </head>

View File

@ -84,6 +84,8 @@ export class ESPLoader {
0x18: "16MB", 0x18: "16MB",
}; };
USB_JTAG_SERIAL_PID = 0x1001;
chip: ROM; chip: ROM;
IS_STUB: boolean; IS_STUB: boolean;
FLASH_WRITE_SIZE: number; FLASH_WRITE_SIZE: number;
@ -278,20 +280,40 @@ export class ESPLoader {
async _connect_attempt(mode = "default_reset", esp32r0_delay = false) { async _connect_attempt(mode = "default_reset", esp32r0_delay = false) {
this.log("_connect_attempt " + mode + " " + esp32r0_delay); this.log("_connect_attempt " + mode + " " + esp32r0_delay);
if (mode !== "no_reset") { if (mode !== "no_reset") {
await this.transport.setDTR(false); if (this.transport.get_pid() === this.USB_JTAG_SERIAL_PID) {
await this.transport.setRTS(true); // Custom reset sequence, which is required when the device
await this._sleep(100); // is connecting via its USB-JTAG-Serial peripheral
if (esp32r0_delay) { await this.transport.setRTS(false);
//await this._sleep(1200); await this.transport.setDTR(false);
await this._sleep(2000); await this._sleep(100);
await this.transport.setDTR(true);
await this.transport.setRTS(false);
await this._sleep(100);
await this.transport.setRTS(true);
await this.transport.setDTR(false);
await this.transport.setRTS(true);
await this._sleep(100);
await this.transport.setRTS(false);
await this.transport.setDTR(false);
} else {
await this.transport.setDTR(false);
await this.transport.setRTS(true);
await this._sleep(100);
if (esp32r0_delay) {
//await this._sleep(1200);
await this._sleep(2000);
}
await this.transport.setDTR(true);
await this.transport.setRTS(false);
if (esp32r0_delay) {
//await this._sleep(400);
}
await this._sleep(50);
await this.transport.setDTR(false);
} }
await this.transport.setDTR(true);
await this.transport.setRTS(false);
if (esp32r0_delay) {
//await this._sleep(400);
}
await this._sleep(50);
await this.transport.setDTR(false);
} }
let i = 0; let i = 0;
let keepReading = true; let keepReading = true;
@ -999,22 +1021,22 @@ export class ESPLoader {
} }
async hard_reset() { async hard_reset() {
this.transport.setRTS(true); // EN->LOW await this.transport.setRTS(true); // EN->LOW
await this._sleep(100); await this._sleep(100);
this.transport.setRTS(false); await this.transport.setRTS(false);
} }
async soft_reset() { async soft_reset() {
if (!this.IS_STUB) { if (!this.IS_STUB) {
// "run user code" is as close to a soft reset as we can do // "run user code" is as close to a soft reset as we can do
this.flash_begin(0, 0); await this.flash_begin(0, 0);
this.flash_finish(false); await this.flash_finish(false);
} else if (this.chip.CHIP_NAME != "ESP8266") { } else if (this.chip.CHIP_NAME != "ESP8266") {
throw new ESPError("Soft resetting is currently only supported on ESP8266"); throw new ESPError("Soft resetting is currently only supported on ESP8266");
} else { } else {
// running user code from stub loader requires some hacks // running user code from stub loader requires some hacks
// in the stub loader // in the stub loader
this.command(this.ESP_RUN_USER_CODE, undefined, undefined, false); await this.command(this.ESP_RUN_USER_CODE, undefined, undefined, false);
} }
} }
} }

View File

@ -12,6 +12,10 @@ class Transport {
: ""; : "";
} }
get_pid() {
return this.device.getInfo().usbProductId;
}
slip_writer(data: Uint8Array) { slip_writer(data: Uint8Array) {
let count_esc = 0; let count_esc = 0;
let i = 0, let i = 0,
@ -181,11 +185,18 @@ class Transport {
} }
} }
_DTR_state = false;
async setRTS(state: boolean) { async setRTS(state: boolean) {
await this.device.setSignals({ requestToSend: state }); await this.device.setSignals({ requestToSend: state });
// # Work-around for adapters on Windows using the usbser.sys driver:
// # generate a dummy change to DTR so that the set-control-line-state
// # request is sent with the updated RTS state and the same DTR state
// Referenced to esptool.py
await this.setDTR(this._DTR_state);
} }
async setDTR(state: boolean) { async setDTR(state: boolean) {
this._DTR_state = state;
await this.device.setSignals({ dataTerminalReady: state }); await this.device.setSignals({ dataTerminalReady: state });
} }