Skip to content

Commit ca1f325

Browse files
webusb: On serial connection check baud rate before setting it. (#1103)
Setting the baud rate makes DAPLink send a "break signal", which resets the target. This is triggered when switching tabs as it resets the user's micro:bits when the editor goes out of focus and active again.. We can avoid this reset by checking first the DAPLink serial settings and only set the baud rate if necessary.
1 parent bcc8f6a commit ca1f325

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: src/device/dap-wrapper.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ export class DAPWrapper {
112112
}
113113

114114
async startSerial(listener: (data: string) => void): Promise<void> {
115-
await this.daplink.setSerialBaudrate(115200);
115+
const currentBaud = await this.daplink.getSerialBaudrate();
116+
if (currentBaud !== 115200) {
117+
// Changing the baud rate causes a micro:bit reset, so only do it if necessary
118+
await this.daplink.setSerialBaudrate(115200);
119+
}
116120
this.daplink.on(DAPLink.EVENT_SERIAL_DATA, listener);
117121
await this.daplink.startSerialRead(1);
118122
}

0 commit comments

Comments
 (0)