support built-in USB-JTAG-Serial

This commit is contained in:
Legend 2023-01-12 17:04:58 +01:00 committed by Ivan Grokhotkov
parent 238d6ad410
commit 91472669b4
No known key found for this signature in database
GPG Key ID: 1E050E141B280628
2 changed files with 51 additions and 18 deletions

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,6 +280,25 @@ 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") {
if (this.transport.get_pid() === this.USB_JTAG_SERIAL_PID) {
// Custom reset sequence, which is required when the device
// is connecting via its USB-JTAG-Serial peripheral
await this.transport.setRTS(false);
await this.transport.setDTR(false);
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.setDTR(false);
await this.transport.setRTS(true); await this.transport.setRTS(true);
await this._sleep(100); await this._sleep(100);
@ -293,6 +314,7 @@ export class ESPLoader {
await this._sleep(50); await this._sleep(50);
await this.transport.setDTR(false); await this.transport.setDTR(false);
} }
}
let i = 0; let i = 0;
let keepReading = true; let keepReading = true;
while (keepReading) { while (keepReading) {
@ -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 });
} }