Fix flashing after microbit reset (#1108)
* Fix flashing after microbit reset * Remove debug out
This commit is contained in:
parent
51a485580b
commit
9f87ec52db
@ -34,41 +34,18 @@ namespace pxt.editor {
|
|||||||
packetIo: HF2.PacketIO;
|
packetIo: HF2.PacketIO;
|
||||||
cmsisdap: any;
|
cmsisdap: any;
|
||||||
flashing = true;
|
flashing = true;
|
||||||
|
pbuf = new U.PromiseBuffer<Uint8Array>();
|
||||||
private useSerial = true;
|
private useSerial = true;
|
||||||
|
|
||||||
constructor(h: HF2.PacketIO) {
|
constructor(h: HF2.PacketIO) {
|
||||||
this.packetIo = h;
|
this.packetIo = h;
|
||||||
let pbuf = new U.PromiseBuffer<Uint8Array>();
|
|
||||||
|
|
||||||
/*
|
|
||||||
let sendMany = (cmds: Uint8Array[]) => {
|
|
||||||
return h.talksAsync(cmds.map(c => ({ cmd: 0, data: c })));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!h.talksAsync)
|
|
||||||
sendMany = null;
|
|
||||||
*/
|
|
||||||
|
|
||||||
let dev = new DapJS.DAP({
|
|
||||||
write: writeAsync,
|
|
||||||
close: this.disconnectAsync,
|
|
||||||
read: readAsync,
|
|
||||||
//sendMany: sendMany
|
|
||||||
});
|
|
||||||
this.cmsisdap = (dev as any).dap;
|
|
||||||
this.cortexM = new DapJS.CortexM(dev);
|
|
||||||
|
|
||||||
h.onData = buf => {
|
h.onData = buf => {
|
||||||
pbuf.push(buf);
|
// console.log("RD: " + pxt.Util.toHex(buf))
|
||||||
|
this.pbuf.push(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeAsync(data: ArrayBuffer) {
|
this.allocDAP()
|
||||||
return h.sendPacketAsync(new Uint8Array(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
function readAsync() {
|
|
||||||
return pbuf.shiftAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
const readSerial = () => {
|
const readSerial = () => {
|
||||||
if (!this.useSerial) {
|
if (!this.useSerial) {
|
||||||
@ -105,15 +82,50 @@ namespace pxt.editor {
|
|||||||
readSerial()
|
readSerial()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private allocDAP() {
|
||||||
|
/*
|
||||||
|
let sendMany = (cmds: Uint8Array[]) => {
|
||||||
|
return h.talksAsync(cmds.map(c => ({ cmd: 0, data: c })));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!h.talksAsync)
|
||||||
|
sendMany = null;
|
||||||
|
*/
|
||||||
|
|
||||||
|
let dev = new DapJS.DAP({
|
||||||
|
write: writeAsync,
|
||||||
|
close: this.disconnectAsync,
|
||||||
|
read: readAsync,
|
||||||
|
//sendMany: sendMany
|
||||||
|
});
|
||||||
|
this.cmsisdap = (dev as any).dap;
|
||||||
|
this.cortexM = new DapJS.CortexM(dev);
|
||||||
|
|
||||||
|
let h = this.packetIo
|
||||||
|
let pbuf = this.pbuf
|
||||||
|
|
||||||
|
function writeAsync(data: ArrayBuffer) {
|
||||||
|
// console.log("WR: " + pxt.Util.toHex(new Uint8Array(data)));
|
||||||
|
return h.sendPacketAsync(new Uint8Array(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
function readAsync() {
|
||||||
|
return pbuf.shiftAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
reconnectAsync(first: boolean) {
|
reconnectAsync(first: boolean) {
|
||||||
|
// configure serial at 115200
|
||||||
if (!first)
|
if (!first)
|
||||||
return this.packetIo.reconnectAsync()
|
return this.packetIo.reconnectAsync()
|
||||||
// configure serial at 115200
|
.then(() => this.allocDAP())
|
||||||
.then(() => this.cmsisdap.cmdNums(0x82, [0x00, 0xC2, 0x01, 0x00]))
|
|
||||||
.then(() => {}, err => { this.useSerial = false })
|
|
||||||
.then(() => this.cortexM.init())
|
.then(() => this.cortexM.init())
|
||||||
|
.then(() => this.cmsisdap.cmdNums(0x82, [0x00, 0xC2, 0x01, 0x00]))
|
||||||
|
.then(() => { }, err => { this.useSerial = false })
|
||||||
else
|
else
|
||||||
return this.cortexM.init();
|
return this.cortexM.init()
|
||||||
|
.then(() => this.cmsisdap.cmdNums(0x82, [0x00, 0xC2, 0x01, 0x00]))
|
||||||
|
.then(() => { }, err => { this.useSerial = false })
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnectAsync() {
|
disconnectAsync() {
|
||||||
@ -347,7 +359,8 @@ namespace pxt.editor {
|
|||||||
.then(w => {
|
.then(w => {
|
||||||
wrap = w
|
wrap = w
|
||||||
log("reset")
|
log("reset")
|
||||||
return wrap.cortexM.reset(true)
|
return wrap.cortexM.init()
|
||||||
|
.then(() => wrap.cortexM.reset(true))
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
log("trying re-connect")
|
log("trying re-connect")
|
||||||
return wrap.reconnectAsync(false)
|
return wrap.reconnectAsync(false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user