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
How to Debug Arduino Boards using SWD Interface¶
In this wiki, you will learn how to use SWD Interface to debug your Arduino boards via the J-Link Debug Programmer. For reference, Wio Terminal is used as the hardware to demonstrate the debugging process.
What is SWD Debugging¶
SWD, also known as Serial Wire Debug is a 2-pin interface (SWDIO/SWCLK) of which it's also an alternative JTAG interface that has the same JTAG protocol. SWD uses an ARM CPU standard bi-directional wire protocol, defined in the ARM Debug programmer.
Before you start, you will need the following materials:
Wio Terminal (or Other Arduino Boards with SWD Interface)
J-Link Debug Programmer
Wio Terminal SWD Interface¶
For Wio Terminal, the SWD interface pads are on the bottom of the front side of Wio Terminal (Bare PCBA without casing). There are three jumper wires that need to be led out:
Once the jumper wires are soldered on, we can connect them to the J-Link Debug programmer following the SWD Pin Map:
Connect as followed:
- (Wio Terminal) -> (J-Link Debug Programmer Pin 7)
- (Wio Terminal) -> (J-Link Debug Programmer Pin 9)
- (Wio Terminal) -> (J-Link Debug Programmer Pin 4)
Installing J-Link GDB Server for Debugging¶
To debug with J-Link Debug programmer, you will need to download the J-Link GDB Server. Download and install according to your OS.
Before launching J-Link GDB Server, you will also need to open IDE for later configurations.
1. Obtaining the Arduino Sketch ELF File Path¶
In the settings of Arduino IDE, make sure that the Show verbose output during compilation and upload are both ticked.
Under the Arduino sketch you want to debug, click Compile (select Wio Termianl as board), and check the log information to get the path of the file location. Let's take as example:
Copy this path and it will be used later for GDB.
For example, in my case:
2. Obtain the GCC Path¶
Under the same sketch compile log information, you can also find the GCC path used by Arduino of which also can be used for J-Link Debug Programmer later.
For example, in my case:
Getting Started with J-Link GDB Server¶
Connect the J-Link Debug Programmer to the PC and also power Wio Terminal from the USB port. Launch the J-Link GDB Server, select the following settings:
- Connection to J-Link: USB
- Target Device: Cortex-M4
- Target Interface: SWD
Select OK and if everything goes well you should see the following screen:
You should see that the listening port will appear and the J-Link GDB server is up and ready!
Launching a GDB Client¶
Now you can launch the GDB Client by using the path we've saved earlier from the GCC path in Arduino. Open Terminal and paste the copied path + :
Run the following commands under gdb:
- + Arduino Sketch ELF File Path, i.e.
Now you can use GDB to debug your Arduino Sketch!
You can also create a file, copy the following and save it in the location to avoid keep repeating setting process for gbd.
Now if you just launch the GDB client and you can start debugging straight away!
Some useful commands for GDB:
Q1. How to take off the enclosure of Wio Terminal?
A1. First, take out the 4 rubber pads of 4 corner, and you will see 2 screws that holds the Wio Terminal enclosure together. Simply unscrew them and you can take it apart.
- Narrow outdoor plant stand
- Lego tie fighter ebay
- Sans in steven universe
- Simplex fire alarm speakers
- Ada condos for sale
Open-Source SWD Programming Adapter
After making the switch from AVR to STM32 microcontrollers, I redesigned my old 6-pin ICSP pogo-programming adapter for SWD. The new design allows programming with pogo pins or a small pin header soldered to the pogo pads for debugging, all with the same cable. The footprint uses surface mount pads only, so it can be placed on even the most compact board layouts.
The ST-link adapter
I designed a small PCB which mounts directly on top of an st-link programming pod. The board has an LED that lights up when the target is powered, and also has a jumper that powers the target from the st-link’s onboard regulator. This feature is great when mass pogo-programming low-power PCBs.
The board also has a 0.05″ pitch ribbon cable connector. This connector is quite rugged and easy to use, and has the same pitch as the programming footprint that it interfaces with. Premade cables are available from Digikey for a fairly reasonable price.
PCB Footprint and Header
The PCB footprint is nearly the same as my old 6-pin footprint, but without any vias for alignment. This footprint could easily be modified to use vias to align the pogo pins, but I find that aligning 4 pins is quite easy even without alignment features. The footprint is small enough to fit on pretty much any design, and should optimally be placed on the edge of the board so a pin header can be soldered on, if desired.
One of the best features of this footprint is that you can solder on a 0.05″ pitch header along the edge of the board. The ribbon cable from the programmer can plug right into this connector without any adapter. This is great for debugging on the bench when you don’t want to solder wires directly to the pads or hold a pogo programmer in exactly the right position for extended periods of time.
Pogo Programming Adapter
The pogo programming adapter is a very simple board, with only a ribbon cable connector, an LED, and pogo pin mounting holes. Inserting and aligning the 4 pogo pins is quite easy as opposed to the 6 and 8 pin versions I used previously. When connecting to a powered target, the LED is a nice indicator that at least two of the pogo pins are making good contact with the board.
Read more: Open-Source SWD Programming Adapter
Using the Segger J-Link Debugger with the MKR Boards
This tutorial teaches you how to set up a MKR board with the Segger J-link debugger.
This tutorial will show you how to debug an Arduino sketch using an Arduino MKR board and the Segger J-Link probe. It will go through how to connect these and use the Arduino IDE 2.0 to then debug a sketch.
Required Hardware and Software
J-Link Debug Probes
J-Link debug probes are one of the most widely used line of debug and programming probes in the market. They have provide solid value to embedded development for over a decade. J-Link supports a wide range of CPUs and architectures, everything from single 8051 to mass market Cortex-M to high-end cores like Cortex-A. One of the main features of J-Link debug progbes is its support of several debugging/programming interfaces like JTAG, SWD and SWO. For debugging SAM-based Arduino® boards with A J-Link probe, you are going to use its SWD interface.
The SWD Interface
JTAG is the de facto interface for debugging and accessing a processor registers. This interface has been used for many years, and it is still largely used today. But JTAG has a drawback: it uses many signals (or pins), at least four. To address this drawback, ARM® created an alternative debug interface called the Serial Wire Debug (SWD) interface.
The SWD interface is a two-pin (SWDIO/SWCLK) electrical alternative to the JTAG interface that has the same JTAG protocol on top. The SWD interface can be used to program the firmware of a processor and access its registers for debugging purposes. This interface and its associated protocol are now available in nearly all ARM® Cortex®-A, Cortex®-R, and Cortex®-M processors.
Before you can connect your J-Link probe to your Arduino® MKR board, you must prepare the SWD interface pins of the board. The Arduino® MKR boards have the SWD interface pins, SWDIO and SWCLK, connected to the J2 header. The J2 header of the Arduino® MKR boards is located on the underside of the board in the exposed pads.
Note: The goal is to reach the exposed pads that are located on the underside of the board, feel free to choose one of the two methods that are explained in this tutorial or to implement another solution not mentioned here.
Connecting the Board and Device with MKR Proto Shield
A method for connecting that doesn't requires any soldering, uses a MKR Proto Shield and 6 2.54mm straight male headers to access the exposed pads of the MKR board as shown in the images below:
Besides not requiring any soldering, with this method the MKR Proto Shield remains fully reusable. Now you can connect the mini-squid cable to the straight headers in the shield.
Connecting the Board and Device with Soldering
It is also possible to solder connectors onto the exposed pads on the back of the MKR board, that will then allow us to connect the J-Link adapter to the board. Refer to the illustration below to see where the connectors need to be soldered.
If there is an adapter or cable already plugged into the J-link, remove the FLAT cable or J Link adapter and expose the male pins. Connect the MKR to the J-link using female to female jumper wires, use the illustration below to know which pins to connect.
When the connections have been made, simply power the J-link probe and the MKR via USB (micro USB and type A cables).
Installing the J-Link GDB Server Software
If you haven't already, download and install the Arduino IDE 2.0, this will be used to debug our sketch. You will also need to download the J-Link GDB Server software, here. The J-Link GDB Server is a remote server for the GNU Debugger (GDB) which allows to use a J-Link probe with GDB or any toolchain which uses GDB as debugging interface, like the Arduino IDE 2.0.
Note: write down where you installed the J-Link GDB Server software in your computer, this install path will be useful in the next step.
Debugging in Arduino IDE 2.0
Now we are ready to start debugging our sketch. Connect the power to the MKR board and the J-link to power them up. Start Arduino IDE 2.0 and select your MKR board in the deployable menu where you specify the board and port.
Then create or open the sketch that you want to debug. If you don't already have a sketch in mind, feel free to use the example sketch found at the end of this tutorial.
Now go to the folder where the sketch is located. Add a file in the same folder as your sketch and name it . The easiest way would be to create a text file and rename it . In the file, add the following lines:
The needs to be changed to the location where you installed the J-link package in the previous step. When this is done, click on the debugging icon.
You should see a window similar to the one shown below. Do not close this window, just minimize it and you are now ready to start debugging. You can add breakpoints, inspect variables, halt the execution and more.
In this tutorial you learned how to connect your MKR board to a Segger J-Link probe. And then how to use this setup to debug a sketch with Arduino IDE 2.0.
Now that you have your hardware set up, you can learn how to use the IDE 2.0 Debugger through the Debugging with the Arduino IDE 2.0 tutorial. This tutorial goes through some key features of the Debugger, and includes pointers to get started.
Contribute to Arduino
Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.
Check out our store and get what you need to follow this tutorial.
VISIT OUR STORE
Programmer arduino swd
Hello everyone, I'm here the share my last two months of work for those just like me who are still struggling with getting a much affordable JTAG debugger. Thanks for the new ARM CMSIS-DAP specs, and the great CMSIS-DAP project from mbed, I learned a lot from those fanstatics guys behind it, However, I want to move the project further, more open, more affordable, more easy to re-make, more customizable for serious firmware debugging.
Let me introduce you IBDAP, a gcc version of CMSIS-DAP. I had this idea of making IBDAP when I was trying to solve a firmware issue of another project and then realized that I really really need a debug probe to do code steppings in order to figure out the problem. I searched online for a long time and realize that debug probes are either super expensive, like Segger J-Link or they are not universally compatible between vendors. I decided to make my own, here it comes IBDAP.
There are some versions of CMSIS-DAP implementation on the market, one is the reference implementation from ARM and the other is from mbed project. However, you still need a Keil MDK Professional edition software in order to build the firmware, even the open source one provided by mbed and the price for Keil Professional is intimidating. All these barriers has become the first issue that every inventor is facing, and we need a solution!
IBDAP's objective is to become an affordable open source & open hardware CMSIS-DAP JTAG/SWD debug probe implementation using gcc and makefile. Anyone can modify and embed a debug probe on its own device easily with everything under its control.
Currenty, IBDAP has been tested on LPC11U35 and nRF51822 chips using Keil and OpenOCD. In the future, we are planning to test it with CC3200 and other microcontrollers. Future plans includes USB-TTL relay and USB drag-n-drop programming in gcc.
I'll bring bring the IBDAP to the New York Maker Faire for exhibition. For those we are coming to the event, come and see the project and probably some other projects:
Facebook page: https://www.facebook.com/armstart
Google+ : https://www.facebook.com/armstart
Heads up! This tutorial was written for ARM microcontrollers with SWD or JTAG pins. You will need a dedicated programmer (i.e. J-Link EDU Mini or J-Link EDU Base) to connect to the port. If you are using an AVR microcontroller with an Arduino bootloader using ICSP pins, you'll need to head on over to the Installing an Arduino Bootloader tutorial.
SparkFun has been a fan of Arduino for a long time. We've programmed ATMega328s (and 168s, and 8s before that), written tutorials, and hacked all sorts of fun projects. But now the market is maturing and we are looking at a lot more ARM chips. One advantage of the newer chips is that they generally do not need a USB-to-serial adapter; instead they have USB built in (at least the ones we are using do). You still need to add a bootloader to use them with Arduino, and since ARM programmers are also a little more complicated than AVR programmers you'll want to invest in a stand alone programmer instead of trying to use the Uno you have laying around.
Please Note: Most SparkFun boards come pre-programmed. This tutorial is meant to provide information if you wish to re-program your board or change the bootloader.
A few ARM boards:
To follow along with this tutorial, you will need the following materials. You may not need everything though, depending on what you have. Add it to your cart, read through the guide, and adjust the cart as necessary.
If you aren’t familiar with the following concepts, we recommend checking out these tutorials before continuing.
What is an ARM?
Let's start with what an ARM processor is. They are used in everything from the Redboard Turbo to the Raspberry Pi to most cellphones, but that's a large range of performance. ARM is actually a unique business model. Arm Holdings does the design work for the cores and holds the patents/copyright/other legal things and then licenses the design out. The cores are then put into CPUs, microcontrollers, SOCs (System on Chip), etc. A company might decide they want to build a camera that uses the ARM core. They can license the core, maximize power efficiency, add some silicone for the camera sensor interface, and build the entire system onto a chip.
If you look around you'll actually see quite a few naming conventions. The v7 architectures lists 3 different profiles:
- Cortex-A: the Application profile
- Cortex-R: the Real-time profile
- Cortex-M: the Microcontroller profile
We are going to be looking at Cortex-Ms. The Cortex M0/M0+ and M1 are actually from the v6 architecture and can be considered a subset for the v7 profile. All that to say that we are going to be looking at programming the SamD21 on our Redboard Turbo (and other boards) as well as the SamD51 on the Thing Plus. The SAMD21 is an ARM Cortex-M0, where the SAMD51 is an ARM Cortex-M4F.
A bootloader is a small piece of code that looks at the programming port (in this case USB) to see if there is new code coming in. If there is, then it takes the code and puts it in a predetermined location. If there isn't, then it runs the code currently at that location.
Most Arduino boards have a bootloader that allows us to upload code over a USB port (or UART Serial connection). This way, once the bootloader is installed, we can program the board much easier. But sometimes we want to change the function of the bootloader, install a bootloader on a brand new board, or just skip the bootloader and install our code directly (makes it harder for other people to change the code on, say, a commercial product).
The bootloader we recommend using is the UF2 bootloader. You can go here for more information on UF2 bootloaders, or click on the button below to go to SparkFun's SAMD Bootloaders GitHub Repo:
SparkFun SamD UF2 bootloaders
UF2 is a file format designed by Microsoft that stands for USB Flashing Format. This format was designed for PXT (also known as Microsoft MakeCode) and allows for programming boards over the Mass Storage Class (removable drive). The bootloader is also compatible with BOSSA which is what the Arduino IDE uses. In other words, UF2 lets you write MakeCode, use Circuit Python, and use the Arduino IDE, all in one bootloader.
Whether you use the UF2 bootloader or another bootloader, you're going to have to download the file. Make sure the file you download is compatible with the board/configuration you are using. Check out our GitHub Respository for the SAMD bootloaders; the Turbo bootloader should work with these boards (you want the *.bin file).
JTAG and SWD
Joint Test Action Group
JTAG stands for Joint Test Action Group (the group who defined the JTAG standard) and was designed as a way to test boards. JTAG allows the user to talk to the bits and pieces of the microcontroller. In many cases, this involves giving them a set of instructions or programming the board. The JTAG standard defines 5 pins:
- TCK: Test Clock
- TMS: Test Mode Select
- TDI: Test Data-In
- TDO: Test Data-out
- TRST: Test Reset (Optional)
The reduced pin count JTAG definition really only consists of 2 pins:
- TMSC: Test Serial Data
- TCKS: Test Clock
The 20 pin connector you see on some programmers was designed for JTAG and all those extra pin can be used for power, ground, and other things. While JTAG does not define a physical pin layout, there are a few common options. The 20 pin connector you see on Segger's J-Link EDU Base and Base Compact programmer is a good example.
Serial Wire Debug
Serial Wire Debug (SWD) is really just a modification/implementation of JTAG specifically for ARM processors. SWD puts the 2 pins (SWDIO and SWCLK) on top of the JTAG pins allowing a user to use either JTAG or SWD without the need to breakout more pins.
Programmers and J-Link Software
SparkFun now carries 3 different ARM programmers from Segger. If you are just getting started and don't plan on making any money off your project, then the EDU Mini is a great place to start. If you want something a bit more powerful, the J-Link Base EDU is a good option. If you are planning on making money, you cannot use the EDU versions, in which case I recommend the Base Compact that we carry. This is the cheapest Segger ARM programmer without an EDU license. There are plenty of higher end programmers as well, but based on their price, you are only going to grab those if you know exactly what features you need from them. But don't worry, all these are more than capable of programming our boards.
First step is to download the J-Link Software. This software is good for updating the firmware on the programmers. Go ahead and open the Jlink Configurator and see if your programmer needs an update. The J-Link Software packages has a lot of features you can dig into, but we aren't going to use them. Feel free to play around and explore the software and all the debugging has to offer.
J-Link Software Download Page
Now it's time to hook things up. We will need to make sure that SWCLK and SWDIO are both connected to the microcontroller. On some of our larger boards, like the SAMD21 Dev board and the RedBoard Turbo, we managed to get the full 10 pin header. Our footprint shows a small dash where pin 1 goes. If you check the pinout above you'll notice that the notch goes on the same side as pin 1. You will probably want a 2x5 header to connect the cable to the board (you can either solder it on, or hold it on securely while programming).
|10 Pin Headers on Various SparkFun Boards|
|SAMD21 Mini||RedBoard Turbo||SAMD21 Dev|
On other boards such as the ProRF or the SAMD51 Thing Plus you may have to dig into the schematic or board files to find the test points. There is at least one test point on all our boards since we program the boards after they are assembled and need access to them. Programming these might be a bit trickier without a jig, but I recommend holding a pair of jumper wires against the pads while uploading. It should only take a few seconds to program, but might be tricky and require an extra pair of hands.
|Test Pads on the SparkFun SAMD51 Thing Plus Board|
|SAMD51 Board with SWDIO above MISO and SWDCLK below MIOS||Back of SAMD51 board showing the 2 testpads|
With the 2x5 header soldered into the 10 pin headers, connecting to the RedBoard Turbo is fairly straightforward:
⚡ Don't forget to power your board! Because of all the various power options, the J-LINK programmers will generally not power your board by default. That means you'll need to power it over USB, battery, or something else. Just make sure your board gets power (and ground).
Now that we've gotten everything hooked up it is time to program. There are a few different options for programming. Atmel studio is a great option (assuming you are using an ATMEL ARM processor like the SAMD line). Atmel Studio also lets you write programs in C, and compile your code. The Arduino IDE also lets you compile and download a *.hex file of your code. Make sure you download and install Atmel Studio (Windows 7 or later only)
Download Atmel Studio 7
Atmel Studio 7 Installation Instructions
Next, we'll go to the Memories tab, you'll probably want to select "Erase Flash before programming", and then select the location of your bootloader or other code. Hit Program and you should be good to go after a second or 2.
Having a hard time seeing? Click the image for a closer look.
Bootloader Protect Fuse Bits
If you get an error when trying to program, check the Fuses tab. On many of our boards we set the bootloader protection to protect from accidental overwriting. Basically this defines the size of the bootloader. Setting this value to 0x07 will set the bootloader size to 0 and allow you to write to that space.
Error Reading Device Signature and Flashing
If you receive the error below:
This may be due to a few things:
- clock speed is too high
- try setting the the programmer to 1/4 of the frequency of the target device
- the wiring of the 2x5 header may be different depending on your programmer
- check the user manual on the programmer and ensure that the pinout matches the target's header pins
- ensure that the solder joints are good
- target device is not powered
- since the programmer does not provide power, make sure you are providing power to your target device
In this particular case, it was due to the wiring of the 2x5 header on the Atmel JTAGICE3 port. It was different from the 2x5 header on the target device. The latest Atmel JTAGICE has two ports and an adapter to correctly connect to the 2x5 header.
Resources and Going Further
Need more information? Check out some of the links below:
Check out these other great tutorials for ARM based boards from SparkFun:
- Fye quotes for instagram
- The real mr acl
- Couple promise rings
- Music starry projector bluetooth
- Matthew 10 27 kjv
- Ed hardy hoodie
- 2004 bmw x5 reliability
- 2015 volkswagen jetta
- Redneck mullet haircut
- Wowhead allied races
- Corten steel square planter