|
| 1 | +--- |
| 2 | +title: Burn the bootloader on SAMD boards |
| 3 | +description: Learn how to burn the bootloader on SAMD boards. |
| 4 | +difficulty: Advanced |
| 5 | +featuredImage: 'clip' |
| 6 | +--- |
| 7 | + |
| 8 | +In this tutorial, we will learn how to burn the bootloader on boards that use the ATSAMD21G18 microcontroller using another Arduino board. The bootloader is a small piece of software that allows uploading sketches onto the Arduino board. It comes preprogrammed on the microcontrollers on Arduino boards. Whether the bootloader has been corrupted or intentionally has been removed, it can be restored by burning (also called, flashing or programming) a new bootloader to the board. |
| 9 | + |
| 10 | +>**Note:** If you want to burn the bootloader on AVR boards such as an UNO, Mega, and classic Nano you can check out [these instructions](https://support.arduino.cc/hc/en-us/articles/4841602539164-Burn-the-bootloader-on-UNO-Mega-and-classic-Nano-using-another-Arduino). |
| 11 | +
|
| 12 | +## Requirements |
| 13 | +- An extra SAMD-based Arduino board to use as the programmer. |
| 14 | +- An SD slot. This could be built into your Arduino board (e.g., [MKR Zero](https://store.arduino.cc/products/arduino-mkr-zero-i2s-bus-sd-for-sound-music-digital-audio-data?_gl=1%2A17dcyg9%2A_ga%2AMjEyMzQ2MjgwOC4xNjY1NjUyNTY3%2A_ga_NEXN8H46L5%2AMTY3MTYyNzMzMS4xNjEuMS4xNjcxNjI5ODA2LjAuMC4w)), a shield (e.g., [MKR SD Proto Shield](https://store.arduino.cc/products/mkr-sd-proto-shield?_gl=1%2A1xs1eol%2A_ga%2AMjEyMzQ2MjgwOC4xNjY1NjUyNTY3%2A_ga_NEXN8H46L5%2AMTY3MTYyNzMzMS4xNjEuMS4xNjcxNjMwMzgxLjAuMC4w)), or one of the common SD modules. |
| 15 | +- An SD card that fits your SD slot. |
| 16 | +- A way to connect the SD card to your computer. |
| 17 | +- A way to make the connections to the SWD pins on your target Arduino board. |
| 18 | + |
| 19 | +## Instructions |
| 20 | +- Select **Sketch > Include Library > Manage Libraries...** from the Arduino IDE menus. |
| 21 | +- Wait for any index updates to finish. |
| 22 | +- In the **"Filter your search..."** field, type `Adafruit DAP library` |
| 23 | +- Press **<kbd>Enter</kbd>**. |
| 24 | +- Click on "**Adafruit DAP library by Adafruit**". |
| 25 | +- Click the **<kbd>Install</kbd>** button. |
| 26 | +- Wait for the installation to finish. |
| 27 | +- Close **Library Manager**. |
| 28 | +- Select **File > Examples > Adafruit DAP library > samd21 > flash_MKR_bootloaders** from the Arduino IDE menus. |
| 29 | + - despite the "MKR" in the sketch name, this also supports the [**Nano 33 IoT**](https://store.arduino.cc/products/arduino-nano-33-iot) |
| 30 | +- Select your **programmer** Arduino board from Arduino IDE's **Tools > Board** menu. |
| 31 | +- Select the port of the **programmer** Arduino board from Arduino IDE's **Tools > Port** menu. |
| 32 | +- Select **Sketch > Upload** from the Arduino IDE menus. |
| 33 | +- Wait for the upload to finish successfully. |
| 34 | +- Unplug the **programmer** Arduino board from your computer. |
| 35 | +- Connect the **programmer** Arduino board to the **target** Arduino board as follows: |
| 36 | + | Programmer | Target | |
| 37 | + | ---------- | ------ | |
| 38 | + | VCC | +3V3 | |
| 39 | + | 1 | SWDIO | |
| 40 | + | 2 | SWCLK | |
| 41 | + | GND | GND | |
| 42 | + | 0 | RESETN | |
| 43 | + |
| 44 | +**SWD pads on MKR boards other than MKR 1000:** |
| 45 | + |
| 46 | + |
| 47 | + **MKR 1000 SWD header pinout:** |
| 48 | + |
| 49 | + |
| 50 | +**Nano 33 IoT SWD pads:* |
| 51 | + |
| 52 | + |
| 53 | +- Plug the USB cable of the **programmer** Arduino board into your computer. |
| 54 | +- Select **Tools > Serial Monitor** from the Arduino IDE menus. |
| 55 | +- Select "No line ending" from the dropdown menu near the bottom right corner of the **Serial Monitor** window. |
| 56 | + |
| 57 | +You should see some instructions for using the sketch in the **Serial Monitor** output field. <br /> |
| 58 | + This includes a menu of the boards supported by the sketch: |
| 59 | + ```text |
| 60 | + [...] |
| 61 | +
|
| 62 | + Select Arduino MKR board to erase and flash with bootloader: |
| 63 | + |
| 64 | + Z -> Arduino Zero (6504 bytes) |
| 65 | + MZ -> Arduino MKR Zero (6408 bytes) |
| 66 | + 1000 -> Arduino MKR 1000 WIFI (6408 bytes) |
| 67 | + 1010 -> Arduino MKR WIFI 1010 (7984 bytes) |
| 68 | +
|
| 69 | + [...] |
| 70 | + ``` |
| 71 | + Find your **target** Arduino board on the list and note the code written to the left of it. |
| 72 | + |
| 73 | +- Type the code for the **target** Arduino board in the message field of **Serial Monitor**. |
| 74 | +- Press the <kbd>**Enter** key. |
| 75 | +- The Serial Monitor output field should now show the board you selected and the progress of flashing the bootloader to the **target** Arduino board. |
| 76 | + Wait for it to show "Done!" |
| 77 | +- Unplug the **programmer** Arduino board from your computer. |
| 78 | +- Disconnect the **programmer** Arduino board from the **target** Arduino board. |
0 commit comments