How to unbrick a dead xiao using raspberry pi [ GUIDE ][openocd]

Thank you for this article. I managed to unbrick my dead XIAO using the following steps:

Raspberry Pi:

$ uname -a
Linux raspberrypi 5.10.103-v7+ #1529 SMP Tue Mar 8 12:21:37 GMT 2022 armv7l GNU/Linux

Note that the openocd version that comes with this version of OS did not work due to tcl errors like these:

$ openocd -f openocd.cfg
Open On-Chip Debugger 0.10.0+dev-00114-g41bcbc67d-dirty (2021-01-18-16:43)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
/usr/bin/../share/openocd/scripts/target/swj-dp.tcl:30: Error: Unknown param: 4, try one of: -irlen, -irmask, -ircapture, -enable, -disable, -expected-id, -ignore-version, -dp-id, or -instance-id
in procedure 'script' 
at file "embedded:startup.tcl", line 26
at file "openocd.cfg", line 5
in procedure 'swj_newdap' called at file "/usr/share/openocd/scripts/target/at91samdXX.cfg", line 36
at file "/usr/bin/../share/openocd/scripts/target/swj-dp.tcl", line 30

So I first had to uninstall openocd and then compile it on my Raspberry Pi:

Update and install needed tools:

$ sudo apt-get update 
$ sudo apt-get install git autoconf libtool make pkg-config libusb-1.0-0 libusb-1.0-0-dev htop

Download OpenOCD from http://openocd.zylin.com/#/admin/projects/openocd:

$ git clone http://openocd.zylin.com/openocd

Compile:

$ cd openocd-code 
$ ./bootstrap 
$ ./configure --enable-sysfsgpio --enable-bcm2835gpio 
$ make 
$ sudo make install

openocd version:

$ openocd -v
Open On-Chip Debugger 0.11.0+dev-00656-g66335683f (2022-05-02-13:20)

Now the wiring:

              GPIO on RaspBerry Pi

               R     I G C
               S     O N L  
               T       D K
    ----------------------------------------
   | o o o o o o o o o o o o o o o o o o o o |
   | o o o o o o o o o o o o o o o o o o o o |
    ----------------------------------------


               XIAO
     _____________________ 
    |                     |
    |                     |
   _|_  IO  RST           |
  | | |  o   o            |
  | | |                   |
  |_|_|  o   o            |
    |   CLK GND           |
    |                     |
    |_____________________|

Content of openocd.cfg:

source /path/to/interface/raspberrypi2-native.cfg
transport select swd
set CHIPNAME at91samd21g18
source /path/to/target/at91samdXX.cfg
#did not yet manage to make a working setup using srst
#reset_config srst_only
reset_config srst_nogate
adapter srst delay 400
adapter srst pulse_width 100
bcm2835gpio swd_nums 25 24
bcm2835gpio trst_num 7
bcm2835gpio srst_num 18
#bcm2835gpio_peripheral_base 0xFE000000
#bcm2835gpio_speed_coeffs 236181 60
init
targets
reset halt
at91samd chip-erase
at91samd bootloader 0
flash write_image bootloader-XIAO_m0-v3.7.0-33-g90ff611-dirty.bin
#at91samd bootloader 8192
reset
shutdown

Now run:

openocd -f openocd.cfg

Hope this helps …

2 Likes