Skip to content

WebUSB: On serial connection check baud rate before setting it. #1103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2023
Merged

WebUSB: On serial connection check baud rate before setting it. #1103

merged 1 commit into from
Feb 27, 2023

Conversation

microbit-carlos
Copy link
Contributor

@microbit-carlos microbit-carlos commented Feb 17, 2023

Setting the baud rate makes DAPLink send a "break signal", which basically resets the target.

This is noticeable to the Python Editor users when switching tabs as it makes their programme reset.

We can avoid this reset by checking first the DAPLink serial settings and only set the baud rate if necessary.

For devices with DAPLink 0257 and newer (V2.2) the default baud rate is set to 115200 already, so they will never reset on WebUSB connection. For devices with older DAPLink versions (V1 and V2.00) the editor will set the baud rate on first connection (triggering a reset), but won't have to set it again until the device is unplugged.

I tried to replicate the Bad response for 8 -> 17 issue for about 5 minutes changing tabs and refreshing-and-reconnecting and it seems fine (and also checked that it's really easy to replicate in the Python Editor v2).

Copy link
Collaborator

@microbit-robert microbit-robert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Tested with v1, v2.00, and v2.21, and the program no longer resets on switching tabs. Some minor changes requested via comments.

@microbit-carlos
Copy link
Contributor Author

Awesome, thanks @microbit-robert!
I've left the GitHub web interface commits assuming this PR will be squashed when merged, but let me know if you prefer the branch to be squashed beforehand instead.

@microbit-carlos
Copy link
Contributor Author

microbit-carlos commented Feb 27, 2023

Ah, there are merge conflicts and it needs to be rebased anyway, I'll do that.

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.
@microbit-carlos
Copy link
Contributor Author

Okay, should be ready for merge now 👍

Copy link
Collaborator

@microbit-robert microbit-robert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@microbit-robert microbit-robert merged commit ca1f325 into microbit-foundation:main Feb 27, 2023
@microbit-carlos microbit-carlos deleted the serial-baud-reset branch February 27, 2023 17:33
@microbit-matt-hillsdon
Copy link
Collaborator

Now we've done this it might be worth trying to avoid resetting the serial console (i.e clearing scrollback) in this scenario as that's what most folks have been complaining about. Needs some thought though as serial output that doesn't match the running program is confusing (e.g. we might show a clickable traceback for it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants