blob: c758015561c6defb231f06c4c06ce0a510483b30 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Developing Mynewt Applications with Visual Studio Code &mdash; Apache Mynewt latest documentation</title>
<link rel="shortcut icon" href="../_static/mynewt-logo-only-newt32x32.png"/>
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../_static/css/sphinx_theme.css" type="text/css" />
<link rel="stylesheet" href="../_static/css/bootstrap-3.0.3.min.css" type="text/css" />
<link rel="stylesheet" href="../_static/css/v2.css" type="text/css" />
<link rel="stylesheet" href="../_static/css/custom.css" type="text/css" />
<link rel="stylesheet" href="../_static/css/restructuredtext.css" type="text/css" />
<link rel="stylesheet" href="../_static/css/overrides.css" type="text/css" />
<link rel="index" title="Index"
href="../genindex.html"/>
<link rel="search" title="Search" href="../search.html"/>
<link rel="top" title="Apache Mynewt latest documentation" href="../index.html"/>
<link rel="up" title="Appendix" href="index.html"/>
<link rel="prev" title="Contributing to Newt or Newtmgr Tools" href="go_env.html"/>
<script src="../_static/js/modernizr.min.js"></script>
<script>
(function(i, s, o, g, r, a, m) {
i["GoogleAnalyticsObject"] = r;
(i[r] =
i[r] ||
function() {
(i[r].q = i[r].q || []).push(arguments);
}),
(i[r].l = 1 * new Date());
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m);
})(window, document, "script", "//www.google-analytics.com/analytics.js", "ga");
ga("create", "UA-72162311-1", "auto");
ga("send", "pageview");
</script>
</head>
<body class="not-front page-documentation" role="document" >
<div id="wrapper">
<div class="container">
<div id="banner" class="row v2-main-banner">
<a class="logo-cell" href="/">
<img class="logo" src="../_static/img/logo.png">
</a>
<div class="tagline-cell">
<h4 class="tagline">An OS to build, deploy and securely manage billions of devices</h4>
</div>
<div class="news-cell">
<div class="well">
<h4>Latest News:</h4> <a href="/download">Apache Mynewt 1.11.0, Apache NimBLE 1.6.0 </a> released September 7, 2023)
</div>
</div>
</div>
</div>
<header>
<nav id="navbar" class="navbar navbar-inverse" role="navigation">
<div class="container">
<!-- Collapsed navigation -->
<div class="navbar-header">
<!-- Expander button -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Expanded navigation -->
<div class="navbar-collapse collapse">
<!-- Main navigation -->
<ul class="nav navbar-nav navbar-right">
<li>
<a href="/"><i class="fa fa-home" style="font-size: larger;"></i></a>
</li>
<li class="important">
<a href="/quick-start/">Quick Start</a>
</li>
<li>
<a href="/about/">About</a>
</li>
<li>
<a href="/talks/">Talks</a>
</li>
<li class="active">
<a href="/documentation/">Documentation</a>
</li>
<li>
<a href="/download/">Download</a>
</li>
<li>
<a href="/community/">Community</a>
</li>
<li>
<a href="/events/">Events</a>
</li>
</ul>
<!-- Search, Navigation and Repo links -->
<ul class="nav navbar-nav navbar-right">
</ul>
</div>
</div>
</nav>
</header>
<!-- STARTS MAIN CONTENT -->
<div id="main-content">
<div id="breadcrumb">
<div class="container">
<a href="/documentation/">Docs</a> /
<a href="index.html">Appendix</a> /
Developing Mynewt Applications with Visual Studio Code
<div class="sourcelink">
<a href="https://github.com/apache/mynewt-documentation/edit/master/docs/misc/ide.rst" class="icon icon-github"
rel="nofollow"> Edit on GitHub</a>
</div>
</div>
</div>
<!-- STARTS CONTAINER -->
<div class="container">
<!-- STARTS .content -->
<div id="content" class="row">
<!-- STARTS .container-sidebar -->
<div class="container-sidebar col-xs-12 col-sm-3">
<div id="docSidebar" class="sticky-container">
<div role="search" class="sphinx-search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search documentation" class="search-documentation" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<!-- Note: only works when deployed -->
<select class="form-control" onchange="if (this.value) window.location.href=this.value">
<option value="/latest" selected>
Version: latest
</option>
<option value="/v1_11_0" >
Version: 1.11.0
</option>
<option value="/v1_10_0" >
Version: 1.10.0
</option>
<option value="/v1_9_0" selected="selected" >
Version: 1.9.0
</option>
<option value="/v1_8_0" >
Version: 1.8.0
</option>
<option value="/v1_7_0" >
Version: 1.7.0
</option>
<option value="/v1_6_0" >
Version: 1.6.0
</option>
<option value="/v1_5_0" >
Version: 1.5.0
</option>
<option value="/v1_4_0" >
Version: 1.4.0
</option>
<option value="/v1_3_0/os/introduction" >
Version: 1.3.0
</option>
<option value="/v1_2_0/os/introduction" >
Version: 1.2.0
</option>
<option value="/v1_1_0/os/introduction" >
Version: 1.1.0
</option>
<option value="/v1_0_0/os/introduction" >
Version: 1.0.0
</option>
<option value="/v0_9_0/os/introduction" >
Version: 0.9.0
</option>
</select>
<div class="region region-sidebar">
<div class="docs-menu">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../get_started/index.html">Setup &amp; Get Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../concepts.html">Concepts</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorials/tutorials.html">Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="../external_links.html">Third-party Resources</a></li>
<li class="toctree-l1"><a class="reference internal" href="../os/os_user_guide.html">OS User Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../network/index.html">BLE User Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../newt/index.html">Newt Tool Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../newtmgr/index.html">Newt Manager Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mynewt_faq/index.html">Mynewt FAQ</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Appendix</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="go_env.html">Contributing to Newt or Newtmgr Tools</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Developing Mynewt Applications with Visual Studio Code</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<!-- ENDS STICKY CONTAINER -->
</div>
<!-- ENDS .container-sidebar -->
<div class="col-xs-12 col-sm-9">
<div class="alert alert-warning">
<p>
Version 1.9.0 is not the most recent version of the
Apache Mynewt documentation. Click <a href="/latest">here</a> to
read the latest version.
</p>
</div>
<div class="">
<div class="rst-content">
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="developing-mynewt-applications-with-visual-studio-code">
<h1>Developing Mynewt Applications with Visual Studio Code<a class="headerlink" href="#developing-mynewt-applications-with-visual-studio-code" title="Permalink to this headline"></a></h1>
<p>This guide shows you how to set up Visual Studio Code to develop and
debug Mynewt applications. Visual Studio Code is supported on Mac OS,
Linux, and Windows. This guide shows you how to:</p>
<ol class="arabic simple">
<li><p>Install Visual Studio Code.</p></li>
<li><p>Install the C/C++ and debugger extensions.</p></li>
<li><p>Define task configurations to build Mynewt applications.</p></li>
<li><p>Define debugger configurations to debug Mynewt applications.</p></li>
<li><p>Launch the debugger.</p></li>
</ol>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><p><a class="reference internal" href="#installing-visual-studio-code" id="id1">Installing Visual Studio Code</a></p></li>
<li><p><a class="reference internal" href="#installing-the-c-c-and-debugger-extensions" id="id2">Installing the C/C++ and Debugger Extensions</a></p></li>
<li><p><a class="reference internal" href="#defining-tasks-for-mynewt-projects" id="id3">Defining Tasks for Mynewt Projects</a></p>
<ul>
<li><p><a class="reference internal" href="#associating-a-mynewt-project-to-a-workspace" id="id4">Associating a Mynewt Project to a Workspace</a></p></li>
<li><p><a class="reference internal" href="#defining-visual-studio-code-tasks-to-build-and-debug-mynewt-applications" id="id5">Defining Visual Studio Code Tasks to Build and Debug Mynewt Applications</a></p></li>
<li><p><a class="reference internal" href="#running-a-task" id="id6">Running a Task</a></p></li>
<li><p><a class="reference internal" href="#defining-tasks-for-other-newt-commands" id="id7">Defining Tasks for Other Newt Commands</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#defining-debugger-configurations" id="id8">Defining Debugger Configurations</a></p></li>
<li><p><a class="reference internal" href="#debugging-your-application" id="id9">Debugging Your Application</a></p></li>
<li><p><a class="reference internal" href="#working-with-multiple-mynewt-applications" id="id10">Working with Multiple Mynewt Applications</a></p></li>
</ul>
</div>
<p>Prerequisites:</p>
<ul class="simple">
<li><p>Have Internet connectivity to fetch remote Mynewt components.</p></li>
<li><p>Have a computer to build a Mynewt application.</p></li>
<li><p>Perform <a class="reference internal" href="../get_started/native_install/index.html"><span class="doc">native installation</span></a> for the
Mynewt tools and toolchains.
<strong>Note:</strong> For Windows platforms, ensure that the MinGW bash you
install is added to your Windows Path. In addition, if you are using
Windows 10 WSL, you must have the MinGW bash before the Windows 10
WSL bash in your Windows Path.</p></li>
<li><p>Read the Mynewt OS Concepts section.</p></li>
<li><p>Create a project space (directory structure) and populate it with the
core code repository (apache-mynewt-core) or know how to as explained
in Creating Your First Project.</p></li>
<li><p>Complete one of the <a class="reference internal" href="../tutorials/blinky/blinky.html#blinky-tutorials"><span class="std std-ref">Blinky Tutorials</span></a>.</p></li>
</ul>
<p><strong>Notes:</strong></p>
<ul class="simple">
<li><p>This guide is not a tutorial for Visual Studio Code. It assumes you
are familiar with Visual Studio Code. If this is your first time
using Visual Studio Code, we recommend that you read the Visual
Studio Code <a class="reference external" href="https://code.visualstudio.com/docs">documentation and
tutorials</a> and evaluate
whether you would like to use it to develop Mynewt applications.</p></li>
<li><p>This guide uses Visual Studio Code on Windows. Visual Studio Code is
supported on Linux and Mac OS but may have some variations in the
keyboard shortcuts and command names for these platforms.</p></li>
<li><p>You can also use the Eclipse IDE to develop Mynewt applications. See
<a class="reference external" href="https://www.codecoup.pl/blog/hacking-mynewt-in-eclipse">hacking-mynewt-in-eclipse</a> for more
details. On Windows platforms, you must also ensure the MinGW bash is
set in your Windows Path as described in the prerequisites.</p></li>
</ul>
<div class="section" id="installing-visual-studio-code">
<h2><a class="toc-backref" href="#id1">Installing Visual Studio Code</a><a class="headerlink" href="#installing-visual-studio-code" title="Permalink to this headline"></a></h2>
<p>Download and install Visual Studio Code from <a class="reference external" href="https://code.visualstudio.com/">https://code.visualstudio.com/</a>.</p>
</div>
<div class="section" id="installing-the-c-c-and-debugger-extensions">
<h2><a class="toc-backref" href="#id2">Installing the C/C++ and Debugger Extensions</a><a class="headerlink" href="#installing-the-c-c-and-debugger-extensions" title="Permalink to this headline"></a></h2>
<p>You need to install two extensions:</p>
<ol class="arabic simple">
<li><p>The C/C++ extension from Microsoft. This extension provides language
support such as symbol searching, signatuare help, go to definition,
and go to declaration.</p></li>
<li><p>The Native Debug extension from webfreak. This extension provides GDB
support.</p></li>
</ol>
<p>To install the C/C++ extension:</p>
<ol class="arabic simple">
<li><p>Press <code class="docutils literal notranslate"><span class="pre">Ctrl-P</span></code> to open the search box.</p></li>
<li><p>Type <code class="docutils literal notranslate"><span class="pre">ext</span> <span class="pre">install</span> <span class="pre">cpptools</span></code> in the search box and press Enter. You
should see the extension at the top of the list.</p></li>
<li><p>Click <code class="docutils literal notranslate"><span class="pre">Install</span></code> to install the extension.</p></li>
</ol>
<p>To install the Native Debugger:</p>
<ol class="arabic simple">
<li><p>Press <code class="docutils literal notranslate"><span class="pre">Ctrl-P</span></code> to open the search box.</p></li>
<li><p>Type <code class="docutils literal notranslate"><span class="pre">ext</span> <span class="pre">install</span> <span class="pre">webfreak.debug</span></code> in the search box and press
Enter. You should see the Native Debug extension at the top of the
list.</p></li>
<li><p>Click <code class="docutils literal notranslate"><span class="pre">Install</span></code> to install the extension.</p></li>
</ol>
</div>
<div class="section" id="defining-tasks-for-mynewt-projects">
<h2><a class="toc-backref" href="#id3">Defining Tasks for Mynewt Projects</a><a class="headerlink" href="#defining-tasks-for-mynewt-projects" title="Permalink to this headline"></a></h2>
<p>Two main concepts in Visual Studio Code are workspaces and tasks. A
workspace represents a folder that is open. You can open multiple
workspaces and switch between workspaces.</p>
<p>Tasks allow you to integrate the external tools and operations that are
used to build or test your project into Visual Studio Code. Tasks are
run from and the task results can be analyzed in Visual Studio Code.
Tasks are defined within the scope of a workspace. This means that the
tasks you define for a workspace only apply to the given workspace.</p>
<div class="section" id="associating-a-mynewt-project-to-a-workspace">
<h3><a class="toc-backref" href="#id4">Associating a Mynewt Project to a Workspace</a><a class="headerlink" href="#associating-a-mynewt-project-to-a-workspace" title="Permalink to this headline"></a></h3>
<p>For your Mynewt
project, your Visual Studio Code workspace is the Mynewt project base
directory. For example, if you create a project named <code class="docutils literal notranslate"><span class="pre">myproj</span></code> under
the <code class="docutils literal notranslate"><span class="pre">~/dev</span></code> directory, then you open the <code class="docutils literal notranslate"><span class="pre">~/dev/myproj</span></code> folder for
your workspace.</p>
<p>Select <strong>File</strong> &gt; <strong>Open Folder</strong>, and select the <code class="docutils literal notranslate"><span class="pre">myproj</span></code> folder from
the <code class="docutils literal notranslate"><span class="pre">Select</span> <span class="pre">Folder</span></code> dialog box to open the folder.</p>
</div>
<div class="section" id="defining-visual-studio-code-tasks-to-build-and-debug-mynewt-applications">
<h3><a class="toc-backref" href="#id5">Defining Visual Studio Code Tasks to Build and Debug Mynewt Applications</a><a class="headerlink" href="#defining-visual-studio-code-tasks-to-build-and-debug-mynewt-applications" title="Permalink to this headline"></a></h3>
<p>You define Visual Studio Code tasks to build and debug your Mynewt
targets in Visual Studio Code. We use the Blinky application for the
Arduino Zero board from the <a class="reference internal" href="../tutorials/blinky/arduino_zero.html"><span class="doc">Blinky On Arduino Zero
Tutorial</span></a> to illustrate how to define
the tasks to build and debug the Arduino blinky bootloader and
application targets.</p>
<p>Perform the following steps to create the tasks to build and debug the
Arduino blinky bootloader and appliction targets:</p>
<p>Step 1: Press <code class="docutils literal notranslate"><span class="pre">Ctrl-Shift-P</span></code>, type <code class="docutils literal notranslate"><span class="pre">task</span></code>, and select
<strong>Tasks:Configure Task Runner</strong> from the search results.</p>
<p>Step 2: Select <strong>Others</strong> (scroll down to the bottom of the list) to
create a task runner for external commands.</p>
<div class="figure align-default">
<img alt="../_images/task_runner_small.png" src="../_images/task_runner_small.png" />
</div>
<p>Tasks are defined in the <code class="docutils literal notranslate"><span class="pre">tasks.json</span></code> file. You should see the
<code class="docutils literal notranslate"><span class="pre">.vscode</span></code> folder created in the <code class="docutils literal notranslate"><span class="pre">MYPROJ</span></code> folder and a <code class="docutils literal notranslate"><span class="pre">tasks.json</span></code>
file created in the <code class="docutils literal notranslate"><span class="pre">.vscode</span></code> folder. The <code class="docutils literal notranslate"><span class="pre">tasks.json</span></code> file has the
following default values.</p>
<div class="figure align-default">
<img alt="../_images/task_json_small.png" src="../_images/task_json_small.png" />
</div>
<p>The sample <code class="docutils literal notranslate"><span class="pre">tasks.json</span></code> file defines a simple task that runs the echo
command with “Hello World” as the argument.</p>
<p>Step 3: Delete the content from the <code class="docutils literal notranslate"><span class="pre">tasks.json</span></code> file, add the
following definitions, and press <code class="docutils literal notranslate"><span class="pre">Ctrl-S</span></code> to save the file.</p>
<div class="highlight-JSON notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="w"> </span><span class="nt">&quot;version&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;0.1.0&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;command&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;newt&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;echoCommand&quot;</span><span class="p">:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;isShellCommand&quot;</span><span class="p">:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;tasks&quot;</span><span class="p">:[</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nt">&quot;taskName&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;build_arduino_boot&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;args&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="s2">&quot;build&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;arduino_boot&quot;</span><span class="p">],</span>
<span class="w"> </span><span class="nt">&quot;suppressTaskName&quot;</span><span class="p">:</span><span class="w"> </span><span class="kc">true</span>
<span class="w"> </span><span class="p">},</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nt">&quot;taskName&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;build_arduino_blinky&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;args&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="s2">&quot;build&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;arduino_blinky&quot;</span><span class="p">],</span>
<span class="w"> </span><span class="nt">&quot;isBuildCommand&quot;</span><span class="p">:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;suppressTaskName&quot;</span><span class="p">:</span><span class="w"> </span><span class="kc">true</span>
<span class="w"> </span><span class="p">},</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nt">&quot;taskName&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;create_arduino_blinky&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;args&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="s2">&quot;create-image&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;arduino_blinky&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;1.0.0&quot;</span><span class="p">],</span>
<span class="w"> </span><span class="nt">&quot;suppressTaskName&quot;</span><span class="p">:</span><span class="kc">true</span>
<span class="w"> </span><span class="p">},</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nt">&quot;taskName&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;debug_arduino_blinky&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;args&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="s2">&quot;debug&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;arduino_blinky&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;-n&quot;</span><span class="p">],</span>
<span class="w"> </span><span class="nt">&quot;suppressTaskName&quot;</span><span class="p">:</span><span class="w"> </span><span class="kc">true</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="p">]</span>
<span class="p">}</span>
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">tasks.json</span></code> file specifies the tasks that are run to build and
debug the Arduino blinky targets. Each task runs a <code class="docutils literal notranslate"><span class="pre">newt</span></code> command. The
<code class="docutils literal notranslate"><span class="pre">newt</span></code> command to run and the arguments for the <code class="docutils literal notranslate"><span class="pre">newt</span></code> command are
passed in the <code class="docutils literal notranslate"><span class="pre">args</span></code> property for each task.</p>
<p>The following tasks are defined in this example:</p>
<ol class="arabic">
<li><p><strong>build_arduino_boot</strong>: Runs the <code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">build</span> <span class="pre">arduino_boot</span></code>
command to build the arduino_boot target.</p></li>
<li><p><strong>build_arduino_blinky</strong>: Runs the <code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">build</span> <span class="pre">arduino_blinky</span></code>
command to build the arduino_blinky target.</p>
<p><strong>Note:</strong> This task sets the <code class="docutils literal notranslate"><span class="pre">isBuildCommand</span></code> property to <code class="docutils literal notranslate"><span class="pre">true</span></code>.
This is an optional property that, when set to true, allows you to
run the <strong>Tasks: Run Build Task</strong>(<code class="docutils literal notranslate"><span class="pre">Ctrl-Shift-B</span></code>) command to
start the task.</p>
</li>
<li><p><strong>create_arduino_blinky</strong>: Runs the
<code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">create-image</span> <span class="pre">arduino_blinky</span></code> command to create the image
file.</p></li>
<li><p><strong>debug_arduino_blinky</strong>: Runs the <code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">build</span> <span class="pre">arduino_blinky</span> <span class="pre">-n</span></code>
command to debug the arduino_blinky target. The <code class="docutils literal notranslate"><span class="pre">-n</span></code> flag is
specified to start only the GDB server and not the GDB client. We
will launch the GDB client from Visual Studio Code.</p></li>
</ol>
<p>For more information on tasks and all supported properties, see the
<a class="reference external" href="https://code.visualstudio.com/docs/editor/tasks">Visual Studio Code Task
documentation</a>.</p>
</div>
<div class="section" id="running-a-task">
<h3><a class="toc-backref" href="#id6">Running a Task</a><a class="headerlink" href="#running-a-task" title="Permalink to this headline"></a></h3>
<p>To run a task, press <code class="docutils literal notranslate"><span class="pre">Ctrl-Shift-P</span></code>, type <code class="docutils literal notranslate"><span class="pre">task</span></code> on the search box,
and select <strong>Tasks: Run Task</strong>. The tasks that you define in the
<code class="docutils literal notranslate"><span class="pre">tasks.json</span></code> file are listed. Select the task to run.</p>
<p>The following is an example of running the <code class="docutils literal notranslate"><span class="pre">build_arduino_boot</span></code> task:</p>
<div class="figure align-default">
<img alt="../_images/task_select_small.png" src="../_images/task_select_small.png" />
</div>
<div class="figure align-default">
<img alt="../_images/task_start_small.png" src="../_images/task_start_small.png" />
</div>
<p><strong>Note</strong>: To run the <code class="docutils literal notranslate"><span class="pre">build_arduino_blinky</span></code> task, you can use the
keyboard shortcut <code class="docutils literal notranslate"><span class="pre">Ctrl-Shift-B</span></code> because the task has the property
<code class="docutils literal notranslate"><span class="pre">isBuildCommand</span></code> set to true.</p>
</div>
<div class="section" id="defining-tasks-for-other-newt-commands">
<h3><a class="toc-backref" href="#id7">Defining Tasks for Other Newt Commands</a><a class="headerlink" href="#defining-tasks-for-other-newt-commands" title="Permalink to this headline"></a></h3>
<p>Other newt commands, such as the <code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">load</span></code> command, do not need to
run from within Visual Studio Code. You can define a task for each
command as a convenience and run the command as a task, or you can run
the newt command on the command line from the Visual Studio Code
integrated terminal or an external terminal.</p>
<p>To create the tasks for the <code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">load</span> <span class="pre">arduino_boot</span></code> and
<code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">load</span> <span class="pre">arduino_blinky</span></code> commands, add the following definitions to
the <code class="docutils literal notranslate"><span class="pre">tasks.json</span></code> file:</p>
<div class="highlight-JSON notranslate"><div class="highlight"><pre><span></span><span class="p">[</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nt">&quot;taskName&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;load_arduino_boot&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;args&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="s2">&quot;load&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;arduino_boot&quot;</span><span class="p">],</span>
<span class="w"> </span><span class="nt">&quot;suppressTaskName&quot;</span><span class="p">:</span><span class="kc">true</span>
<span class="w"> </span><span class="p">},</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nt">&quot;taskName&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;load_arduino_blinky&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;args&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="s2">&quot;load&quot;</span><span class="p">,</span><span class="w"> </span><span class="s2">&quot;arduino_blinky&quot;</span><span class="p">],</span>
<span class="w"> </span><span class="nt">&quot;suppressTaskName&quot;</span><span class="p">:</span><span class="kc">true</span>
<span class="w"> </span><span class="p">},</span>
<span class="p">]</span>
</pre></div>
</div>
<p>To run a command from the Visual Studio integrated terminal, instead of
starting a task, press <code class="docutils literal notranslate"><span class="pre">Ctrl-`</span></code> to launch the integrated terminal and
enter the command on the prompt:</p>
<div class="figure align-default">
<img alt="../_images/integrated_terminal_small.png" src="../_images/integrated_terminal_small.png" />
</div>
</div>
</div>
<div class="section" id="defining-debugger-configurations">
<h2><a class="toc-backref" href="#id8">Defining Debugger Configurations</a><a class="headerlink" href="#defining-debugger-configurations" title="Permalink to this headline"></a></h2>
<p>You need to define a debugger
configuration to launch the GDB debugger from within Visual Studio Code:</p>
<p>Step 1: Select <strong>Debug</strong> &gt; <strong>Open Configuration</strong>, and select the
<strong>GDB</strong> environment.</p>
<div class="figure align-default">
<img alt="../_images/debug_new_config_small.png" src="../_images/debug_new_config_small.png" />
</div>
<p>You should see a default <code class="docutils literal notranslate"><span class="pre">launch.json</span></code> file created in the <code class="docutils literal notranslate"><span class="pre">.vscode</span></code>
folder.</p>
<div class="figure align-default">
<img alt="../_images/launch_small.png" src="../_images/launch_small.png" />
</div>
<p>Step 2: Delete the content from the <code class="docutils literal notranslate"><span class="pre">launch.json</span></code> file, add the
following definitions, and press ‘Ctrl-S’ to save the file.</p>
<div class="highlight-json notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="w"> </span><span class="nt">&quot;version&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;0.2.0&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;configurations&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nt">&quot;name&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;gdb_arduino_blinky&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;type&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;gdb&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;request&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;attach&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;executable&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;${workspaceRoot}\\bin\\targets\\arduino_blinky\\app\\apps\\blinky\\blinky.elf&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;target&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;:3333&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;cwd&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;${workspaceRoot}&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;gdbpath&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;C:\\Program Files (x86)\\GNU Tools ARM Embedded\\4.9 2015q2\\bin\\arm-none-eabi-gdb.exe&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="nt">&quot;remote&quot;</span><span class="p">:</span><span class="w"> </span><span class="kc">true</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="p">]</span>
<span class="p">}</span>
</pre></div>
</div>
<p>This defines a <code class="docutils literal notranslate"><span class="pre">gdb_arduino_blinky</span></code> debugger configuration. It
specifies:</p>
<ul class="simple">
<li><p>The debugger is type <strong>gdb</strong>.</p></li>
<li><p>To use the <code class="docutils literal notranslate"><span class="pre">blinky.elf</span></code> file for the executable.</p></li>
<li><p>To use port 3333 to connect with the remote target.</p></li>
<li><p>To use arm-none-eabi-gdb for the GDB program.</p></li>
</ul>
</div>
<div class="section" id="debugging-your-application">
<h2><a class="toc-backref" href="#id9">Debugging Your Application</a><a class="headerlink" href="#debugging-your-application" title="Permalink to this headline"></a></h2>
<p>To debug your application, start the GDB server and
launch the GDB session from Visual Studio Code. For the the arduino
blinky example, perform the following:</p>
<p>Step 1: Run the debug_arduino_blinky task to start the GDB server.
Perform the following:</p>
<ol class="arabic simple">
<li><p>Press <code class="docutils literal notranslate"><span class="pre">Ctrl-Shift-P</span></code> and type <code class="docutils literal notranslate"><span class="pre">task</span></code> in the search box.</p></li>
<li><p>Select <strong>Tasks:Run Task</strong> &gt; <strong>debug_arduinoblinky</strong>.</p></li>
<li><p>Press <code class="docutils literal notranslate"><span class="pre">Ctrl-Shift-U</span></code> to open the Output Panel and see the OpenOCD
GDB Server output.</p></li>
</ol>
<div class="figure align-default">
<img alt="../_images/gdb_server_small.png" src="../_images/gdb_server_small.png" />
</div>
<p>Step 2: Start the GDB session. Perform the following:</p>
<ol class="arabic simple">
<li><p>Press <code class="docutils literal notranslate"><span class="pre">Ctrl-Shift-Y</span></code> to view the Debug Console.</p></li>
<li><p>Press the Debugging icon on the activity bar (Ctrl-Shift-D) to bring
up the Debug Side Bar.</p></li>
<li><p>Select <code class="docutils literal notranslate"><span class="pre">gdb_arduino_blinky</span></code> from the DEBUG drop down menu.</p></li>
<li><p>Press the green play button to start the gdb session.</p></li>
</ol>
<div class="figure align-default">
<img alt="../_images/gdb_small.png" src="../_images/gdb_small.png" />
</div>
<p>Step 3: Debug your application. You should see a debug session similar
to the one shown below:</p>
<div class="figure align-default">
<img alt="../_images/gdb_debug_small.png" src="../_images/gdb_debug_small.png" />
</div>
<p>For more information on how to use the Visual Studio Code Debugger, see
the <a class="reference external" href="https://code.visualstudio.com/docs/editor/debugging">Visual Studio Code debugging
documentation</a>.</p>
</div>
<div class="section" id="working-with-multiple-mynewt-applications">
<h2><a class="toc-backref" href="#id10">Working with Multiple Mynewt Applications</a><a class="headerlink" href="#working-with-multiple-mynewt-applications" title="Permalink to this headline"></a></h2>
<p>As mentioned previously, each mynewt project corresponds to a Visual
Studio Code workspace. If you have multiple Mynewt application targets
defined in same project, you will need to define build and debug tasks
for each target in the <code class="docutils literal notranslate"><span class="pre">tasks.json</span></code> file and debugger configurations
for the targets in the <code class="docutils literal notranslate"><span class="pre">launch.json</span></code> file for the workspace. If you
have a different Mynewt project for each mynewt application, you will
need to define build and debug tasks in the <code class="docutils literal notranslate"><span class="pre">tasks.json</span></code> file and the
debugger configuration in the <code class="docutils literal notranslate"><span class="pre">launch.json</span></code> file for each workspace.</p>
</div>
</div>
</div>
</div>
<div class="rst-footer-buttons row" role="navigation" aria-label="footer navigation">
<a href="go_env.html" class="btn btn-neutral" title="Contributing to Newt or Newtmgr Tools" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous: Contributing to Newt or Newtmgr Tools</a>
</div>
</div>
</div>
</div>
<!-- ENDS CONTENT SECTION -->
</div>
<!-- ENDS .content -->
</div>
</div>
<footer>
<div class="container">
<div class="row">
<div class="col-xs-12">
<p class="copyright">Apache Mynewt is available under Apache License, version 2.0.</p>
</div>
<div class="col-xs-12">
<div class="logos">
<img src="../_static/img/asf_logo_wide_small.png" alt="Apache" title="Apache">
<small class="footnote">
Apache Mynewt, Mynewt, Apache, the Apache feather logo, and the Apache Mynewt project logo are either
registered trademarks or trademarks of the Apache Software Foundation in the United States and other countries.
</small>
<a href="">
<img src="../_static/img/add_to_slack.png" alt="Slack Icon" title="Join our Slack Community" />
</a>
</div>
</div>
</div>
</div>
</footer>
</div>
<!-- ENDS #wrapper -->
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../',
VERSION:'latest',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt',
LINK_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/js/bootstrap-3.0.3.min.js"></script>
<script type="text/javascript" src="../_static/js/affix.js"></script>
<script type="text/javascript" src="../_static/js/main.js"></script>
</body>
</html>