Open microbit-carlos opened 1 year ago
Could not repeat this with V2.00 + 0258-beta1_kl27z_microbit_if_crc_1c60ddb_gcc.hex. Unplugging causes one of
Failed to execute 'transferOut' on 'USBDevice': A transfer error has occurred.
Failed to execute 'transferIn' on 'USBDevice': A transfer error has occurred.
and once there was Bad response for 5 -> 131 at CMSISDAP.
which did cause a problem, but it went away after a retry.
makecode.microbit.org-1676231506869.log
I cannot replicate this in the Python Editor V2, but it does replicate quite easily in Python Editor V3 and MakeCode, so that points at being related to WebUSB serial being pulled.
Commenting out these lines from the Python Editor V3 "resolves" the issue, so I that confirms it's related to that: https://github.com/microbit-foundation/python-editor-v3/blob/c5b20f13fc66cb8058c00ba4fd1c9325f108a02d/src/device/webusb.ts#L268-L273
With V2.00 and 0258beta2, I saw none of the problems switching between power bank and PC USB with a battery connected given in https://github.com/microbit-foundation/DAPLink-microbit/issues/146.
After testing that 10-20 times, my first attempt to disconnect and connect WebUSB in MakeCode failed
Uncaught (in promise) Error: Bad response for 5 -> 131
at CMSISDAP.<anonymous> (editor.js:2391:35)
at step (editor.js:2317:23)
at Object.next (editor.js:2298:53)
at fulfilled (editor.js:2289:58)
When I power cycled micro:bit, it connected, and I flashed a program.
Repeatedly reconnecting the USB cable and flashing a program, the same error appears in the console every few (maybe 5-10) connections, the micro:bit logo next to Download keeps pulsing, but flashing always works and appears to fix the connection, though the console says:
Found an ARM Cortex-M4 editor.js:3325 try to access codal information before it is computed The times when the console shows Bad response for 5 -> 131 correspond to the times that reconnecting doesn't cause a reset.
With a battery powered V2.0, reconnecting USB still seems to cause a glitch in MakeCode. In previous tests I said "WebUSB may be broken until micro:bit is power cycled", but with 0258beta2, all I see is that the MakeCode Download button continues pulsing. Ignoring the pulsing, and downloading anyway always seems to work, as does power cycling or simply reconnecting.
Python seems to repeat the pairing process whenever the USB is disconnected, instead of trying to reconnect, so doesn't see a problem. The only way I could trigger a problem in Python was to add a switch between MakeCode and Python.
A quick note to add that response for command 131 is the ID_DAP_Vendor3
0x83, which in DAPLink is used for ID_DAP_UART_Read
, which is reading serial data.
This is likely because the USB cable was disconnected between the editors sending a 131 command, to read serial data (as the Python Editor and MakeCode constantly do in the background) and DAPLink being able to send the respond back. So, then on the next connection, the editors send a new command, but DAPLink responds with what it already had in its buffer from the previous session.
Adding a bit of extra logging to the Python Editor we can see the following set of events;
ID_DAP_Vendor3
-> read serial data), but could be other DAP commandsIdeally we could find a way to reset the DAPLink state/buffers with existing DAP commands, but we haven't looked into this yet.
One possible workaround we could try to implement in the editors (to avoid having to ask users to update the micro:bit firmware with an updated DAPLink) could be the following:
Thanks Carlos. Reading through this thread I can't quite determine whether 0258-beta3 fixes this, or whether we still think this is outstanding in DAPLink?
This is still outstanding in DAPLink.
With a micro:bit V2.2 running 0256 or 0257:
This is not replicable with V2.0 running DAPLink 0255.
Current reports: