Has anyone programmed the Zero using SWD?

Development pretty much finished on the Zero board so I am looking at producing a custom board. To save complication and board size I hope to program this board using SWD. Has anyone actually used SWD programming in a real project? I can find plenty of theoretical uses but I can't find anyone who has actually used the SWD programming capability, if it has been done there must be someone here that has done it.

The plan.
Transfer the Arduino sketch to Atmel Studio 7 since it does not look as though the Arduino IDE has any way of emulating SWD. Use Atmel ICE. Program the SAMD21G using a minimum number of pins (5?) configuration.
SWCLK, SWDIO, reset, ground, 3v3 (which looks as though it is an Atmel ICE reference voltage only). It looks as though a bootloader is not required (sorry, I am pretty new to microcontrollers).

Questions please.
Does the plan sound OK in practice or have I missed something important?
Do I need to do anything with the two zero ohm resistors in the SWD signal lines?
I will keep the programming wires as short as possible - would 8 inches be OK?

It would be nice to be able to create a little SWD users guide in this thread because I am sure I am not the only one with plans like this.

Thanks a lot, Brian

It would help to explain at least once what SWD stands for. I have a lot of posts (as you can see) but have never heard of it (I understand what the expansion means: Serial Wire Debug - but I had to Google for the acronym).

I'll move this to the Zero section for you.

SWD is quite common outside the Arduino environment.

FWIW Brian I have just designed two boards with just the SWD interface, different chip (SAMG55) but same thing really. I have yet to actually use SWD though.

I'll bring up my schematics and post here soon.

I stress that this has not been tested, PCBs are currently being made. Ask me in a few weeks if it works :slight_smile:

You can use the Arduino IDE to upload to bare SAMD21 board using an Atmel ICE programmer through SWD. It is very easy and you don't have to use Atmel Studio. Use the 10 pin SWD/JTAG connector (see Arduino Zero schematic) to connect your board and you'll be fine. When programming, use the "Upload using programmer" function of the IDE. Even if there is a bug with the Atmel ICE, you can use this function by selecting the EDBG option.

Thanks Nick and thanks to everyone for the replies.

AloyseTech, that's really interesting that the Arduino IDE will work. I will try it.

Of course, the SWD connector (SWD is the way the Atmel 7 IDE refers to the process) is not installed on the board so I will connect a standard header to the Zero board through some thin wire and try a programming session. I will report back.

This programming method certainly seems the best way to go with a custom board. As with some of the other posters my board is being turned from a schematic to Gerbers right now but I still have time for some tests.

.

...I will connect a standard header to the Zero board through some thin wire and try a programming session.

I use the 1.27mm, 2x5 way, Harwin M50 connector as the SWD header on my Zero based custom boards: http://uk.farnell.com/harwin/m50-3500542/connector-header-tht-1-27mm-10way/dp/1022305?ost=1022305&selectedCategoryId=&categoryNameResp=All%2BCategories&searchView=table&iscrfnonsku=false

It allows the Atmel ICE to be connected directly and the bootloader to be burnt using the Arduino IDE.

MartinL

What is the rest of your programming routine please. I have been programming some boards of someone else's design through the "Sketch > Upload using programmer" option but for this I did not think I needed a bootloader. I used a standard Arduino sketch with an AVRISP Mk2 programmer.

As I've mentioned before I am pretty new to microcontrollers although I have some years on VHDL. I thought that if you were programming through a USB port you needed a bootloader but if you just used a programmer you simply dumped the program directly to flash. Is this a matter of using the bootloader to set fuses?

Thanks.

Here is what I have so far.
I mounted the Zero board, a small square of patch board and the Atmel ICE on a piece of plywood to keep things secure. Using the various schematics I found the pin-outs of J100 on the Zero board, the unmounted 2x5 header. I connected J100 pins 1 (3.3 volts), pin 9 (ground), pin2 (data) and pin4 (clk) to a 4 pin header on the patch board. (On my custom board these lines will be bought out on a special pin connector so I will not be using a 2x5 header). In the full Atmel ICE kit Atmel supplies a 2x5 header to connect to the programmer which terminates in individual header sockets labeled 1 to 0 with the zero being pin10. I connected the required individual header sockets 1, 2, 4 and 9 to the corresponding pins on the 4-pin header.

Initially I loaded the Zero with a standard copy of the Blink program into the unit to confirm correct programming using the USB and the EDGB system through the programming socket. The board programmed correctly.

I could not load the Blink program into the Zero using the "Upload using programmer" option through the Zero SWD port and the bootloader was erased. I replaced the bootloader to confirm I could still program the unit through the EDGB. This worked correctly.

I then loaded the Blink program into Atmel Studio 7 which has been extended with the VMicro Add-on. Using purely the options in the VMicro drop-down I was able to program the Zero through the SWD port. The VMicro routine is a little confusing because, although it tells you what to do inside VMicro it does not really explain VMicros operation inside of Atmel Studio 7. In my experimentation I may have accidentally set some required options in Studio 7 so if you try these procedures and they do not work you may need to change some options in the Studio 7 drop-downs.

I changed the on/off times in the Blink program and re-programmed the Zero several times to prove correct operation, everything seems to work correctly.

Conclusion .... A SAMD21G on a custom board can be programmed through the SWD port using only 5 wires. These connections are Ground, 3v3, data, clock and Reset. I am not sure if reset is really needed. The method I used is to transfer the Arduino sketch into Atmel Studio 7 using the VMicro add-on. Then, working through VMicro (possibly requiring certain Studio 7 settings) it is possible to load Arduino sketches unmodified into the SAMD21G.

Hope this helps.
Brian

If you solved this could you help ?

https://forum.arduino.cc/index.php?topic=425358.new#new