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.

Hi msfujino, i tried to unbricked my nRF52840 with all steps above, but i got this error message on my cmd, can you help me to solve this? Thank You!

WARNING: interface/raspberrypi2-native.cfg is deprecated.
WARNING: Please use interface/raspberrypi-native.cfg for all Raspberry Pi models.
Error: The specified debug interface was not found (bcm2835gpio)
The following debug adapters are available:
1: ftdi
2: usb_blaster
3: usbprog
4: jlink
5: vsllink
6: rlink
7: ulink
8: arm-jtag-ew
9: hla
10: osbdm
11: opendous
12: picoprobe
13: cmsis-dap
14: xds110
15: st-link

Serena_Hasianna,
This thread is about XIAO_SAMD21? and does not apply to nRF52840.
What kind of problem with nRF52840?

if i press the rst button twice, usually the driver XIAO will shows in my driver manager, but somehow after i flash the zephyr.uf2 from nrf connect example i did not get anything from it. After that, when i tried to press twice the rst button, the driver XIAO didn’t show up and my nRF52840’s port won’t recognize in my laptop. Can you tell me why and how to solve it?

Carefully follow the steps below. With luck, it will be restored.
[Note] Maybe “Seeed XIAO nRF52840 Sense” or “TinyUSB Serial” will appear with a different name in your device manager.

  1. Is“Seeed XIAO nRF52840 Sense" or“TinyUSB Serial”listed under“Universal Serial Bus Devices”in the Device Manager?
    Note: not “Ports (COM & LPT)”.
  2. If not, this method does not work.
  3. If so, right click “Seeed XIAO nRF52840 Sense”or“TinyUSB Serial”, and “Update Driver”
  4. select “Browse my computer for drivers”
  5. select “Let me pick from a list of available drivers on my computer”
  6. select “USB Serial Device” and click “Next”

Also, if you read the Wiki carefully, you will find a description of re-writing the bootloader.

I’m so sorry, after i checked my device manager “Seeed XIAO nRF52840 Sense” or“TinyUSB Serial” not appears, do you have another method to solve this or using ST-Link maybe? Thank you so much

Also, if you read the Wiki “Power Consumption Verification” carefully, you will find a description of re-writing the bootloader.

Thanks for your posts on this topic. After using Xiao for a few years without a problem, I have had a recent series of bricks and spent this weekend restoring them. Your bootloader is now in all of them.

Hi gregarious2,
Happy to help you.

Thank for this, helps everyone

Hi, Great article. Many thanks. I couldn’t get the solution to work using either a st-link v2 or your daplink solution. In case anyone finds them selves in the same boat I posted my command line solution in your post re daplink. Repeating it here:

I was unable to get the batch script work with the flash.cfg. flash.bat returned errors suggesting that the device couldn’t be found/wasn’t attached to my st-link v2. At this point I assumed I had destroyed the device but I found the following command line call to openocd that does:

.\openocd -f interface/stlink.cfg -c “transport select swd” -f target/nrf52.cfg -c “init;halt;nrf5 mass_erase;program Seeed_XIAO_nrf52840_bootloader-0.6.2_s140_7.3.0.hex verify reset; exit”

Brief Instructions:

  1. I used a ST-link v2. Connect 3v to the 3v pin on the xiao. Connect GND to a GND pin on the xiao. Connect SWDIO and SWCLK to the solder pads on the back of the device (I melted the GND pad off, but using a GND pin works just fine).
  2. Download and install openocd in a directory on your windows machine. Google will tell you how.
  3. Go to openocd/bin and place the .hex file for the latest bootloader in the same location as the openocd.exe file. I found it in the arudino ide as instructed here but there were several locations ala Google.
  4. Modify the command to reflect the actual name of the bootloader file in the step above.
  5. Open a command prompt. Go to the directory openocd\bin.
  6. Cut and the paste the command line call (modified as required), and hit return.

I don’t know why the flash.cfg didn’t work. I did try to use transport select swd instead of transport select ha_swd and was told that me device (a st-link v2) didn’t support it.

Thanks again!