ARMmbed / ARMmbed/DAPLink

Interrupting USB connection can cause DAP response queue misalignment

Open
#1,089 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
2.8k
Forks
1.1k
Avg merge
3d 12h
Merged PRs (30d)
1

Description

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:
- https://github.com/microbit-foundation/DAPLink/issues/17
Opening this issue upstream to open a PR and link it.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure with a micro:bit V2.2 running 0256+ through MakeCode v7 and WebUSB, while observing the developer console. Trace the DAP response queue around an interrupted transfer and the subsequent SWJ_CLOCK commands; done means repeated USB disconnects and reconnects no longer produce stale, one-off responses or prevent WebUSB from connecting.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.