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

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.