Now that we have setup Visual Studio and can use it to program any board (provided it has an Arduino board support package), let’s look at real, hardware-based debugging. The setup is a bit simpler than it was in Eclipse because the OpenOCD and GDB configurations are specified in the board-specific “platform.txt” that the Arduino build recipe uses during the build process, instead of being defined in the IDE.
We will use the “blink” of the previous post as a starting point, on an “Arduino Zero (Programming Port)”. Watch this space for an upcoming article on how to setup boards with chips other than the ATSAMD21G18.
1/ Hardware requirements
As discussed here, we will need a debug probe – a small but worthwhile investment since it will make our life much easier than LED-based debugging.
2/ Software requirement
We are going to need two tools:
- Android SDK, which contains the debugger used by Visual Micro
- Visual Micro GDB, a small plugin that comes on top of the ‘basic’ Visual Micro plugin that we installed previously. More details on the official website
3/ Installing the Android SDK for Visual Studio
Note: Before proceeding, make sure Visual Studio is not running
First of all, we need to install Android SDK for Visual Studio, since it includes a debugger that Visual Micro uses. To do so, launch “Visual Studio Installer” from the Windows startup menu.
Click on “Modify” button under Visual Studio Community 2017.
In the new window, select “Mobile Development with C++” and click on the “Modify” button in the bottom right corner. The installer will download the files (~10 GB), which can take a while.
After the installation is over, you can restart Visual Studio.
4/ Installing the Visual Micro GDB plugin
Now we need to install the plugin called “Visual Micro GDB” in the Visual Studio environment. Select “Extensions and Updates” from the “Tools” menu.
In the new window, select the “Online” tab from the sidebar and search for “arduino”. Download the plugin called “Arduino GDB for Visual Micro 2017”.
To apply the changes, restart Visual Studio. Agree to the license terms, and wait for the installation to complete.
5/ Launching a debug session
To launch a debug session, make sure the GDB debugger is enabled instead of Visual Micro’s own serial debugger. To do that, select “Micro GDB Debugger” from the “Debugger” submenu, in the “vMicro” menu.
In the output window of Visual Studio, you should see a message telling you that it is now configured to enable GDB debugging.
To access to the debug toolbar, check “Debug” in the View > Toolbars menu.
To avoid any further error messages when starting a debug session, make sure to uncheck “build” in the “Configuration Manager”. You can open this window by selecting it in the “Build” menu.
Compile and upload your code. You will have to do it every time you make changes, otherwise it will not be taken into account by GDB. Finally, you can start the debug session by either, clicking the “Start” button in the debug toolbar, or by selecting “Start debugging” in the “Debug” menu. The layout of Visual Studio will change slightly and look like this:
Use the toolbar to easily control the session and jump from your breakpoints. To end a debug session, simply hit the “Stop” icon in the toolbar.