Main Content

ARM Programming

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.

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.

Bootloaders
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:

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.”

Link to article