How to unbrick a dead XIAO using ST-LINK and OpenOCD

Worked like charm!!!
Thank you so much. I recovered a Xiao (stoped working after a few days transmitting LoRaWan to ThethingsNetwork on battery- brown out??). But most of all it was pure joy when I saw the Xiao port again.

Thank you!

Hi, Pedotech
I’m glad I could help you.
You may also find the following link useful.

Hi I’ve followed everything so far and am now getting this error.

I can’t say for sure because our PC environment are different, but it sounds like there is a problem with the USB driver.
I suggest you look into the USB driver “Zadig”.

Thank you it worked!


Can someone help me ?

Hi PANOK,
I think the situation is exactly the same as post #32. It sounds like there is a problem with the USB driver. I suggest you look into the USB driver “Zadig”.

@msfujino Would you be able to give me a quick hand?

I’m getting the error:

I ended up soldering the cables directly to the pads and using a multimeter I ensured there is connection between the ST-link V2 and the microcontroller. I also swapped SWDIO with SWCLK just in case I got it wrong the first time around but still no luck.
I’m 100% sure the wiring is correct, I checked it a bunch of times and also rewired it from scratch a few times.

I was looking around and found this article (Programming RP2040 with ST-LINK - Electrical Engineering Stack Exchange) that explains how the ST-LINK V2 can’t connect to the Seeed XIAO RP2040. Someone said to do the update however I have no idea what that guide is talking about. I updated it to the latest version (V2.J37.S7) using the “STM32 ST-link” software.
Did you have to do some weird update or did it just work?
Am I missing something?
Any Idea on how I can fix it?

Thank you,
Andrea

Hi Andrea_Nizzola,
If you have an unbricked XIAO_SAMD21, the method in the link below is very easy.

How to unbrick a dead XIAO using a XIAO(DAPLink) and OpenOCD

Hi Andrea_Nizzola,
I have made a RescueTool for ST-Link.
Unzip the file to a suitabule location and rewrite xxxxxxxx to yours in two places in “flash.bat”.
Double-click “flash.bat” to write the bootloader.
XIAO_BootloaderRescueTool_STLink.zip (10.5 KB)

Andrea_Nizzola,

@msfujino Would you be able to give me a quick hand?

Since you seemed to be in a hurry to resolve the issue, I posted two solutions.
What were the results?

Greetings, if you are still monitoring this feed, would you be so kind as to explain the following? You write

  1. Download the bootloader file bootloader-XIAO_m0-v3.7.0-33-g90ff611-dirty.bin to C:/XIAO_bootloader.

But where do I find the file I am to download? You told me where to place it but I cannot find it. Would you please tell me what the source is? I am certain the information is in your article but it is rather lengthy and I am somewhat dyslexic.

Many Thanks - Baran

The bootloader should be in the following holder
“C:\Users\XXXXXXX\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.4\bootloaders\XIAOM0”

If you have more than one SAMD21, it is very easy to use DAPLink from the link below. It also includes the bootloader files.
How to unbrick a dead XIAO using a XIAO(DAPLink) and OpenOCD

Also, if you use ST-Link, post #39 at the following link has everything you need.
How to unbrick a dead XIAO using ST-LINK and OpenOCD - #40 by msfujino

Make sure your USB cable is a data cable and not just a charging cable
Also try switching cables

I’ve used this guide a couple of times, and provided that the MCU isn’t damaged, it works just the way you’d expect. (Sometimes it takes more than one try.)

Here’s a small improvement. At least in current versions of OpenOCD, the at91samdXX.cfg file allows you to override CPUTAPID directly from your config file. So, instead of modifying the at91samdXX.cfg file and changing XIAO_openocd.cfg to load the modified file, you can insert a line just before, like so:

...
set CPUTAPID 0x0bc11477
source [find target/at91samdXX.cfg]
...

This change allows you to use a stock OpenOCD package, regardless of how you’ve installed it.

Many thanks msfujino, that worked at treat! You’re a star :smiley:

Thanks for the thread. I got this far, any ideas?

C:\Users\scalv\Downloads\XIAO_BootloaderRescueTool_STLink\XIAO_BootloaderRescueTool_STLink>C:\Users\scalv\AppData\Local\Arduino15\packages\arduino\tools\openocd\0.10.0-arduino7\bin\openocd -f flash.cfg -s C:\Users\scalv\AppData\Local\Arduino15\packages\arduino\tools\openocd\0.10.0-arduino7\share\openocd\scripts
Open On-Chip Debugger 0.10.0+dev-gf0767a31 (2018-06-11-13:36)
Licensed under GNU GPL v2
For bug reports, read
OpenOCD: Bug Reporting
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
none separate
adapter speed: 400 kHz
none separate
adapter_nsrst_delay: 200
adapter_nsrst_assert_width: 100
Info : Unable to match requested speed 400 kHz, using 240 kHz
Info : Unable to match requested speed 400 kHz, using 240 kHz
Info : clock speed 240 kHz
Info : STLINK v2 JTAG v34 API v2 SWIM v7 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.564309
Info : at91samd21g18.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : Listening on port 3333 for gdb connections
TargetName Type Endian TapName State


0* at91samd21g18.cpu hla_target little at91samd21g18.cpu halted
target halted due to debug-request, current mode: Thread
xPSR: 0xe1000000 pc: 0xfffffffe msp: 0xfffffffc
target halted due to debug-request, current mode: Thread
xPSR: 0xe1000000 pc: 0xfffffffe msp: 0xfffffffc
** Programming Started **
auto erase enabled
Info : SAMD MCU: SAMD21G18A (256KB Flash, 32KB RAM)
Error: SAMD: NVM programming error
Error: Failed to erase row containing 00000000
Error: SAMD: failed to erase sector 0 at 0x00000000
Error: failed erasing sectors 0 to 31
embedded:startup.tcl:477: Error: ** Programming Failed **
in procedure ‘script’
at file “embedded:startup.tcl”, line 60
in procedure ‘program’ called at file “flash.cfg”, line 23
in procedure ‘program_error’ called at file “embedded:startup.tcl”, line 536
at file “embedded:startup.tcl”, line 477

C:\Users\scalv\Downloads\XIAO_BootloaderRescueTool_STLink\XIAO_BootloaderRescueTool_STLink>pause
Press any key to continue . . .

The openocd should use “0.11.0-arduino2”, but your log seems to use “0.10.0-arduino7”.
The folder “0.11.0-arduino2” is located at /.adruino15/packages/Seeeduino/tools/openocd/.

If you have another XIAO_SAMD21, the method in the link below is easy and successful.

There was a mistake in the description of flash.bat. It has been corrected.

XIAO_BootloaderRescueTool_STLink_1.zip (10.5 KB)

Thank you @msfujino, this worked, very easy to understand if you follow the steps to a T.