Bootloader sometimes destroyed when XIAO (SAMD21) is switched on

I have the problem that sometimes the bootloader is destroyed when the Xiao (SAMD21) is switched on. A reset (even with a double reset) is not possible. Only the green LED lights up.

In my program code, I read data from the EEPROM and rewrite it on request.
Basically, my program does the following:
It reads variables from the EEPROM
It uses the direction information from a magnetic sensor (BNO055)
A servo is controlled based on the direction information of the sensor
If variables need to be adjusted (servo rudder deflection), I write them to the EEPROM. These variables are read in via the serial interface.
The display and the sensor are addressed via I2C

This all works wonderfully, as long as the XIAO carries out the boot process.

The libraries I use are

  • #include <Wire.h>
  • #include <Adafruit_Sensor.h>
  • #include <Adafruit_BNO055.h>
  • #include <utility/imumaths.h>
  • #include <Adafruit_GFX.h>
  • #include <Adafruit_SSD1306.h>
  • #include <Servo.h>
  • #include <FlashStorage_SAMD.h>

My programm-code is at Github

This is the beginning of the setup:
void setup()

//while (!Serial);

// #### Initialize Variables - Read or Read&Write Varaibles in EEPROM
InitVariables(F1E_Variables); // Function with actions in EEPROM
// info about exixting MP - Blinking to show, that Xiao started

My questions:

  • A guess: Could it be that if the XIAO has a power interruption while reading/writing the EEPROM (function “InitVariables”), that the boot sector can then be destroyed?
  • Is it possible to protect the bootloader from being overwritten?
  • Can the boatloader be rewritten via the normal pins or USB?(I can no longer access the pins on the underside as the XIAO in my small series production is soldered onto a circuit board)

The following links may be helpful regarding bootloader protection.

1 Like

Hello msfufujino,
thanks for your quick answer! This helps a lot for repairing the bricked XIAOs! I will try it!

Is there any suggestion how the bricking could happen? Is there suggestion how to avoid damaging the bootloader in the original unprotected version from Seeed?


Is there any suggestion how the bricking could happen?

I am not sure what process causes the overwriting of the bootloader, but in my case, it happened when I was manipulating the registers directly.

Is there suggestion how to avoid damaging the bootloader in the original unprotected version from Seeed?

If you write the bootloader using the method in this link before using XIAO, the bootloader area will be protected, so at least the overwriting will not happen during normal use.

1 Like

Ok, so I will prepare the XIAOs with your method before the first use
Thanks so much for your help!

Hello msfujino,
I just tried to use your method for unbricking the Xiao.

I build a DAPLink_Xiao with a new Xiao as you described. After copying the *.uf2 file to the Arduino drive, the XIAO changed the LED color to blue. So I think, all is done as it should.
The path in flash.bat is filled with my path to openocd.
I wired the DAPLink and a bricked XIAO on a “Expansion Board Base for XIAO”

When i start the flash.bat I get a different output at the terminal:

C:\Users\Flugp\OneDrive\Dokumente\Arduino\eigene_Programme\F1E_PS_V2.0\Xiao\XIAO_BootloaderRescueTool_DAPLink\XIAO_BootloaderRescueTool_DAPLink>C:\Users\Flugp\AppData\Local\Arduino15\packages\arduino\tools\openocd\0.10.0-arduino7\bin\openocd -f flash.cfg -s C:\Users\Flugp\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
none separate
adapter speed: 400 kHz
cortex_m reset_config sysresetreq
none separate
adapter_nsrst_delay: 100
adapter_nsrst_assert_width: 100
Info : CMSIS-DAP: SWD Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : CMSIS-DAP: FW Version = 1.10
Info : SWCLK/TCK = 0 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 400 kHz
in procedure ‘init’ called at file “flash.cfg”, line 15
in procedure ‘ocd_bouncer’

Drücken Sie eine beliebige Taste . . .

Nothing happpend with the bricked board and there is no sucess message in the terminial window. Something do not work in the flash.bat

Could you help me again?


Hi msfujino,
I tried it with other bricked XIAOs - and it worked! I think my first test XIAO was more damaged than only in the bootloader area…

One question to the status of the protected area:
“2” means protected (flashed with flash.bat, checking with SAMD21_BootloaderProtectCheck.ino)
“7” means unprotected (flashed with flash_unprotect.bat, checking with SAMD21_BootloaderProtectCheck.ino)
Correct interpretation?

“7” means 0 byte protected, “2” means 8192 bytes protected.
Details are described in the datasheet 22.6.5. NVM User Configuration Table 22-2. Boot Loader Size.

1 Like