Added support to change baudrate to higher values.
Signed-off-by: Amey Inamdar <amey.inamdar@espressif.com>
This commit is contained in:
parent
c60c067fa1
commit
c59f2e1861
25
ESPLoader.js
25
ESPLoader.js
@ -602,6 +602,7 @@ class ESPLoader {
|
|||||||
ESP_SPI_FLASH_MD5 = 0x13;
|
ESP_SPI_FLASH_MD5 = 0x13;
|
||||||
ESP_READ_REG = 0x0A;
|
ESP_READ_REG = 0x0A;
|
||||||
ESP_SPI_ATTACH = 0x0D;
|
ESP_SPI_ATTACH = 0x0D;
|
||||||
|
ESP_CHANGE_BAUDRATE = 0x0F;
|
||||||
|
|
||||||
// Only Stub supported commands
|
// Only Stub supported commands
|
||||||
ESP_ERASE_FLASH = 0xD0;
|
ESP_ERASE_FLASH = 0xD0;
|
||||||
@ -620,8 +621,9 @@ class ESPLoader {
|
|||||||
|
|
||||||
DETECTED_FLASH_SIZES = {0x12: '256KB', 0x13: '512KB', 0x14: '1MB', 0x15: '2MB', 0x16: '4MB', 0x17: '8MB', 0x18: '16MB'};
|
DETECTED_FLASH_SIZES = {0x12: '256KB', 0x13: '512KB', 0x14: '1MB', 0x15: '2MB', 0x16: '4MB', 0x17: '8MB', 0x18: '16MB'};
|
||||||
|
|
||||||
constructor(transport, terminal) {
|
constructor(transport, baudrate, terminal) {
|
||||||
this.transport = transport;
|
this.transport = transport;
|
||||||
|
this.baudrate = baudrate;
|
||||||
this.terminal = terminal;
|
this.terminal = terminal;
|
||||||
this.IS_STUB = false;
|
this.IS_STUB = false;
|
||||||
this.chip = null;
|
this.chip = null;
|
||||||
@ -750,11 +752,8 @@ class ESPLoader {
|
|||||||
|
|
||||||
read_reg = async({addr, timeout = 3000} = {}) => {
|
read_reg = async({addr, timeout = 3000} = {}) => {
|
||||||
var val, data;
|
var val, data;
|
||||||
console.log("read reg " + addr + " " + timeout);
|
|
||||||
var pkt = this._int_to_bytearray(addr);
|
var pkt = this._int_to_bytearray(addr);
|
||||||
val = await this.command({op:this.ESP_READ_REG, data:pkt, timeout:timeout});
|
val = await this.command({op:this.ESP_READ_REG, data:pkt, timeout:timeout});
|
||||||
console.log("Read reg resp");
|
|
||||||
console.log(val);
|
|
||||||
return val[0];
|
return val[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1222,6 +1221,22 @@ class ESPLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
change_baud = async() => {
|
||||||
|
this.log("Changing baudrate to " + this.baudrate);
|
||||||
|
console.log("Changing baudrate to " + this.baudrate);
|
||||||
|
let second_arg = this.IS_STUB ? this.transport.baudrate : 0;
|
||||||
|
let pkt = this._appendArray(this._int_to_bytearray(this.baudrate), this._int_to_bytearray(second_arg));
|
||||||
|
let resp = await this.command({op:this.ESP_CHANGE_BAUDRATE, data:pkt});
|
||||||
|
this.log("Changed");
|
||||||
|
await this.transport.disconnect();
|
||||||
|
await this._sleep(50);
|
||||||
|
await this.transport.connect({baud:this.baudrate});
|
||||||
|
try {
|
||||||
|
await this.transport.rawRead({timeout:500});
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
main_fn = async () => {
|
main_fn = async () => {
|
||||||
await this.detect_chip();
|
await this.detect_chip();
|
||||||
if (this.chip == null) {
|
if (this.chip == null) {
|
||||||
@ -1238,6 +1253,8 @@ class ESPLoader {
|
|||||||
|
|
||||||
await this.run_stub();
|
await this.run_stub();
|
||||||
|
|
||||||
|
await this.change_baud();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flash_size_bytes = function(flash_size) {
|
flash_size_bytes = function(flash_size) {
|
||||||
|
@ -19,6 +19,13 @@
|
|||||||
<div>
|
<div>
|
||||||
<div id="program">
|
<div id="program">
|
||||||
<h2> Program </h2>
|
<h2> Program </h2>
|
||||||
|
<label for="baudrates">Baudrate:</label>
|
||||||
|
<select name="baudrates" id="baudrates">
|
||||||
|
<option value="921600">921600</option>
|
||||||
|
<option value="460800">460800</option>
|
||||||
|
<option value="230400">230400</option>
|
||||||
|
<option value="115200">115200</option>
|
||||||
|
</select>
|
||||||
<input class="button" type="button" id="connectButton" value="Connect" />
|
<input class="button" type="button" id="connectButton" value="Connect" />
|
||||||
<input class="button" type="button" id="disconnectButton" value="Disconnect" />
|
<input class="button" type="button" id="disconnectButton" value="Disconnect" />
|
||||||
<div id="files">
|
<div id="files">
|
||||||
|
8
index.js
8
index.js
@ -1,3 +1,4 @@
|
|||||||
|
const baudrates = document.getElementById("baudrates");
|
||||||
const connectButton = document.getElementById("connectButton");
|
const connectButton = document.getElementById("connectButton");
|
||||||
const disconnectButton = document.getElementById("disconnectButton");
|
const disconnectButton = document.getElementById("disconnectButton");
|
||||||
const resetButton = document.getElementById("resetButton");
|
const resetButton = document.getElementById("resetButton");
|
||||||
@ -109,18 +110,16 @@ connectButton.onclick = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
esploader = new ESPLoader(transport, term);
|
esploader = new ESPLoader(transport, baudrates.value, term);
|
||||||
connected = true;
|
connected = true;
|
||||||
|
|
||||||
await esploader.main_fn();
|
await esploader.main_fn();
|
||||||
|
|
||||||
console.log("Flash ID 1");
|
|
||||||
await esploader.flash_id();
|
await esploader.flash_id();
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Settings done");
|
console.log("Settings done");
|
||||||
|
baudrates.style.display = "none";
|
||||||
connectButton.style.display = "none";
|
connectButton.style.display = "none";
|
||||||
disconnectButton.style.display = "initial";
|
disconnectButton.style.display = "initial";
|
||||||
filesDiv.style.display = "initial";
|
filesDiv.style.display = "initial";
|
||||||
@ -151,6 +150,7 @@ disconnectButton.onclick = async () => {
|
|||||||
await transport.disconnect();
|
await transport.disconnect();
|
||||||
term.clear();
|
term.clear();
|
||||||
connected = false;
|
connected = false;
|
||||||
|
baudrates.style.display = "initial";
|
||||||
connectButton.style.display = "initial";
|
connectButton.style.display = "initial";
|
||||||
disconnectButton.style.display = "none";
|
disconnectButton.style.display = "none";
|
||||||
filesDiv.style.display = "none";
|
filesDiv.style.display = "none";
|
||||||
|
23
webserial.js
23
webserial.js
@ -146,18 +146,33 @@ class Transport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rawRead = async () => {
|
rawRead = async ({timeout=0} = {}) => {
|
||||||
let reader = this.device.readable.getReader();
|
let reader = this.device.readable.getReader();
|
||||||
let done = false;
|
let done = false;
|
||||||
let value = new Uint8Array(0);
|
let value = new Uint8Array(0);
|
||||||
|
|
||||||
this.reader = reader;
|
this.reader = reader;
|
||||||
|
if (timeout > 0) {
|
||||||
|
t = setTimeout(function() {
|
||||||
|
reader.cancel();
|
||||||
|
reader.releaseLock();
|
||||||
|
}, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
let o = await reader.read();
|
let o = await reader.read();
|
||||||
this.reader = null;
|
this.reader = null;
|
||||||
done = o.done;
|
done = o.done;
|
||||||
|
|
||||||
|
if (done) {
|
||||||
|
throw("timeout");
|
||||||
|
} else {
|
||||||
|
if (timeout > 0) {
|
||||||
|
clearTimeout(t);
|
||||||
|
}
|
||||||
reader.releaseLock();
|
reader.releaseLock();
|
||||||
return o.value;
|
return o.value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setRTS = async (state) => {
|
setRTS = async (state) => {
|
||||||
await this.device.setSignals({requestToSend:state});
|
await this.device.setSignals({requestToSend:state});
|
||||||
@ -166,9 +181,9 @@ class Transport {
|
|||||||
setDTR = async (state) => {
|
setDTR = async (state) => {
|
||||||
await this.device.setSignals({dataTerminalReady:state});
|
await this.device.setSignals({dataTerminalReady:state});
|
||||||
}
|
}
|
||||||
connect = async () => {
|
connect = async ({baud=115200} = {}) => {
|
||||||
await this.device.open({baudRate: 115200});
|
await this.device.open({baudRate: baud});
|
||||||
this.baudrate = 115200;
|
this.baudrate = baud;
|
||||||
}
|
}
|
||||||
disconnect = async () => {
|
disconnect = async () => {
|
||||||
if (this.reader !== null) {
|
if (this.reader !== null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user