Skip to content

Commit

Permalink
Fixes for radio bridge connection (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-robert authored Jul 26, 2024
1 parent bff05d7 commit 802f5ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/usb-device-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,22 @@ export class DAPWrapper {
// We wait on errors as immediately after flash the micro:bit won't be ready to respond
this._deviceId = await this.readMem32WaitOnError(FICR.DEVICE_ID_1);

this._pageSize = await this.cortexM.readMem32(FICR.CODEPAGESIZE);
this._numPages = await this.cortexM.readMem32(FICR.CODESIZE);
this._pageSize = await this.readMem32WaitOnError(FICR.CODEPAGESIZE);
this._numPages = await this.readMem32WaitOnError(FICR.CODESIZE);
}

async readMem32WaitOnError(register: number): Promise<number> {
let retries = 0;
let lastError: Error | undefined;
while (retries < 10) {
while (retries < 20) {
try {
return await this.cortexM.readMem32(register);
} catch (e) {
if (e instanceof Error) {
lastError = e;
if (/^Transfer/.test(e.message)) {
retries++;
await new Promise((resolve) => setTimeout(resolve, 10));
await new Promise((resolve) => setTimeout(resolve, 20));
} else {
throw e;
}
Expand Down
4 changes: 1 addition & 3 deletions lib/usb-radio-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ export class MicrobitRadioBridgeConnection
message: "Serial connect start",
});

if (this.delegate.status !== ConnectionStatus.CONNECTED) {
await this.delegate.connect();
}
await this.delegate.connect();

try {
this.serialSession = new RadioBridgeSerialSession(
Expand Down

0 comments on commit 802f5ea

Please sign in to comment.