microsoft / pxt-microbit

A Blocks / JavaScript code editor for the micro:bit built on Microsoft MakeCode
https://makecode.microbit.org
Other
726 stars 638 forks source link

getting 521 from Daplink on copy of Hex file #5393

Closed tballmsft closed 9 months ago

tballmsft commented 1 year ago

After updating Windows 11 (build 22631, 10.0.22631) , I am still getting the 521 Daplink error when copying a hex file (produced by arcade.makecode.com) to the micro:bit V2. This affects the experience with the three Arcade shields on Windows. The problem is reproducible on makecode.microbit.org, but only with extremely large programs. Also, all the HEX files produced below do transfer fine when copied from a Chromebook to micro:bit V2, so it appears we still have a problem with Windows. 

Repro via command line

  1. git clone https://github.com/microsoft/microcode
  2. install makecode/mkc
  3. mkc
  4. go to built/n3
  5. plug in micro:bit
  6. copy binary.hex to micro:bit drive
  7. If the copy happens quickly (< 5 seconds) you will get the 521

Repro via https://arcade.makecode.com

  1. import https://github.com/microsoft/microcode
  2. choose any of the arcade shields for micro:bit
  3. click download
  4. copy arcade-microcode.hex to micro:bit drive
tballmsft commented 1 year ago

Here are hex files compiled with arcade.makecode.com for microcode and space-destroyer - both files sometimes don't get copied. hex_files.zip

tballmsft commented 1 year ago

I see the same problem when I try download the space-destroyer game: https://arcade.makecode.com/blocks-games/space-destroyer

tballmsft commented 1 year ago

Try this: https://makecode.microbit.org/_9KKHE4WyyUM3

It's a very large micro:bit program that causes makecode.microbit.org to generate a HEX file that will 521 (it is too large for V1, so use a V2).

Michal points out that the HEX file format generated by makecode.microbit.org is different than the one generated by arcade.makecode.com

abchatra commented 1 year ago

@microbit-carlos can you please investigate this issue. This may be different than windows bug.

microbit-carlos commented 1 year ago

Is this an occasional DAPLink 5xx error on Windows 11, or does it happen on every flash?

I've flashed the hex files from the zip file in https://github.com/microsoft/pxt-microbit/issues/5393#issuecomment-1799766528, 3 times each on macOS 12 and couldn't replicate.

tballmsft commented 1 year ago

It happens about 50% of the time on Windows. It doesn't happen at all on ChromeBook. It is a windows-only problem, IMHO.

microbit-carlos commented 1 year ago

And the problem is not replicable with hex files generated from https://makecode.microbit.org ?

I guess arcade doesn't generate Universal Hex files, so when the those files are 1.2MBs it's all for V2 (in micro:bit MakeCode with Universal Hex, 1.2MB files are normal, but half the file is ignored), maybe the issue is more replicable with these large files.

Could we generate a file of similar size in https://makecode.microbit.org/?compile=csv---mbcodal (with that flag it generates V2 only hex files) to check if that's replicable there?

tballmsft commented 1 year ago

Right, Arcade doesn't generate Universal Hex files. The problem can be reproduced with makecode.microbit.org using this large program I created with the help of ChatGPT (just kidding, I used Excel and regexp): https://makecode.microbit.org/_9KKHE4WyyUM3

This file is too large for V1, but fits in V2. A dialog will pop-up telling you it doesn't fit in V1.

abchatra commented 1 year ago

@microbit-carlos try on windows 11 and see if you are able to reproduce this.

eanders-ms commented 1 year ago

FWIW, here are my results when I try to copy the hex file generated by @tballmsft's large microbit program "largeSwitch":

OS: Windows 11 (Build 22631.2506) Microbit: V2.00 Method of hex generation: Import the above project to makecode.microbit.org, then download as file. Method of file copy: drag/drop to the MICROBIT drive in File Explorer.

Observations from ten copy operations:

DETAILS.TXT:

# DAPLink Firmware - see https://mbed.com/daplink
Unique ID: 9904360258434e45001d400e00000035000000009796990b
HIC ID: 9796990b
Auto Reset: 1
Automation allowed: 0
Overflow detection: 0
Incompatible image detection: 1
Page erasing: 0
Daplink Mode: Interface
Interface Version: 0255
Bootloader Version: 0254
Git SHA: 1436bdcc67029fdfc0ff03b73e12045bb6a9f272
Local Mods: 0
USB Interfaces: MSD, CDC, HID, WebUSB
Bootloader CRC: 0x23cc2063
Interface CRC: 0x5b5cc0f5
Remount count: 7
URL: https://microbit.org/device/?id=9904&v=0255

This microbit has been shown to be reliable in the past.

tballmsft commented 1 year ago

I tried to download https://makecode.microbit.org/_9KKHE4WyyUM3 over WebUSB and got the message: error:

main.ts(1,1): error TS9283: program too big by 164532 bytes!

I don't know if this was related to V1. This may be a different bug (failing on WebUSB when program is too large for V1. However, the micro:bit doesn't do anything (the micro:bit doesn't respond and show a count, as expected).

I downloaded as file (Windows 11, build 22631) and copied over, but am getting 521 again (this time on home laptop).

The second time I copied it, the copy succeeded, but the program did nothing again, so I suspected it may be too large for V2 as well (another bug perhaps in size check for V2).

tballmsft commented 1 year ago

Here is a smaller version of the program that works when downloaded over USB: https://makecode.microbit.org/_Chq7538rzeDL (the download goes ahead even though there is an error message about not fitting, probably for V1, but message doesn't say).

See https://github.com/microsoft/pxt-microbit/issues/5395

tballmsft commented 1 year ago

OK, with the "medium program" (https://makecode.microbit.org/_Chq7538rzeDL). I still get 521 on file copy.

eanders-ms commented 1 year ago

Confirmed that mediumSwitch works on my microbit. It seems you have uncovered a different bug here with largeSwitch.

ramseyball commented 1 year ago

Yes, I filed two more issues related to large files:

ramseyball commented 1 year ago

Did anyone see a 521?

abchatra commented 1 year ago

@jaustin -> Chatted with Jonny in this morning call.

microbit-carlos commented 1 year ago

OK, with the "medium program" (https://makecode.microbit.org/_Chq7538rzeDL). I still get 521 on file copy.

Did anyone see a 521?

I've added an icon on startup (to easily confirm the programme started successfully, although the microphone LED does that as well) to that programme, flashed it over 20 times on Windows 11 22621.2506 and could not replicate.

Edition Windows 11 Home Version 22H2 Installed on ‎25/‎04/‎2023 OS build 22621.2506 Experience Windows Feature Experience Pack 1000.22677.1000.0

I've used a micro:bit V2.2 with DAPLink 0257

@tballmsft just to double check, I assume this hex file triggers a 5xx error on your environment? microbit-mediumSwitchHeart.zip

ramseyball commented 1 year ago

Yes, but I am away from my windows machines until Wednesday. I will test again when back

microbit-carlos commented 1 year ago

That'd be great, thanks! Are you running Windows insider builds? I wonder if this is due to an update not release yet to the public channel.

microbit-carlos commented 1 year ago

I've tried the microbit-mediumSwitchHeart.zip file from comment https://github.com/microsoft/pxt-microbit/issues/5393#issuecomment-1805636843 in a Windows 11 insider build 23565.1000 and could not replicate there either.

I'd be really interesting to know what might be the trigger in your environment @ramseyball / @tballmsft, as you've mentioned you could replicate it in two different computers?

ramseyball commented 1 year ago

I will dig into this more this evening, when I have access to Windows computer again.

tballmsft commented 1 year ago

OK, at home on Lenovo laptop, I am successful in copying microbit-mediumSwitch.zip over multiple times.

But I am able to put the same micro:bit's DAPlink in a "bad state" by copying over this hex file for micro:bit produced by Arcade: arcade-tilecode.zip

When I next try to copy the microbit-mediumSwitch over, I get a 521.

After a few more trues, I get it to copy OK.

So perhaps DAPlink is not resetting itself properly after a failure?

tballmsft commented 1 year ago

At work, on desktop I am seeing a 521 about 50% of the time when copying mediumSwitch. The OS is same version (build 22631). Other differences:

At work I am seeing 521 failures against a variety of micro:bits (v2.21 and v2.0).

ofaurax commented 11 months ago

With a new microbit v2, I had this error 521 when I tried to flash my first program, with Linux (online makecode, download, drag'n'drop). Then everything went fine and I didn't see any 521 since.

abchatra commented 9 months ago

This is fixed.