Skip to content

Commit 2f99381

Browse files
Check serial baud rate before setting it & only set it if necessary. (#4953)
1 parent 8dc87a4 commit 2f99381

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

editor/flash.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,19 @@ class DAPWrapper implements pxt.packetio.PacketIOWrapper {
264264
return this.io.isConnecting() || (this.io.isConnected() && !this.initialized)
265265
}
266266

267+
private async getBaudRate() {
268+
const readSerialSettings = new Uint8Array([0x81]) // get serial settings
269+
const serialSettings = await this.dapCmd(readSerialSettings)
270+
const baud = (serialSettings[4] << 24)+ (serialSettings[3] << 16) + (serialSettings[2] << 8) + serialSettings[1]
271+
return baud
272+
}
273+
267274
private async setBaudRate() {
275+
const currentBaudRate = await this.getBaudRate()
276+
if (currentBaudRate === 115200) {
277+
log(`baud rate already set to 115200`)
278+
return
279+
}
268280
log(`set baud rate to 115200`)
269281
const baud = new Uint8Array(5)
270282
baud[0] = 0x82 // set baud

0 commit comments

Comments
 (0)