MKR wifi 1010 bootloader

My project uses the MKR wifi 1010 platform and following a bad handling,
I lost or damaged the bootloader.
To fix this problem, I followed 
the Arduino as In-circuit Serial Programmer (ISP) and Arduino Bootloaders tutorial 
accessible from the link
[iurl=https://www.arduino.cc/en/Tutorial/BuiltInExamples/ArduinoISP]https://www.arduino.cc/en/Tutorial/BuiltInExamples/ArduinoISP[/iurl]
Inspired by this tutorial, I made an ISP from an Arduino 101 platform. 
The advantage of the latter is that it interfaces its signals in 3.3V.
By going through the IDE procedure to upload the bootloader:
 • with the Arduino 101 card indicated in the type of card the result is satisfactory
 but it is the relative BLE boot loader of the Aduino 101 which is uploaded
 • with the Arduino MKR wifi 1010 board indicated in the board type, 
an error is immediately declared:
Arduino : 1.8.13 (Linux), Carte : "Arduino MKR WiFi 1010"

java.lang.NullPointerException
	at cc.arduino.packages.uploaders.SerialUploader.burnBootloader(SerialUploader.java:329)
	at processing.app.Editor.lambda$handleBurnBootloader$61(Editor.java:2379)
	at java.lang.Thread.run(Thread.java:748)
Erreur lors de la gravure de la séquence d'initialisation.
In english: Error while burning boot sequence.

Below are the links to access the photo and diagram of the ISP:
Thank you in advance for helping me solve this problem. 
Cordially.
Airel

pre.cjk { font-family: "AR PL SungtiL GB", monospace } p { margin-bottom: 0.25cm; line-height: 115% }pre.cjk { font-family: "AR PL SungtiL GB", monospace } p { margin-bottom: 0.25cm; line-height: 115% }

The "Arduino as ISP" programmer can only be used to program boards of the AVR architecture. It won't work with the SAMD architecture of your MKR WiFi 1010. So the error you're getting is normal and expected.

I'll provide you with instructions for burning the bootloader on the SAMD boards:

You'll need:

  • An extra Arduino board that runs at 3.3 V.
  • An SD slot. This could be built into your Arduino board (e.g., MKR Zero), a shield (e.g., MKR SD Proto Shield), or one of the common SD modules.
  • An SD card that fits your SD slot.
  • A way to connect the SD card to your computer.
  • A way to make the connections to the SWD pins on your target Arduino board. For the Nano 33 IoT and the MKR boards other than MKR1000, I like to use a 0.1" pitch 2x3 POGO adapter. You could also solder wires to the test points if you prefer. 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 (e.g., https://www.digikey.com/short/z3dvdv). On the MKR1000, it is a 0.05" pitch 2x5 male header on the top of the board, which you will need an adapter and cable for.

It is possible to use an Arduino board that runs at 5 V as the programmer, but you'll need to use level shifting circuitry on the programming lines to avoid exposing the target board to 5 V logic levels, which would damage it.


Instructions:

Connect an SD card to your computer.

Open this link in your browser: ArduinoCore-samd/bootloaders at master · arduino/ArduinoCore-samd · GitHub

Click the folder that matches the name of your target board.

Click the file that ends in .bin.

Click the "Download" button.

Rename the downloaded file to fw.bin

Move fw.bin to the SD card.

Eject the SD card from your computer.

Plug the USB cable of the Arduino board you will be using as a programmer into your computer.

(In the Arduino IDE) Sketch > Include Library > Manage Libraries

Wait for the download to finish.

In the "Filter your search..." field, type "Adafruit DAP library".

Press "Enter".

Click on "Adafruit DAP library by Adafruit".

Click the "Install" button.

Wait for the installation to finish.

Click the "Close" button.

File > Examples > Adafruit DAP library > flash_from_SD

Change this line:

#define SD_CS 4

according to the Arduino pin connected to the SD CS pin. If your board has a built-in SD slot (e.g., MKR Zero), then you can change this line:

if (!SD.begin(SD_CS)) {

to:

if (!SD.begin()) {

Select the correct board from the Tools > Board menu.

Select the correct port from the Tools > Port menu.

Sketch > Upload

Wait for the upload to finish successfully.

Unplug the programmer Arduino board from your computer.

Plug the SD card into the SD slot connected to your Arduino board.

Connect the programmer Arduino board to the target Arduino board as follows:

| Programmer | | Target |
| - | - |
| ----------- | |------- |
| VCC | | +3V3 |
| ----------- | |------- |
| 10 | | SWDIO |
| ----------- | |------- |
| 9 | | SWCLK |
| ----------- | |------- |
| GND | | GND |
| ----------- | |------- |
| 11 | | RESETN |
| ----------- | |------- |

MKR board (except MKR 1000) SWD pads:
MKRZero_labeled.jpg
MKR 1000 SWD header pinout:
MKR-1000-SWD.jpg
Nano 33 IoT SWD pads:
Nano33IoT_labeled.jpg

Plug the USB cable of the programmer Arduino board into your computer.

Tools > Serial Monitor. You should now see the target board detected, and the bootloader file flashed to it successfully.

Unplug the programmer Arduino board from your computer.

Disconnect the programmer Arduino board from the target Arduino board.


Note: if you have a CMSIS-DAP debugger, you can just do this instead:

  • Connect the debugger to your Arduino board.
  • (In the Arduino IDE) Tools > Programmer > Atmel EDBG
  • Tools > Burn Bootloader

I use this little open source debugger.

What do you want to do ?
New mail
Copy
Hello Perl,

Thank you for your detailed response.
Before purchasing the various electronic components, 
I want to ask you a question to be sure to avoid mistakes.
About the first point: "An extra Arduino board that runs at 3.3 V." 
Is it possible to use an Arduino Uno coupled to a "level shifting circuitry on the programming lines"?
Cordially.
Airel

I'm not sure. There is conflicting information from Adafruit on this subject. The tutorial says:

Note that an ATSAMD21 based board must be used as the programmer. AVR based boards like the Feather 32u4 will not work.

(The Uno is an AVR board)

but the library's readme says:

Tested with a Metro M0 / Arduino Zero as the 'host' and with ATSAMD21's as the client but in theory any 3.3V Arduino board will work as host (just slower)

As long as you use the level shifter, I don't think it can cause any harm to try it. I would start by simply compiling the library's sketch for the Uno. If it doesn't compile, then you'll know there is an incompatibility at the firmware level before you even need to worry about the hardware.

What do you want to do ?
New mail
Copy
Hello Pert,

To constitute the programmer,
I chose to use the MKR Zero and a micro SD card.
Before establishing the connection with the MKR wifi 1010,
I would like to ask you a question about the modification of the flash_from_SD program. 
The default value of SD_CS is 4, 
should this value be changed next to MKR zero?
I am attaching the .ino file as I modified it.
In advance thank you for your response.
AIREL

flash_from_SD.ino (2.98 KB)

The built-in SD card socket on the MKR Zero uses pin 28 (more conveniently referenced via the SDCARD_SS_PIN macro) for the SD CS pin. The SD library is written to automatically use that pin if you don't specify the SD CS argument to SD.begin():

SD.begin()

, but you are also welcome to explicitely specify the pin if you prefer:

#define SD_CS SDCARD_SS_PIN

What do you want to do ?
New mail
Copy
Hello Perl,

Without making any changes in the flash_from_SD.ino program, 
I connected the MKR wifi 1010 card according to your instructions. 
The firmware was executed, the report is as follows:
Card initialized
Connecting...Adafruit Generic CMSIS-DAP Adapter 123456 v0.1 (S)

Found Target: SAM D21G18A (Rev D)	Flash size: 262144	Flash pages: 4096
 done.
Erasing...  done.
Programming... 89

Done!
I then press the reset button on the MKR wifi 1010 card, its operation is still abnormal.

The operating fault is described below:

  • The yellow LED lights weakly and simulates a pumping effect
  • The MKR wifi 1010 card no longer executes its firmware program. Additionally, there is an error when uploading a new program: "No new serial port detected".
Thank you in advance for helping me solve this problem. 
Cordially.
Airel

Airel:
The yellow LED lights weakly and simulates a pumping effect

A pulsing LED is the signal that the board is in bootloader mode, where the bootloader runs continuously. This is actually not a bad sign.

Airel:
there is an error when uploading a new program: "No new serial port detected".

Did you select the MKR WiFi 1010 serial port from the Tools > Port menu? When the board is in bootloader mode, it is actually normal for the uploader to not detect a new serial port, because the board is already in bootloader mode and so the bootloader serial port has already been enumerated. In this case, you should still see "Done uploading" on the status bar when the upload process finishes, rather than an error message.

I've followed your instructions for burning the bootloader on the SAMD boards with big interest.
The bootloader of my MKR WiFi 1010 is also corrupted, so...
The 1st try wasn't very succesful, however.
I'am using the SD on my MKR ENV Shield, and there the pins 9, 10, 11 are already in use for SDK, MISO and SDA respectively.
So, I changed the defines for SWDIO, SWRST and SWCLK in the flash_from_SD sketch to the free pins 5, 3 and 2.
That did the job!

Congratulations on rescuing your MKR WiFi 1010 @ostwhc!

Once I learned this technique, not only was I able to recover my Arduino board, I also felt more comfortable experimenting because I wasn't so worried about accidentally bricking my boards.

Hello Pert, I managed to upload the bootloader correctly, given the positive report from the flash_from_SD sketch, but unfortunately the problems are still there.
I've still communicating problems between the MKR WiFi 1010 and the IDE, both online and offline.
The USB connection is randomly disfunctional, from session to session.
With my UNO and another MKR1010 all goes well.