Skip to content

Commit 802f5ea

Browse files
Fixes for radio bridge connection (#17)
1 parent bff05d7 commit 802f5ea

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

lib/usb-device-wrapper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,22 @@ export class DAPWrapper {
122122
// We wait on errors as immediately after flash the micro:bit won't be ready to respond
123123
this._deviceId = await this.readMem32WaitOnError(FICR.DEVICE_ID_1);
124124

125-
this._pageSize = await this.cortexM.readMem32(FICR.CODEPAGESIZE);
126-
this._numPages = await this.cortexM.readMem32(FICR.CODESIZE);
125+
this._pageSize = await this.readMem32WaitOnError(FICR.CODEPAGESIZE);
126+
this._numPages = await this.readMem32WaitOnError(FICR.CODESIZE);
127127
}
128128

129129
async readMem32WaitOnError(register: number): Promise<number> {
130130
let retries = 0;
131131
let lastError: Error | undefined;
132-
while (retries < 10) {
132+
while (retries < 20) {
133133
try {
134134
return await this.cortexM.readMem32(register);
135135
} catch (e) {
136136
if (e instanceof Error) {
137137
lastError = e;
138138
if (/^Transfer/.test(e.message)) {
139139
retries++;
140-
await new Promise((resolve) => setTimeout(resolve, 10));
140+
await new Promise((resolve) => setTimeout(resolve, 20));
141141
} else {
142142
throw e;
143143
}

lib/usb-radio-bridge.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ export class MicrobitRadioBridgeConnection
116116
message: "Serial connect start",
117117
});
118118

119-
if (this.delegate.status !== ConnectionStatus.CONNECTED) {
120-
await this.delegate.connect();
121-
}
119+
await this.delegate.connect();
122120

123121
try {
124122
this.serialSession = new RadioBridgeSerialSession(

0 commit comments

Comments
 (0)