Skip to content

Commit 0d8fa52

Browse files
Merge pull request #738 from arduino/Hannes7eicher/bootloader-reloading
[MKC-761] Bootloader reloading (SAMD boards) tutorial
2 parents 99f687c + 3827b0b commit 0d8fa52

File tree

4 files changed

+170
-0
lines changed

4 files changed

+170
-0
lines changed
77.1 KB
Loading
85.9 KB
Loading
74.5 KB
Loading
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
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+
Below you will find two different approaches to burning the bootloader:
11+
- [The first approach](#no-sd-card) does not require an SD card and should be used by users who want the easiest solution.
12+
13+
- [The second approach](#sd-card) uses an SD card and should be used when wanting to flash a different bootloader than the ones bundled with the "flash_MKR_bootloaders" sketch.
14+
15+
>**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).
16+
17+
## No SD card
18+
### Requirements
19+
- An extra SAMD-based Arduino board to use as the programmer.
20+
- A way to make connections to the SWD pins on your target Arduino board.
21+
22+
### Instructions
23+
- Plug the USB cable of the Arduino board you will be using as a programmer into your computer.
24+
- Select **Sketch > Include Library > Manage Libraries…** from the Arduino IDE menu.
25+
- Wait for the index updates to finish.
26+
- In the "**Filter your search…**” field type ‘Adafruit DAP library’.
27+
- Press **Enter**.
28+
- Click on “**Adafruit DAP library by Adafruit**”.
29+
- Click the **Install** button.
30+
- You may now get a dialog asking whether to install the library's dependencies. If so, click the "**Install All**" button.
31+
- Wait for the installation to finish
32+
- Close the **Library Manager**
33+
- Select **File > Example > Adafruit DAP Library > samd21 > flash_MKR_bootloaders** from the Arduino IDE menu. (despite the “MKR” in the sketch name, this also supports the **Nano 33 IoT**).
34+
- Select your **programmer** Arduino board from the IDE’s **Tools > Board** menu.
35+
- Select the port of the **programmer** Arduino board from the Arduino IDE’s Tools > Port menu.
36+
- Select **Sketch > Upload** from the Arduino IDE menu.
37+
- Unplug the **programmer** Arduino board from your computer.
38+
- Connect the **programmer** Arduino board to the target Arduino board as follows:
39+
40+
| Programmer | Target |
41+
| ----------- | ----------- |
42+
| VCC | +3V3 |
43+
| 1 | SWDIO |
44+
| 2 | SWCLK |
45+
| GND | GND |
46+
| 0 | RESETN |
47+
48+
SWD pads on MKR boards other than MKR 1000:
49+
50+
![](assets/SWDpadsMKR.png)
51+
52+
MKR1000 SWD header pinout:
53+
54+
![](assets/SWDMKR1000header.png)
55+
56+
Nano 33 IoT SWD pads:
57+
58+
![](assets/SWDpadsNano33IoT.png)
59+
60+
- Plug the USB cable of the **programmer** Arduino board into your computer.
61+
- Select **Tools > Serial Monitor** from the Arduino IDE’s menu.
62+
- Select "**No line ending**” from the dropdown menu near the bottom right corner of the **Serial Monitor** window.
63+
- You should now see some instructions for using the sketch in the **Serial Monitor** output field.
64+
65+
This includes a menu of the boards supported by the sketch:
66+
67+
```
68+
[...]
69+
70+
Select Arduino MKR board to erase and flash with bootloader:
71+
72+
Z -> Arduino Zero (6504 bytes)
73+
MZ -> Arduino MKR Zero (6408 bytes)
74+
1000 -> Arduino MKR 1000 WIFI (6408 bytes)
75+
1010 -> Arduino MKR WIFI 1010 (7984 bytes)
76+
77+
[...]
78+
```
79+
- Find your **target** Arduino board on the list and note the code written to the left of it.
80+
- Type the code for the **target** Arduino board in the message field of the Serial Monitor.
81+
- Press **Enter**
82+
- The Serial Monitor Output field should now show the board you selected and the progress of flashing the bootloader to the **target** Arduino board.
83+
- Wait for it to show “Done!”
84+
- Unplug the **programmer** Arduino board from your computer.
85+
- Disconnect the programmer Arduino board from the target Arduino board.
86+
87+
**Congratulations** you have now successfully burned the bootloader on your Arduino board and can go back to upload sketches like before.
88+
89+
## SD card
90+
### Requirements
91+
- An extra SAMD-based Arduino board to use as the programmer.
92+
- 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)), a shield (e.g., [MKR SD Proto](https://store.arduino.cc/products/mkr-sd-proto-shield)), or one of the common SD modules.
93+
- An SD card that fits your SD slot.
94+
- A way to connect the SD card to your computer.
95+
- A way to make connections to the SWD pins on your target Arduino board.
96+
97+
For the [Nano 33 IoT](https://store.arduino.cc/products/arduino-nano-33-iot?_gl=1%2A80ta1j%2A_ga%2AMjEyMzQ2MjgwOC4xNjY1NjUyNTY3%2A_ga_NEXN8H46L5%2AMTY3MTYyNzMzMS4xNjEuMS4xNjcxNjMwNDIwLjAuMC4w) and the **MKR Boards** other than **MKR1000** ([tutorial](https://support.arduino.cc/hc/en-us/articles/360014905199-How-to-burn-the-bootloader-to-Arduino-MKR1000-using-a-programmer?queryID=ae55269235f9756d76c0b66bbb8ffa69)), we found it the easiest to use a 0.1" pitch 2x3 pogo adapter. You could also solder wires to the test points if you prefer.
98+
99+
On the MKR boards other than the MKR1000, the SWD header is on the bottom of the board and is the footprint for a 0.1" pitch 2x3 SMD header.
100+
101+
On the MKR1000, it is a 0.05" pitch 2x5 male header on the top of the board, which you will need an [adapter](https://www.adafruit.com/product/2743) and one [cable](https://www.adafruit.com/product/1675) for.
102+
103+
### Instructions
104+
- Connect the SD card to your computer.
105+
- Open [this link](https://github.com/arduino/ArduinoCore-samd/tree/master/bootloaders) in your browser.
106+
- Click the folder that matches the name of your target board.
107+
- Click the file that ends in `.bin`
108+
- Click the **Download** button.
109+
- Rename the downloaded file to `fw.bin`
110+
- Move `fw.bin` to the SD card.
111+
- Eject the SD card from your computer.
112+
- Connect the Arduino board you will be using as a programmer to your computer via USB.
113+
- Select **Sketch > Include Library > Manage Libraries...** from the Arduino IDE's menu.
114+
- Wait for the index to finish.
115+
- In the **"Filter your search..."** field, type "Adafruit DAP library".
116+
- Press **Enter**.
117+
- Click on **"Adafruit DAP library by Adafruit"**.
118+
- Click the **"Install"** button.
119+
- You may now get a dialog asking whether to install the library's dependencies. If so, click the **"Install All**" button.
120+
- Wait for the installation to finish.
121+
- Close Library Manager.
122+
- Select **File > Examples > Adafruit DAP library > samd21 > flash_from_SD** from the Arduino IDE's menu.
123+
- Change this line: `#define SD_CS 4` according to the Arduino pin connected to the SD CS pin.
124+
125+
If your board has a built-in SD slot (e.g., [MKR Zero](https://store.arduino.cc/products/arduino-mkr-zero-i2s-bus-sd-for-sound-music-digital-audio-data)), then you can change this line:
126+
127+
`
128+
(!SD.begin(SD_CS)) {
129+
`
130+
131+
to:
132+
133+
`
134+
if (!SD.begin()) {
135+
`
136+
137+
- Select the programmer Arduino board from Arduino IDE's **Tools > Board** menu.
138+
- Select the port of the programmer Arduino board from Arduino IDE's **Tools > Port** menu.
139+
- Select **Sketch > Upload** from the Arduino IDE's menu.
140+
- Wait for the upload to finish successfully.
141+
- Unplug the **programmer** Arduino board from your computer.
142+
- Plug the SD card into the SD slot connected to your Arduino board.
143+
- Connect the **programmer** Arduino board to the target Arduino board as follows:
144+
145+
| Programmer | Target |
146+
| ----------- | ----------- |
147+
| VCC | +3V3 |
148+
| 12 | SWDIO |
149+
| 11 | SWCLK |
150+
| GND | GND |
151+
| 9 | RESETN |
152+
153+
SWD pads on MKR boards other than MKR 1000:
154+
155+
![](assets/SWDpadsMKR.png)
156+
157+
MKR1000 SWD header pinout:
158+
159+
![](assets/SWDMKR1000header.png)
160+
161+
Nano 33 IoT SWD pads:
162+
163+
![](assets/SWDpadsNano33IoT.png)
164+
165+
- Plug the USB cable of the **programmer** Arduino board into your computer.
166+
- Select **Tools > Serial Monitor** from the Arduino IDE's menu. You should now see the Serial Monitor output showing the **target** board detected, and the bootloader file flashed to it successfully.
167+
- Unplug the **programmer** Arduino board from your computer.
168+
- Disconnect the programmer Arduino board from the target Arduino board.
169+
170+
**Congratulations** you have now successfully burned the bootloader on your Arduino board and can go back to upload sketches like before.

0 commit comments

Comments
 (0)