Custom Arduino SAMD21 bootloader with Atmel Studio

I recently got a low-cost ARM Cortex M0 based ( Atmel SAMD21G18A ) board , a clone of the Robotdyn SAMD21 M0-mini board and wanted to make a custom Arduino IDE compatible bootloader using the Atmel Studio IDE – it has the GNU-ARM toolchain built in.

The user L-LED was not mounted, so the RX- and TX-LEDs could be used as bootloading progress indicators. It turned out that a fresh installed Arduino IDE is able to add GNU ARM Cortex M0+ toolchain for various Arduino boards that uses the Atmel SAMD21 microcontroller.

Steps involved to make the custom bootloader are these, assuming Windows 10 is used:

  1. Download the Arduino IDE v. 1.18.13 from here: Arduino IDE  , do not use Microsoft App Store to inatall the Arduino IDE.!
  2. Install to the default installation path: C:\Program Files (x86)\Arduino
  3. Select Tools -> Board -> Boards Manager . Scroll down to find and install the Arduino package: Arduino SAMD Boards ( 32 bits ARM Cortex M0+ ). After installation , goto Tools -> Board and select the Arduino MKRZero board :
  4. Close the Arduino IDE. Bootloader source code for the bootloaders shown for the Arduino SAMD boards are found in the path: C:\Users\foo\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.9\bootloaders , replace foo with your Win 10 user name , and enable “show hidden files” in Explorer View. Contents of the bootloaders folder:  
  5. Download and install the Atmel Studio IDE ( I used version 7.0.2397 ) from here:  Atmel Studio download
  6. The zero folder holds the source files for the Arduino SAMD21 bootloaders. Copy the zero folder to: C:\Users\foo\Documents\Atmel Studio\7.0 ,  foo is your user name.
  7. Open the zero folder in C:\Users\foo\Documents\Atmel Studio\7.0 ,  foo is your user name. In the zero folder find and click the samd21_sam_ba.atsln Atmel Studio project file:
  8. Atmel Studio starts the project . Press F7 to build the bootloader:
  9. Some Warnings will show, but the “Build succeeded.” is OK. The bootloader .hex file from the compilation is found in the folder from step 7 and can be flashed to the SAMD21G18A microcontroller via the on-board SWD connector. At this point a customized Arduino compatible SAMD21 bootloader can be made by modifying the files in the Atmel Studio project to fulfill the actual needs. I made a bootloader version that used the RX- and TX-LEDs to indicate, that the bootloader is running. This version of the bootloader is here: SAMD21 custom bootloader. A small demo video is to be seen here: Youtube ldr
  10. To flash the bootloader, refer to the blog: Atmel Studio 7 and SAMD21 – ARM Cortex M0+

Leave a Reply