Developing Embedded Applications with VS Code Arduino
By: Greg Terrell
Tags: Segger, Arduino, Debugging, Vscode, Arduino Ide

Based on the popularity of the “Feather” form-factor created by Adafruit, there are numerous people out there working with a similar setup to one I use frequently. I also know there are experienced developers out there familiar with enterprise software tools that find the Arduino IDE frustratingly simple.

The Arduino IDE is a good set of training wheels for simple projects and a straight-forward tool for non-developers to get started creating IoT embedded applications. But for those of us creating something more, it doesn’t have the horsepower we are used to and need for productive development.

Enter Visual Studio Code Arduino, a nice extension to Microsoft Visual Studio Code for creating embedded applications in the Arduino style. If you aren’t familiar with VS Code, it is a highly extensible, open-source, runs anywhere code editor. Runs anywhere means Windows (of course) but also Linux x64 and macOS on Apple devices.

For those of you with experience in Visual Studio, VS Code is a lightweight sibling with a short learning curve. Because of its popularity there are some great extensions for a huge list of development scenarios. Enough about VS Code; if you aren’t convinced yet, look around and you won’t have to look far.

One thing I like about the VS Code Arduino approach is that it stays close enough to the Arduino IDE environment that switching back and forth between the two is not difficult. I need to write library software that Arduino IDE users could consume, so the examples I create need to be tested and run from the Arduino IDE environment. If you are writing software to share with others using the Arduino IDE, VS Code Arduino will let you do that without changes to your code. This is good, because while I really like VS Code Arduino, there are others that will find its takes a little more experience than they have; they should stick with the Arduino IDE until they are ready.

Through the rest of this guide I am assuming you are comfortable with the Arduino IDE, embedded libraries and boards, and embedded development in general. If so and you are ready to move on to a more powerful development workflow, below I will show you my development workbench for SAMD devices that has helped increase my productivity a great deal.

One other thing… debugging.

Debugging is core to software development. You can do it slow or do it fast. But no matter how you do it, you will be debugging your code. I prefer fast.

To debug efficiently, like many enterprise developers are used to, in the embedded space you need a debug probe. The debug probe connects to the processor in your embedded device and interfaces with your development environment to set breakpoints, inspect variables and upload your software into your device.

The reigning king of embedded debugging is Segger and their J-Link family of debugging probes. You can find J-Links everywhere and for the hobbyists reading this, there are cost effective EDU versions you can use for your non-commercial projects.

The Setup: Adafruit Feather M0 Express and Segger J-Link Plus

I am using a J-Link Plus attached via USB.

You can benefit from VS Code Arduino as simply a better code editor than the Arduino IDE, you don’t have to invest in a debugger. But if you are serious about writing embedded applications you should consider that a must purchase.

Setup

To start you will need to install VS Code. You will also need to install Arduino IDE. VS Code Arduino relies on some Arduino functionality to build applications and to manage both libraries and 3-party boards (like Adafruit or Sparkfun SAMD development boards).

To use a Segger J-Link you need to also install the Segger combination software and documentation download (see downloads section at the end of this article for a recommended set of links).

To add superpowers to your VS Code environment, I recommend you do that from within VS Code using the built-in Extensions manager (Ctrl+Shift+X).

VS Code, Extension showing list of install extensions

To install an extension, search for the extension by entering its identifier (listed below, use the Bold highlighted text for the search phrase). Note the cortex-debug extension is only useful if you have a J-Link in you workflow. There are plenty of other useful VS Code extensions, but the ones listed below directly support the topics here.