blob: adfe039f77224fd6a0cf597b2681b132bb2fc754 [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">
<!-- This is broken by doc revisioning.
-->
<link rel="shortcut icon" href="../../img/favicon.ico">
<title>Using an IDE to Develop Mynewt Applications - Apache Mynewt</title>
<link href="../../css/bootstrap-3.0.3.min.css" rel="stylesheet">
<link rel="stylesheet" href="../../css/highlight.css">
<link href="../../css/base.css" rel="stylesheet">
<link href="../../css/custom.css" rel="stylesheet">
<link href="../../css/v2.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<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="Using an IDE to Develop Mynewt Applications">
<div class="container">
<div class="row v2-main-banner">
<a class="logo-cell" href="/">
<img class="logo" src="/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.12.0, Apache NimBLE 1.7.0 </a> released (April 4, 2024)
</div>
</div>
</div>
</div>
<nav id="navbar" class="navbar navbar-inverse affix-top" data-spy="affix" data-offset-top="150" 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
class=""
>
<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
class=""
>
<a href="/about/">About</a>
</li>
<li
class=""
>
<a href="/talks/">Talks</a>
</li>
<li
class="active"
>
<a href="/documentation/">Documentation</a>
</li>
<li
class=""
>
<a href="/download/">Download</a>
</li>
<li
class=""
>
<a href="/community/">Community</a>
</li>
<li
class=""
>
<a href="/events/">Events</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-3 v2-sidebar sidebar-container"><div id="docSidebar" class="hidden-print" role="complementary">
<div class="top">
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<div class="form-group">
<input type="text" name="q" class="form-control" placeholder="Search documentation" />
</div>
</form>
</div>
</div>
<ul class="toc-nav">
<li class="doc-version"><select class="form-control" onchange="if (this.value) window.location.href=this.value">
<option value="/latest">
Version: master
</option>
<option value="/v1_12_0/" >
Version: 1.12.0
</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/" >
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" selected="selected" >
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></li>
<li ><a href="../../os/introduction/">Mynewt Documentation</a>
</li>
<li><a href="
../../newt/install/prev_releases/
">Appendix</a>
<ul>
<li >
<a href="../../newt/install/prev_releases/">Installing Previous Releases of Newt</a>
</li>
<li >
<a href="../../newtmgr/prev_releases/">Installing Previous Releases of Newtmgr</a>
</li>
<li >
<a href="../go_env/">Setting Up Go to Contribute to Newt and Newtmgr Tools</a>
</li>
<li class="active">
<a href="./">Using an IDE to Develop Mynewt Applications</a>
</li>
<li >
<a href="../how_to_edit_docs/">Edit Docs</a>
</li>
<li >
<a href="../answers/">FAQ</a>
</li>
</ul>
</li>
</ul>
</div></div>
<div class="col-md-9" role="main">
<div class="doc-header">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="/documentation/">Docs</a></li>
<li>&raquo; <a href="newt/install/prev_releases/">Appendix</a></li>
<li>&raquo; Using an IDE to Develop Mynewt Applications</li>
<li class="wy-breadcrumbs-aside">
<a href="https://github.com/apache/mynewt-site/blob/master/docs/faq/ide.md"
class="icon icon-github"> Edit on GitHub</a>
</li>
</ul>
</div>
</div>
<div class="alert alert-warning">
<p>
Version 1.2.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>
<h2 id="developing-mynewt-applications-with-visual-studio-code">Developing Mynewt Applications with Visual Studio Code</h2>
<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>
<li>Install Visual Studio Code. </li>
<li>Install the C/C++ and debugger extensions.</li>
<li>Define task configurations to build Mynewt applications.</li>
<li>Define debugger configurations to debug Mynewt applications. </li>
<li>Launch the debugger. </li>
</ol>
<p>Prerequisites:</p>
<ul>
<li>Have Internet connectivity to fetch remote Mynewt components.</li>
<li>Have a computer to build a Mynewt application.</li>
<li>
<p>Perform <a href="/os/get_started/native_install_intro.md">native installation</a> for the Mynewt tools and toolchains.</p>
<p><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>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. </li>
<li>Complete one of the <a href="/os/tutorials/blinky.md">Blinky Tutorials</a>.</li>
</ul>
<p><strong>Notes:</strong> </p>
<ul>
<li>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 href="https://code.visualstudio.com/docs">documentation and tutorials</a> and evaluate whether you would like to use it to develop Mynewt applications. </li>
<li>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. </li>
<li>You can also use the Eclipse IDE to develop Mynewt applications. See <a href="https://www.codecoup.pl/blog/hacking-mynewt-in-eclipse">https://www.codecoup.pl/blog/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.</li>
</ul>
<h3 id="installing-visual-studio-code">Installing Visual Studio Code</h3>
<p>Download and install Visual Studio Code from <a href="https://code.visualstudio.com/">https://code.visualstudio.com/</a>.</p>
<h3 id="installing-the-cc-and-debugger-extensions">Installing the C/C++ and Debugger Extensions</h3>
<p>You need to install two extensions:</p>
<ol>
<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><br>
To install the C/C++ extension:</p>
<ol>
<li>Press <code>Ctrl-P</code> to open the search box.</li>
<li>Type <code>ext install cpptools</code> in the search box and press Enter. You should see the extension at the top of the list. </li>
<li>Click <code>Install</code> to install the extension.
<br></li>
</ol>
<p>To install the Native Debugger:</p>
<ol>
<li>Press <code>Ctrl-P</code> to open the search box.</li>
<li>Type <code>ext install webfreak.debug</code> in the search box and press Enter. You should see the Native Debug extension at the top of the list.</li>
<li>Click <code>Install</code> to install the extension.
<br></li>
</ol>
<h3 id="defining-tasks-for-mynewt-projects">Defining Tasks for Mynewt Projects</h3>
<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>
<p><br></p>
<h4 id="associating-a-mynewt-project-to-a-workspace">Associating a Mynewt Project to a Workspace</h4>
<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>myproj</code> under the <code>~/dev</code> directory, then you open the <code>~/dev/myproj</code> folder for your workspace. </p>
<p>Select <strong>File</strong> &gt; <strong>Open Folder</strong>, and select the <code>myproj</code> folder from the <code>Select Folder</code> dialog box to open the folder.</p>
<p><br></p>
<h4 id="defining-visual-studio-code-tasks-to-build-and-debug-mynewt-applications">Defining Visual Studio Code Tasks to Build and Debug Mynewt Applications</h4>
<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 href="/os/tutorials/arduino_zero.md">Blinky On Arduino Zero Tutorial</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>Ctrl-Shift-P</code>, type <code>task</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.
<br></p>
<p align="center"><img src="/faq/pics/task_runner_small.png"></p>
<p><br>
Tasks are defined in the <code>tasks.json</code> file. You should see the <code>.vscode</code> folder created in the <code>MYPROJ</code> folder and a <code>tasks.json</code> file created in the <code>.vscode</code> folder. The <code>tasks.json</code> file has the following default values. </p>
<p><br></p>
<p align="center"><img src="/faq/pics/task_json_small.png"></p>
<p><br></p>
<p>The sample <code>tasks.json</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>tasks.json</code> file, add the following definitions, and press <code>Ctrl-S</code> to save the file.</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code>{
&quot;version&quot;: &quot;0.1.0&quot;,
&quot;command&quot;: &quot;newt&quot;,
&quot;echoCommand&quot;: true,
&quot;isShellCommand&quot;: true,
&quot;tasks&quot;:[
{
&quot;taskName&quot;: &quot;build_arduino_boot&quot;,
&quot;args&quot;: [&quot;build&quot;, &quot;arduino_boot&quot;],
&quot;suppressTaskName&quot;: true
},
{
&quot;taskName&quot;: &quot;build_arduino_blinky&quot;,
&quot;args&quot;: [&quot;build&quot;, &quot;arduino_blinky&quot;],
&quot;isBuildCommand&quot;: true,
&quot;suppressTaskName&quot;: true
},
{
&quot;taskName&quot;: &quot;create_arduino_blinky&quot;,
&quot;args&quot;: [&quot;create-image&quot;, &quot;arduino_blinky&quot;, &quot;1.0.0&quot;],
&quot;suppressTaskName&quot;:true
},
{
&quot;taskName&quot;: &quot;debug_arduino_blinky&quot;,
&quot;args&quot;: [&quot;debug&quot;, &quot;arduino_blinky&quot;, &quot;-n&quot;],
&quot;suppressTaskName&quot;: true
}
]
}
</code></pre></div>
<p><br>
The <code>tasks.json</code> file specifies the tasks that are run to build and debug the Arduino blinky targets. Each task runs a <code>newt</code> command. The <code>newt</code> command to run and the arguments for the <code>newt</code> command are passed in the <code>args</code> property for each task. </p>
<p>The following tasks are defined in this example:</p>
<ol>
<li><strong>build_arduino_boot</strong>: Runs the <code>newt build arduino_boot</code> command to build the arduino_boot target.</li>
<li>
<p><strong>build_arduino_blinky</strong>: Runs the <code>newt build arduino_blinky</code> command to build the arduino_blinky target. </p>
<p><strong>Note:</strong> This task sets the <code>isBuildCommand</code> property to <code>true</code>. This is an optional property that, when set to true, allows you to run the <strong>Tasks: Run Build Task</strong>(<code>Ctrl-Shift-B</code>) command to start the task.</p>
</li>
<li>
<p><strong>create_arduino_blinky</strong>: Runs the <code>newt create-image arduino_blinky</code> command to create the image file.</p>
</li>
<li><strong>debug_arduino_blinky</strong>: Runs the <code>newt debug arduino_blinky -n</code> command to debug the arduino_blinky target. The <code>-n</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.</li>
</ol>
<p>For more information on tasks and all supported properties, see the <a href="https://code.visualstudio.com/docs/editor/tasks">Visual Studio Code Task documentation</a>.</p>
<p><br></p>
<h4 id="running-a-task">Running a Task</h4>
<p>To run a task, press <code>Ctrl-Shift-P</code>, type <code>task</code> on the search box, and select <strong>Tasks: Run Task</strong>. The tasks that you define in the <code>tasks.json</code> file are listed. Select the task to run. </p>
<p>The following is an example of running the <code>build_arduino_boot</code> task:
<br></p>
<p align="center"><img src="/faq/pics/task_select_small.png"></p>
<p><br>
<br></p>
<p align="center"><img src="/faq/pics/task_start_small.png"></p>
<p><br></p>
<p><strong>Note</strong>:To run the <code>build_arduino_blinky</code> task, you can use the keyboard shortcut <code>Ctrl-Shift-B</code> because the task has the property <code>isBuildCommand</code> set to true. </p>
<p><br></p>
<h4 id="defining-tasks-for-other-newt-commands">Defining Tasks for Other Newt Commands</h4>
<p>Other newt commands, such as the <code>newt load</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>newt load arduino_boot</code> and <code>newt load arduino_blinky</code> commands, add the following definitions to the <code>tasks.json</code> file:</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code> {
&quot;taskName&quot;: &quot;load_arduino_boot&quot;,
&quot;args&quot;: [&quot;load&quot;, &quot;arduino_boot&quot;],
&quot;suppressTaskName&quot;:true
},
{
&quot;taskName&quot;: &quot;load_arduino_blinky&quot;,
&quot;args&quot;: [&quot;load&quot;, &quot;arduino_blinky&quot;],
&quot;suppressTaskName&quot;:true
},
</code></pre></div>
<p><br>
To run a command from the Visual Studio integrated terminal, instead of starting a task, press <code>Ctrl-`</code> to launch the integrated terminal and enter the command on the prompt:
<br></p>
<p align="center"><img src="/faq/pics/integrated_terminal_small.png"></p>
<p><br></p>
<h3 id="defining-debugger-configurations">Defining Debugger Configurations</h3>
<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>
<p><br></p>
<p align="center"><img src="/faq/pics/debug_new_config_small.png"></p>
<p><br></p>
<p>You should see a default <code>launch.json</code> file created in the <code>.vscode</code> folder.
<br></p>
<p align="center"><img src="/faq/pics/launch_small.png"></p>
<p><br></p>
<p><br>
Step 2: Delete the content from the <code>launch.json</code> file, add the following definitions, and press 'Ctrl-S' to save the file.</p>
<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%;"><span></span><code>{
&quot;version&quot;: &quot;0.2.0&quot;,
&quot;configurations&quot;: [
{
&quot;name&quot;: &quot;gdb_arduino_blinky&quot;,
&quot;type&quot;: &quot;gdb&quot;,
&quot;request&quot;: &quot;attach&quot;,
&quot;executable&quot;: &quot;${workspaceRoot}\\bin\\targets\\arduino_blinky\\app\\apps\\blinky\\blinky.elf&quot;,
&quot;target&quot;: &quot;:3333&quot;,
&quot;cwd&quot;: &quot;${workspaceRoot}&quot;,
&quot;gdbpath&quot;: &quot;C:\\Program Files (x86)\\GNU Tools ARM Embedded\\4.9 2015q2\\bin\\arm-none-eabi-gdb.exe&quot;,
&quot;remote&quot;: true
}
]
}
</code></pre></div>
<p><br>
This defines a <code>gdb_arduino_blinky</code> debugger configuration. It specifies: </p>
<ul>
<li>The debugger is type <strong>gdb</strong>.</li>
<li>To use the <code>blinky.elf</code> file for the executable. </li>
<li>To use port 3333 to connect with the remote target.</li>
<li>To use arm-none-eabi-gdb for the GDB program.
<br></li>
</ul>
<h3 id="debugging-your-application">Debugging Your Application</h3>
<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>
<li>Press <code>Ctrl-Shift-P</code> and type <code>task</code> in the search box. </li>
<li>Select <strong>Tasks:Run Task</strong> &gt; <strong>debug_arduino_blinky</strong>.</li>
<li>Press <code>Ctrl-Shift-U</code> to open the Output Panel and see the OpenOCD GDB Server output.
<br> </li>
</ol>
<p align="center"><img src="/faq/pics/gdb_server_small.png"></p>
<p><br></p>
<p>Step 2: Start the GDB session. Perform the following: </p>
<ol>
<li>Press <code>Ctrl-Shift-Y</code> to view the Debug Console. </li>
<li>Press the Debugging icon on the activity bar (Ctrl-Shift-D) to bring up the Debug Side Bar.</li>
<li>Select <code>gdb_arduino_blinky</code> from the DEBUG drop down menu. </li>
<li>Press the green play button to start the gdb session.</li>
</ol>
<p align="center"><img src="/faq/pics/gdb_small.png"></p>
<p><br>
Step 3: Debug your application. You should see a debug session similar to the one shown below:</p>
<p align="center"><img src="/faq/pics/gdb_debug_small.png"></p>
<p><br>
For more information on how to use the Visual Studio Code Debugger, see the <a href="https://code.visualstudio.com/docs/editor/debugging">Visual Studio Code debugging documentation</a>.</p>
<h3 id="working-with-multiple-mynewt-applications">Working with Multiple Mynewt Applications</h3>
<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>tasks.json</code> file and debugger configurations for the targets in the <code>launch.json</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>tasks.json</code> file and the debugger configuration in the <code>launch.json</code> file for each workspace. </p>
<div class="row">
<ul class="nav nav-pills" style="margin-bottom: 10px">
<li>
</li>
<li class="pull-right">
</li>
</ul>
</div>
<footer 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">
<a href="https://www.apache.org/">
<img src="/img/asf_logo_wide_small.png" alt="Apache" title="Apache">
</a>
<p>
Copyright © 2015-2021 The Apache Software Foundation.<br>
<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>
</p>
<a href="">
<img src="https://www.countit.com/images/add_to_slack.png" alt="Slack Icon" title="Join our Slack Community" />
</a>
</div>
</div>
<a href="https://www.apache.org/licenses/">
<button class="button-footer-asf">
License
</button>
</a>
<a href="https://www.apache.org/foundation/sponsorship.html">
<button class="button-footer-asf">
Sponsorship
</button>
</a>
<a href="https://www.apache.org/foundation/thanks.html">
<button class="button-footer-asf">
Thanks
</button>
</a>
<a href="https://www.apache.org/security/">
<button class="button-footer-asf">
Security
</button>
</a>
<a href="https://apache.org/events/current-event">
<button class="button-footer-asf">
ASF Events
</button>
</a>
</footer>
</div>
</div>
</div>
<script src="../../js/jquery-1.10.2.min.js"></script>
<script src="../../js/bootstrap-3.0.3.min.js"></script>
<script src="../../js/highlight.pack.js"></script>
<script src="../../js/base.js"></script>
<script src="../../js/custom.js"></script>
<script src="search/main.js"></script>
</body>
</html>