Skip to content

Interrupting USB connection can cause DAP response queue misalignment #1089

Open
@microbit-carlos

Description

@microbit-carlos

Tested with the latest code in the main branch and replicable with 0255 forward (not tested with older versions).

During a WebUSB connection, if the a transfer is interrupted before the DAPLink can send a DAP response (for example, by having a battery connected and yanking the USB cable), the next DAPJs connections process will fail (it establishes the connection and then sends a couple of DAP commands, like the SWJ_CLOCK).
This is because the DAP queue incorrectly responds to the first command with the unsent data from the previous connection. This leaves to the DAP queue to always respond with stale data, being "one off".

To replicate with a micro:bit V2.2 running 0256+:

  • Connect a battery pack
  • Connect the USB cable
  • Open MakeCode v7 https://makecode.microbit.org/v7#editor
    • The MakeCode editor constantly checks in the background if there is any UART data to read
  • Open the developer console
  • Connect via WebUSB and flash
  • Try multiple times: Disconnect and reconnect the USB cable
    • After inserting the USB cable, MakeCode should try to automatically reconnect WebUSB. Wait until the micro:bit logo on the "Download" button stops moving (it animates during WebUSB connection)
    • Every time the cable is disconnected at this point it should print an error in the console, this indicates a USB transfer was interrupted before the response was received.
  • Eventually, after a few reconnections the the WebUSB connection will throw an error on the console and won't connect.

We were familiar with this issue for a while, and was reported here:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions