Actions

EmSys

Difference between revisions of "Developing Cortex M3 Applications Using Visual Studio Code"

From EdWiki

m (Visual Studio Code)
m (Chocolatey (The Package Manager For Windows))
 
(16 intermediate revisions by the same user not shown)
Line 16: Line 16:
  
 
=== Visual Studio Code ===
 
=== Visual Studio Code ===
We can look at [https://code.visualstudio.com/ VSCode] as an intelligent text editor which provides an extensive framework to add functionality through [https://code.visualstudio.com/docs/editor/extension-marketplace plugins]. [https://code.visualstudio.com/ VSCode] includes a project explorer, which can show the contents of one or multiple folders as a workspace. There is more information on required plugins further down in this list.
+
We can look at [https://code.visualstudio.com/ VSCode] as an intelligent text editor which provides an extensive framework to add functionality through [https://code.visualstudio.com/docs/editor/extension-marketplace plugins]. [https://code.visualstudio.com/ VSCode] includes a project explorer, which can show the contents of one or multiple folders as a workspace. There is more information on required [https://code.visualstudio.com/docs/editor/extension-marketplace plugins] further down in this list.
  
 
=== Required Plugins ===
 
=== Required Plugins ===
Line 32: Line 32:
  
 
* [https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug marus25.cortex-debug]
 
* [https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug marus25.cortex-debug]
 +
* Cortex-Debug [https://raw.githubusercontent.com/wiki/Marus/cortex-debug/Overview.md Overview]
  
 
==== CMake ====
 
==== CMake ====
Line 48: Line 49:
 
{| class="wikitable" style="margin: auto; border-style: solid; border-width: 4px"
 
{| class="wikitable" style="margin: auto; border-style: solid; border-width: 4px"
 
|-
 
|-
! <center>Icon</center> !! <center>Plugin Name</center> !! <center>Required</center> !! <center>Code Name</center>
+
! <center>Icon</center> !! <center>Plugin Name</center> !! <center>Plugin Description</center> !! <center>Required</center> !! <center>Code Name</center>
 
|-
 
|-
| [[image:vscode_plugin_c_cpp.png|80px]] || C/C++ support for Visual Studio Code to enable cross-platform<br />C and C++ development on Windows, Linux, and macOS.|| Required || ms-vscode.cpptools
+
| [[image:vscode_plugin_c_cpp.png|80px]] || C/C++ || C/C++ support for Visual Studio Code to enable cross-platform<br />C and C++ development on Windows, Linux, and macOS.|| Required || ms-vscode.cpptools
 
|-
 
|-
| [[image:vscode_plugin_cortex-debug.png|80px]] || Cortex-Debug is an extension to add debugging capabilities for<br />ARM Cortex-M devices to Visual Studio Code. || Required || marus25.cortex-debug
+
| [[image:vscode_plugin_cortex-debug.png|80px]] || Cortex-Debug || Cortex-Debug is an extension to add debugging capabilities for<br />ARM Cortex-M devices to Visual Studio Code. || Required || marus25.cortex-debug
 
|-
 
|-
| [[image:vscode_plugin_CMake_Syntax_Highlighting.png|80px]] || CMake Language Support for Visual Studio Code || Optional || twxs.cmake
+
| [[image:vscode_plugin_CMake_Syntax_Highlighting.png|80px]] || CMake Syntax Highlighting || CMake Language Support for Visual Studio Code || Optional || twxs.cmake
 
|-
 
|-
| [[image:vscode_plugin_ARM_Assembly_highlighting.png|80px]] || ARM Assembly highlighting || Optional || dan-c-underwood.arm
+
| [[image:vscode_plugin_ARM_Assembly_highlighting.png|80px]] || ARM Assembly highlighting || ARM Assembly highlighting || Optional || dan-c-underwood.arm
 
|-
 
|-
| [[image:vscode_plugin_Linker_Script.png|80px]] || Language support for GNU linker script || Optional || Zixuan Wang
+
| [[image:vscode_plugin_Linker_Script.png|80px]] || GNU linker script || Language support for GNU linker script || Optional || Zixuan Wang
 
|}
 
|}
 
<br />
 
<br />
Line 74: Line 75:
 
[http://openocd.org/ OpenOCD] is an open-source debugger, supporting a wide variety of JTAG hardware interfaces. For customers using a JTAG adapter other than the [https://www.segger.com/products/debug-probes/j-link/ J-Link], this probably is the matching software. The package contains a GDB server, which connects to [https://code.visualstudio.com/ VSCode] on one side, and to the [https://www.segger.com/products/debug-probes/j-link/ J-Link] JTAG/SWD hardware on the other side.
 
[http://openocd.org/ OpenOCD] is an open-source debugger, supporting a wide variety of JTAG hardware interfaces. For customers using a JTAG adapter other than the [https://www.segger.com/products/debug-probes/j-link/ J-Link], this probably is the matching software. The package contains a GDB server, which connects to [https://code.visualstudio.com/ VSCode] on one side, and to the [https://www.segger.com/products/debug-probes/j-link/ J-Link] JTAG/SWD hardware on the other side.
  
 +
* [http://openocd.org/ OpenOCD]
 
* [https://openocd.org/doc-release/html/index.html OpenOCD Documentation]
 
* [https://openocd.org/doc-release/html/index.html OpenOCD Documentation]
* [[EmSys:OpenOCD Ubuntu Package |OpenOCD Ubuntu Package]]
 
* [[EmSys:OpenOCD Config Files |OpenOCD Config Files]]
 
* [[EmSys:OpenOCD Config File Paths |OpenOCD Config File Paths]]
 
* [[EmSys:Running OpenOCD on Linux |Running OpenOCD on Linux]]
 
* [[EmSys:Running OpenOCD on Windows |Running OpenOCD on Windows]]
 
* [[EmSys:Accessing Devices without Sudo |Accessing Devices without sudo]]
 
* [[EmSys:Configuring Windows 7 for OpenOCD |Configuring Windows 7 for OpenOCD]]
 
  
== Chocolatey (Software Management For Windows) ==
+
== Chocolatey (The Package Manager For Windows) ==
 
<big>The Windows versions of required software will be installed using</big> [https://chocolatey.org/ Chocolately]<br />
 
<big>The Windows versions of required software will be installed using</big> [https://chocolatey.org/ Chocolately]<br />
To Setup/Install, Search, and Upgrade Packages, Please follow/refer following documents:
+
 
* [https://docs.chocolatey.org/en-us/choco/setup Install/Setup] Chocolatey on windows 10
+
* Launch Power shell as an administrator, then run the following command:<br /><br />
 +
> Get-ExecutionPolicy<br /><br />
 +
If it returns ''Restricted'', then run the following command:<br /><br />
 +
> Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))<br /><br />
 +
 
 +
 
 +
If you don't see any errors, you are ready to use Chocolatey! Type choco or choco -? now, or see following documents for more info:<br /><br />
 +
 
 +
* [https://chocolatey.org/install Install] Chocolatey on windows 10
 
* [https://docs.chocolatey.org/en-us/create/functions/install-chocolateyinstallpackage Install] package(s)
 
* [https://docs.chocolatey.org/en-us/create/functions/install-chocolateyinstallpackage Install] package(s)
 
* [https://docs.chocolatey.org/en-us/choco/commands/upgrade upgrade] package(s)
 
* [https://docs.chocolatey.org/en-us/choco/commands/upgrade upgrade] package(s)
Line 106: Line 109:
 
=== 5. Installing Visual Studio Code Plugins ===
 
=== 5. Installing Visual Studio Code Plugins ===
  
The easiest way is to install them from the command prompt inside the IDE:
+
The easiest way is to install them from the command prompt inside the IDE:<br /><br />
 
  code --install-extension ms-vscode.cpptools
 
  code --install-extension ms-vscode.cpptools
 
<!-- code --install-extension metalcode-eu  -->
 
<!-- code --install-extension metalcode-eu  -->
Line 158: Line 161:
 
==== Windows ====
 
==== Windows ====
 
  > choco install openocd
 
  > choco install openocd
 +
 +
 +
Please refer following documents to know more about how to run OpenOCD:<br />
 +
 +
* [[EmSys:OpenOCD Ubuntu Package |OpenOCD Ubuntu Package]]
 +
* [[EmSys:OpenOCD Config Files |OpenOCD Config Files]]
 +
* [[EmSys:OpenOCD Config File Paths |OpenOCD Config File Paths]]
 +
* [[EmSys:Running OpenOCD on Linux |Running OpenOCD on Linux]]
 +
* [[EmSys:Running OpenOCD on Windows |Running OpenOCD on Windows]]
 +
* [[EmSys:Accessing Devices without Sudo |Accessing Devices without sudo]]
 +
* [[EmSys:Configuring Windows 7 for OpenOCD |Configuring Windows 7 for OpenOCD]]
  
  
 
==== Sample Project ====
 
==== Sample Project ====
 
<big>You can download sample project from</big> [{{SERVER}}/emsys/vscode/vscode-tm4c-blinky.zip <big>here</big>]
 
<big>You can download sample project from</big> [{{SERVER}}/emsys/vscode/vscode-tm4c-blinky.zip <big>here</big>]

Latest revision as of 03:34, 7 May 2022

Developing Cortex M3/M4 Applications Using Visual Studio Code

Visual Studio Code (VSCode) can be used to edit the source code, build the application and finally debug it.

Required Software Components

In contrast to fully integrated IDEs, setting up Visual Studio Code requires us to setup a number of software packages, which finally work together to build the complete development environment. The software packages can be split into three groups:

  1. VSCode and plugins
  2. ARM Build Tools (compiler etc.)
  3. Debug tools
  • The packages can be installed in any order
  • VSCode must be installed before VSCode plugins can be installed.

1. Visual Studio Code and Plugins

Visual Studio Code

We can look at VSCode as an intelligent text editor which provides an extensive framework to add functionality through plugins. VSCode includes a project explorer, which can show the contents of one or multiple folders as a workspace. There is more information on required plugins further down in this list.

Required Plugins

C/C++

This plugin offers many features to simplify editing of C/C++ code, including Syntax highlighting, Intellisense (finding definitions of symbols), auto-completion of keywords and identifier names, and marking syntax errors while typing. For more details, please refer the following documents:

Cortex-Debug

This plugin adds support for debugging ARM Cortex-M devices executable through a GDB Server.

CMake

CMake Language Support for Visual Studio Code.

ARM

Syntax highlighting for ARM assembly code

Linker Script

Syntax highlighting for linker scripts


Icon
Plugin Name
Plugin Description
Required
Code Name
Vscode plugin c cpp.png C/C++ C/C++ support for Visual Studio Code to enable cross-platform
C and C++ development on Windows, Linux, and macOS.
Required ms-vscode.cpptools
Vscode plugin cortex-debug.png Cortex-Debug Cortex-Debug is an extension to add debugging capabilities for
ARM Cortex-M devices to Visual Studio Code.
Required marus25.cortex-debug
Vscode plugin CMake Syntax Highlighting.png CMake Syntax Highlighting CMake Language Support for Visual Studio Code Optional twxs.cmake
Vscode plugin ARM Assembly highlighting.png ARM Assembly highlighting ARM Assembly highlighting Optional dan-c-underwood.arm
Vscode plugin Linker Script.png GNU linker script Language support for GNU linker script Optional Zixuan Wang


2. ARM Build Tools

GNU ARM Embedded Toolchain

GNU ARM Embedded Toolchain is the C/C++ compiler and linker along with additional tools. It is used to turn your source code into a binary executable.

CMake

CMake is a tool which turns compiler-independent project definitions into compiler-specific project definitions. CMake converts these into makefiles that can be processed by the GNU ARM Embedded Toolchain.

3. Debugger Tools

OpenOCD

OpenOCD is an open-source debugger, supporting a wide variety of JTAG hardware interfaces. For customers using a JTAG adapter other than the J-Link, this probably is the matching software. The package contains a GDB server, which connects to VSCode on one side, and to the J-Link JTAG/SWD hardware on the other side.

Chocolatey (The Package Manager For Windows)

The Windows versions of required software will be installed using Chocolately

  • Launch Power shell as an administrator, then run the following command:

> Get-ExecutionPolicy

If it returns Restricted, then run the following command:

> Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))


If you don't see any errors, you are ready to use Chocolatey! Type choco or choco -? now, or see following documents for more info:


Note: Always run Chocolatey (choco) under Windows Power Shell (as an administrator)

4. Install VSCode

Ubuntu

Windows

> choco install vscode

5. Installing Visual Studio Code Plugins

The easiest way is to install them from the command prompt inside the IDE:

code --install-extension ms-vscode.cpptools
code --install-extension marus25.cortex-debug
code --install-extension twxs.cmake
code --install-extension dan-c-underwood.arm
code --install-extension zixuanwang.linkerscript


Or we can use in the IDE the menu View > Extensions.

  1. Open VSCode
  2. Select View → Extensions
    This will show the Extension sidebar
  3. In the search box above the Extension sidebar, type the Code name from the above table (without the angle brackets) or another reasonable search term
  4. Click on the little green Install button which appears next to the found plugin.


Below is our installed extensions (menu File > Preferences > Extensions):

Vscode armdev plugins.png

6. Install Build Tools

Ubuntu

GNU Arm Embedded Toolchain

  • Please follow this link to install GNU ARM Embedded Toolchain
  • OR, we can install using apt
$ sudo apt update
$ sudo apt install gcc-arm-none-eabi binutils-arm-none-eabi

Make and CMake

$ sudo apt update
$ sudo apt install make cmake

Windows

GNU Arm Embedded Toolchain

> choco install gcc-arm-embedded

Make

> choco install make

CMake

> choco install cmake

7. Install Debugging Tools

OpenOCD

Ubuntu

$ sudo apt update
$ sudo apt install openocd

Windows

> choco install openocd


Please refer following documents to know more about how to run OpenOCD:


Sample Project

You can download sample project from here