So I'm designing a module for a control network, based on the MKR using a SAMD21 chip. I've prototyped this in a small run and have used a black magic probe to upload a simple sketch. This all works so far.
What I trying to do next is to scale things up so I want to build a test jig (using pogo pins etc) that I can attach to the device under test, so that I can upload some test firmware and then run a series of tests before finally loading the actual application firmware.
I have pulled out a header for the SWD pins (SWCLK, SWDIO) plus 3v3 and GND in my board.
Can I use another MKR to program my firmware onto the device under test via these pins.
I've read the examples where the bootloader can be flashed onto a second Arduino, although these look like Atmega based variants rather than SAMD21.
Is there some existing code to allow a SAMD21 device to have a bootloader flashed, or do I need to try some other approach.
I'm trying to simplify the test jig and software behind it.
I.e. rather than having to run 2 USB connections from the host computer to the test jig I'd prefer to run just the one and have the host run through a sequence of steps:
burn the test firmware,
run the test program on the test jig which interacts with the DUT, and finally
Yes those programmers use the SWD pins. I'm guessing that I would need to reverse engineer their protocol, so I'm probably making life hard for myself
However I did find this page which shows something similar.
As you guessed, the Arduino as ISP programmer can only be used with target microcontrollers of the AVR architecture.
In case you are looking for something equivalent to Arduino as ISP programmer for programming ATSAMD21G18-based targets, you might try the "Adafruit DAP library" I'll provide instructions:
An extra Arduino board that runs at 3.3 V to use as the programmer.
Any of the SAMD architecture boards (e.g., MKR boards, Nano 33 IoT, Zero) will work fine.
The sketch is too large for the AVR architecture boards (e.g., Mega), so they can't be used.
The sketch doesn't compile for the Nano 33 BLE, so it can't be used.
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 MKR 1000 WiFi, 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.
Select Sketch > Include Library > Manage Libraries... from the Arduino IDE menus.
Wait for any index updates 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.
You may now get a dialog asking whether to install the library's dependencies. If so, click the "Install All" button.
Wait for the installation to finish.
Close Library Manager.
Select File > Examples > Adafruit DAP library > samd21 > flash_MKR_bootloaders from the Arduino IDE menus.
(despite the "MKR" in the sketch name, this also supports the Nano 33 IoT)
Connect the programmer Arduino board to your computer with a USB cable.
Select your programmer Arduino board from Arduino IDE's Tools > Board menu.
Select the port of the programmer Arduino board from Arduino IDE's Tools > Port menu.
Select Sketch > Upload from the Arduino IDE menus.
Wait for the upload to finish successfully.
Disconnect the USB cable of the programmer Arduino board from your computer.
Connect the programmer Arduino board to the target Arduino board as follows:
Connect the programmer Arduino board to your computer with a USB cable.
Select Tools > Serial Monitor from the Arduino IDE menus.
Select "No line ending" from the dropdown menu near the bottom right corner of the Serial Monitor window.
You should see some instructions for using the sketch in the Serial Monitor output field.
This includes a menu of the boards supported by the sketch:
[...]
Select Arduino MKR board to erase and flash with bootloader:
Z -> Arduino Zero (6504 bytes)
MZ -> Arduino MKR Zero (6408 bytes)
1000 -> Arduino MKR 1000 WIFI (6408 bytes)
1010 -> Arduino MKR WIFI 1010 (7984 bytes)
[...]
Find your target Arduino board on the list and note the code written to the left of it.
Type the code for the target Arduino board in the message field of Serial Monitor.
Press the Enter key.
The Serial Monitor output field should now show the board you selected and the progress of flashing the bootloader to the target Arduino board.
Wait for it to show "Done!"
Disconnect the USB cable of the programmer Arduino board from your computer.
Disconnect the programmer Arduino board from the target Arduino board.