pxt-microbit 4.1.44 → 4.1.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/built/editor.js CHANGED
@@ -3134,6 +3134,8 @@ function log(msg) {
3134
3134
  pxt.debug(`dap ${ts}: ${msg}`);
3135
3135
  }
3136
3136
  const logV = /webusbdbg=1/.test(window.location.href) ? log : (msg) => { };
3137
+ const setBaudRateOnConnection = !/webusbbaud=0/.test(window.location.href);
3138
+ const resetOnConnection = !/webusbreset=0/.test(window.location.href);
3137
3139
  function murmur3_core(data) {
3138
3140
  let h0 = 0x2F9BE6CC;
3139
3141
  let h1 = 0x1EC3A6C8;
@@ -3337,6 +3339,21 @@ class DAPWrapper {
3337
3339
  isConnecting() {
3338
3340
  return this.io.isConnecting() || (this.io.isConnected() && !this.initialized);
3339
3341
  }
3342
+ async setBaudRate() {
3343
+ log(`set baud rate to 115200`);
3344
+ const baud = new Uint8Array(5);
3345
+ baud[0] = 0x82; // set baud
3346
+ pxt.HF2.write32(baud, 1, 115200);
3347
+ await this.dapCmd(baud);
3348
+ // setting the baud rate on serial may reset NRF (depending on daplink version), so delay after
3349
+ await pxt.Util.delay(200);
3350
+ }
3351
+ async readPageSize() {
3352
+ const res = await this.readWords(0x10000010, 2);
3353
+ this.pageSize = res[0];
3354
+ this.numPages = res[1];
3355
+ log(`page size ${this.pageSize}, num pages ${this.numPages}`);
3356
+ }
3340
3357
  async reconnectAsync() {
3341
3358
  log(`reconnect`);
3342
3359
  this.initialized = false;
@@ -3362,20 +3379,15 @@ class DAPWrapper {
3362
3379
  const binVersion = stringResponse(r);
3363
3380
  log(`bin name: ${this.binName} v:${binVersion}`);
3364
3381
  pxt.tickEvent("hid.flash.connect", { codal: this.usesCODAL ? 1 : 0, daplink: daplinkVersion, bin: binVersion });
3365
- // set baud rate
3366
- const baud = new Uint8Array(5);
3367
- baud[0] = 0x82; // set baud
3368
- pxt.HF2.write32(baud, 1, 115200);
3369
- await this.dapCmd(baud);
3370
- // setting the baud rate on serial may reset NRF (depending on daplink version), so delay after
3371
- await pxt.Util.delay(200);
3382
+ if (setBaudRateOnConnection)
3383
+ await this.setBaudRate();
3372
3384
  // only init after setting baud rate, in case we got reset
3373
3385
  await this.cortexM.init();
3374
- await this.cortexM.reset(true);
3375
- const res = await this.readWords(0x10000010, 2);
3376
- this.pageSize = res[0];
3377
- this.numPages = res[1];
3378
- log(`page size ${this.pageSize}, num pages ${this.numPages}`);
3386
+ if (resetOnConnection) {
3387
+ log(`reset cortex`);
3388
+ await this.cortexM.reset(true);
3389
+ }
3390
+ await this.readPageSize();
3379
3391
  // jacdac needs to run to set the xchg address
3380
3392
  await this.checkStateAsync(true);
3381
3393
  await this.initJacdac(connectionId);