Debugging Arduino Due with Black Magic Probe and VScode/W10

Apologies but setting up toolchains is all quite new to me, so apologies if I have missed any obvious steps.

My platform.ini is:

platform = atmelsam
board = due
framework = arduino
debug_tool = blackmagic
debug_port = \.\COM22

and the output of pio device list is:

Hardware ID: ACPI\PNP0501\1
Description: Communications Port (COM1)

Hardware ID: USB VID:PID=2341:003D SER=85734323030351F081B2 LOCATION=1-1.6
Description: Arduino Due Programming Port (COM3)

Hardware ID: USB VID:PID=1D50:6018 SER=8
Description: USB Serial Device (COM23)

Hardware ID: USB VID:PID=1D50:6018 SER=8 LOCATION=1-1.1:x.2
Description: USB Serial Device (COM22)

I have tried with both COM23 and COM22. but I still get the same error when trying to start debugging:
Failed to launch GDB: .pioinit 16: error in sourced command file: \\.\COM22 No such file or directory

Thanks for any help you can offer!

So have you tried COM22 or COM23 without \.\?

I have tried ignoring the debugging stage for now, and tried uploading using the Black Magic Probe, to see if it will at least work in this way. But I am getting stuck. My platform.ini now reads:

platform = atmelsam
board = due
framework = arduino
debug_tool = blackmagic
debug_port = \\.\COM23

upload_protocol = blackmagic-jtag
upload_port = \\.\COM23

It definitely needs the \\.\ as the upload says port not found otherwise. COM23 seems to be the correct port as when I try and upload I get the error

Uploading .pioenvs\due\firmware.bin
Target voltage: 3.3V
Available Targets:
No. Att Driver
1      Atmel SAM3X
0x00080ae4 in USB_SendStringDescriptor(unsigned char const*, int) ()
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
Error erasing flash with vFlashErase packet
target memory fault, section .text, range 0x80000 -- 0x82a14

I have disconnected the Due and reuploaded the Blink example using the Arduino IDE, so im not sure what program is being debugged at the moment?

Ok, following the advice on another thread I tried adding debug_load_cmd = preload which has enabled some of the debugging functionality! I can enter debug mode and set a breakpoint. However, I still cannot upload using the bmp. While debugging, I dont seem to be able to manipulate variables and the watch variables dont seem to be updating.

Check this out to get up and running:

I think that I’ve found there may be a firmware issue with the BMP for SAM3X8E chips, however I haven’t had time to spare toward debugging that effort. That is being tracking in this github issue.

Thanks very much for your hard work to find a solution! I will try it out and hopefully it will be successful. I plan on moving to the Zero or Feather for my next projects so hopefully that will run a bit smoother.