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

So guys, finally, i was able to revive my dead XIAO after hours of research on google. It can be done by following this guide from Adafruit.

https://learn.adafruit.com/programming-microcontrollers-using-openocd-on-raspberry-pi/overview

Things needed

  1. Raspberry pi
  2. Some jumper wires
  3. Soldering skills to break out the SWDIO and SWDCLK pins from the bottom of the board :stuck_out_tongue: (i had 2 XIAOs bricked. The first one’s pads came off trying to solder :stuck_out_tongue: )

IMPORTANT

  1. Download and keep the original XIAO bootloader froim here:

https://github.com/Seeed-Studio/ArduinoCore-samd/blob/master/bootloaders/XIAOM0/bootloader-XIAO_m0-v3.7.0-33-g90ff611-dirty.bin

  1. Follow the Adafruit guide to build openocd on raspberry pi and make the connections as mentioned. However, in the last stage of burning bootloader, the openocd commands need a change.

Instead of the command

program samd21_sam_ba verify

use the command

flash write_image “bootloader-XIAO_m0-v3.7.0-33-g90ff611-dirty.bin”

Also, i had to add the following lines in my openocd cfg file - though guide mentiontions its needed only for pi zero/1/2

bcm2835gpio_swd_nums 25 24
bcm2835gpio_trst_num 7
bcm2835gpio_srst_num 18

The chip was not getting discovered without those commands.

Once you execute the openocd command (sudo openocd -f openocd.cfg ),
you should see the amber LED pulsing :slight_smile: . You can now connect the XIAO to computer and upload your code using arduino.

Here is my config file for reference,

source [find interface/raspberrypi2-native.cfg]
transport select swd

set CHIPNAME at91samd21g18
source [find target/at91samdXX.cfg]

#did not yet manage to make a working setup using srst
#reset_config srst_only
reset_config srst_nogate

adapter_nsrst_delay 400
adapter_nsrst_assert_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

Let me know if you have any questions regarding the procedure (Note: I am not an openocd/swd expert)

1 Like

@Baozhu @jiachenglu

pls share the guide to help folks with a bricked xiao

Hi @John_Doe
Thank you share this guide to us, I will add a link to this forum in Xiao’s Wiki so that more people can see your solution.

@John_Doe thanks for this guide. You have quotes around the binary file name for the flash write_image command and they should not be included if you are using Linux. Other than that, all worked fine to unbrick two XIAOs with RPiZW.

You are welcome… I have kind of identified why XIAO is unstable…Its because of the UF2 bootloader it ships with. I will post soon about it today… @jiachenglu

2 Likes

Hi, I tried this but the xiao is still bricked. This was the output:
Open On-Chip Debugger 0.11.0-rc1+dev-00001-g0dd3b7fa6-dirty (2020-12-11-15:07)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : BCM2835 GPIO JTAG/SWD bitbang driver
Info : clock speed 400 kHz
Info : SWD DPIDR 00000000

So I am not sure it did it. Yellow led not going and pc does not recognize it.
I am using a Pi-3B.

My Config:
source [find interface/raspberrypi2-native.cfg]
transport select swd

set CHIPNAME at91samd21g18
source [find 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

Any insight would be appreciated.

Edit: I ran with debug and it looks like all the swd cmds received no valid ack’s back, so I guess the chip is gone? Very disturbing because all I did to kill it was to unplug from the pc. When next plugged in, was dead??? Something is extremely unstable.

Well, Dummy me tried this on a good one. Now have two that are bricked. Software revised and broke?
This is the output:
Open On-Chip Debugger 0.11.0-rc1+dev-00001-g0dd3b7fa6-dirty (2020-12-21-17:00)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : BCM2835 GPIO JTAG/SWD bitbang driver
Info : clock speed 400 kHz
Info : SWD DPIDR 0x0bc11477
Info : at91samd21g18.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : starting gdb server for at91samd21g18.cpu on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0xf0000000 pc: 0x213c0a0a msp: 0x0a0a0a08
Info : SAMD MCU: SAMD21G18A (256KB Flash, 32KB RAM)
Error: at91samd21g18.cpu – clearing lockup after double fault
target halted due to debug-request, current mode: Handler HardFault
xPSR: 0xf1000003 pc: 0xfffffffe msp: 0x0a0a09e8
shutdown command invoked

They both lock up after double fault. If I request debug, it goes on and on.