Skip to content
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

Fix abrupt USB disconnection leaving stale data in DAP queue buffers. #1090

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

microbit-carlos
Copy link
Contributor

@microbit-carlos microbit-carlos commented Jan 28, 2025

Clearing the buffers in the USB_DISCONNECTING state, which then moves to the USB_DISCONNECTED state.

The USB_DISCONNECTING state was never used, in the current codebase nor the initial repo commit (well, second commit, first release): bdacee7 (this .patch URL is easier to search in-browser)

It looks like this state might have been initially designed as a way to trigger a USB disconnection from the interface chip, as it manually set usbd_connect(0) to disconnect.
As it was never used it's now the pre-disconnected state to run code only once on state change:
connected->disconnecting->disconnected

Fixes #1089

It was cleaner to do this as a "disconnecting" stage, instead of inside the current "connecting". This is because "connecting" runs during startup, which sets usbd_connect(1), and that could have negative effects (port dependent) when switching from "disconnected" to "connected" as at that point USB is already fully running.

Clearing the buffers in the USB_DISCONNECTING state, which then
moves to the USB_DISCONNECTED state.

The USB_DISCONNECTING state was never used, in the current codebase
nor the initial repo commit (well, second commit, first release):
bdacee7

It looks like this state might have been initialy designed as a way
to trigger a USB disconnection from the interface chip, as it
manually set usbd_connect(0) to disconnect.
As it was never used it's now the pre-disconnected state to run
code only once on state change:
connected->disconnecting->disconnected

Fixes ARMmbed#1089
@microbit-carlos microbit-carlos marked this pull request as draft January 29, 2025 19:49
@microbit-carlos
Copy link
Contributor Author

I've found an issue in this PR with the KL27 of the micro:bit V2 + battery pack, where sometimes inserting the USB cable doesn't start the USB connection with the PC (might be related to the voltage monitoring interrupt, which is meant to trigger this).

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.

Interrupting USB connection can cause DAP response queue misalignment
1 participant