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

The bootloader area of a XIAO is not write-protected when it is shipped from Seeed. If this area is overwritten for any reason, a XIAO will lose its COM port, will not respond to “double reset”, and will be bricked. A bricked XIAO can be repaired by re-writing the bootloader.
All I needed was a XIAO uploading “simple_daplink_xiao.uf2”, OpenOCD that comes with Arduino IDE, and some script files that I attached. Connect a bricked XIAO and a DAPLink_XIAO with four wires, and double-click “flash.bat” to re-write the bootloader, I was able to repair a bricked XIAO. After re-write, the bootloader area will be set to protect so that it will not be overwritten at least. If I don’t want to protect the bootloader area, I can use “flash_unprotect.bat”.
I have tried it with 6 XIAOs and have been able to use it without any problems so far. You can use the attached “SAMD21_BootloaderProtectCheck.ino” to see if the bootloader area is protected.

Here are the step-by-step instructions.
XIAO_BootloaderRescueTool_DAPLink.ZIP (49.2 KB)

Modifying the "flash.bat"

  1. Unzip “XIAO_BootloaderRescueTool_DAPLink.zip” to an appropriate location.
  2. Open the “flash.bat” with an editor and modify it to suit your PC.
    This file is written to match the standard Arduino IDE installation location, so you will need to change
    Modify the directory containing “openocd.exe” and “cmsis-dap.cfg” as necessary.
    Modify the “XXXXXXXX” username part.

Installing DAPLink

  1. Connect a XIAO used as DAPLink to your PC and double-reset it.
    An explorer window of Arduino drive will open.
  2. Drop “simple_daplink_xiao.uf2” in this window.
    Now, a XIAO can be used as DAPLink.

Re-write the bootloader

  1. Connect a DAPLink_XIAO and a bricked XIAO with 4 wires.
  2. Connect a DAPLink_XIAO to your PC and double-click “flash.bat”.
  3. A command prompt will open and the bootloader will be written.
    If success, the following will be displayed.

XIAO to XIAO
Use expansion board

Checking a repaired XIAO

  1. [IMPORTANT] Connect a repaired XIAO to your PC and double-reset to make your PC recognize a XIAO again.
    An explorer window of Arduino drive will open.
  2. [IMPORTANT] In Arduino IDE, tools–Port menu, mark COM port that says “Seeeduino XIAO”.
  3. Compile and upload your sketch, and make sure a XIAO is working as expected.
    If an error occurs, check Tools–Port menu. It may be unmarked, or the port number may have changed.

I found the following link helpful. Thank you.

  1. “Build a DAPLink Deivce using Seeeduino XIAO”.
    To simplify the work, I have included “simple_daplink_xiao.uf2” as an attach file. Thank you.
    https://wiki.seeedstudio.com/Seeeduino-XIAO-DAPLink/

  2. “How to use Arduino Boards as DAPLink Device”
    https://wiki.seeedstudio.com/Arduino-DAPLink/

  3. “The $5 programmer-debugger”
    https://embeddedcomputing.weebly.com/the-5-programmer-debugger.html

2 Likes

Wow ! Nice piece of work. Tools to support Xiao are very much needed. Seeeduino owes you a debt. Very much appreciated here.

Greetings, thanks for the info. I don’t get the feedback you show in the console above. I edited the flash.bat to include my username, but the image below is what I get. Looks like the init fails; looks like the XIAO I am using for DAP is ok, but not communicating with the dead XIAO (I have wired leads to the SWDIO and SWCLK. Any ideas?

Have you wired leads to VCC and GND?

Yes I have wired to 5V and GND on the DAPLink KIAO just like the image above. The DAPLink XIAO has two blue lights (plugged into USB), the bricked XIAO just has one amber LED lit. I can’t put that device into bootloader mode and a COM port doesn’t show up when plugged in.

I too have confirmed the problem of not being able to write. It seems that my confirmation was insufficient.
It seems that this problem occurs when connecting DAPLink_XIAO and brick_XIAO directly with wires. However, when brick_XIAO is put on the XIAO expansion board and connected to DAPLink_XIAO, it can write without any problem. The cause is still unknown at this point.

By the way, if you use ST-Link instead of DAPLink_XIAO, even if you connect directly to brick_XIAO You can write without any problem.

After a few tries, the problem no longer occurs even when wiring DAPLink_XIAO and brick_XIAO directly.
Now I can write without any problem no matter how many times I try. I think it may be a clitical timing issue.

Worked like a charm! Thanks for this - I hate to lose a perfectly good MCU, even if they only cost a few bucks!

Glad my post was helpful.

You are :100: right, this happen to me today for hours I couldn’t figure it out, then loader over the code and realize that my pins was set to valid pin number. I recommend to everyone facing this challenge to check your pins numbers in your code before any process.

This is a really nice piece of work :smiley:

Hi, I am undergoing issues with “flash.bat”. I have modified the directory accordingly.

“cmsis-dap.cfg” file is now under “C:\Users\XXXXXXXX\AppData\Local\Arduino15\packages\arduino\tools\openocd\0.10.0-arduino7\share\openocd\scripts\interface” and I have also changed that

But it keeps giving me “Error: unable to find CMSIS-DAP device”…

Hi jeffery_shen,
Please show us the file you modified and the screenshot of what you see when you run it.
What version of AdruinoIDE do you have?

Hi, Thanks for your timely reply!
Here is my screenshot

and the version of ArduinoIDE is 2.2.1.

I have also tried ArduinoIDE 1.8.x but still gave me the same error…

They only allow me to attach one pic each reply:

Here is what the error and directory contains cmsis-dap.cfg

“unable to find CMSIS-DAP device” is displayed when there is no DAPLink_XIAO.

Is the “simple_daplink_xiao.uf2” correctly installed on the XIAO_samd21 to be used as DAPLink?
Is the connection between Brick XIAO and DAPLink_XIAO correct?
What happens if use “0.11.0-arduino2” instead of “0.10.0-arduino7”?