Developer World Spresense
English 日本語
目录

1. Introduction

This chapter explains the installation and setup procedures for developing Spresense SDK applications on Visual Studio Code (hereafter called as VS Code) provided by Microsoft.

Spresense VSCode IDE is an extension of VS Code specializing in Spresense SDK application development. This extension adds the following functions to support development with a unified interface from project creation to ICE debugging.

vscode overview en
  • Automatic creation of settings for building and debugging applications

  • Create application templates, including multi-core applications

  • Configuring builds with the GUI

  • Serial terminal to check Spresense operation

Using the above functions, here is an example of adding a simple sample application myapps to a project called myproject, and explains how to run the application by Spresense.

vscode sample overview en

2. Setup the Spresense VSCode IDE

Install the Spresense SDK application development environment using the following procedure. As a result, a series of development environment from project creation to debugging is prepared on VS Code.

If you already have a GUI development environment that is setup by default to Spresense SDK 入门指南(CLI版), you do not need to execute the Development environment section steps.

2.1. Development environment

You can develop Spresense SDK on Linux/Windows/macOS. Please setup development environment for your appropriate OS.

Supported Operation System

  • Linux (64bit)

    • Ubuntu 16.04 or later

  • Windows (64bit)

    • 10 (with MSYS2 console)

    • 11 (with WSL2 console)

  • macOS

    • High Sierra (10.13) or later

Does not support 32bit version OS

2.1.1. Setup for Linux

  1. Serial Configuration

    Add user to dialout group

    sudo usermod -a -G dialout <user-name>
    

    Please logout and login after running the above command.

  2. Install development tools

    wget https://raw.githubusercontent.com/sonydevworld/spresense/master/install-tools.sh
    bash install-tools.sh
    

    If you run wget command and install-tools.sh via proxy server, set your proxy server as below.

    export http_proxy=http://<your proxy server>:<port number>
    export https_proxy=http://<your proxy server>:<port number>
    

    The version of the GNU Arm Embedded Toolchain (compiler) is updated in the SDKv2.3 and SDKv3.0 releases.

    SDK version GNU Arm Toolchain version

    SDKv3.0 or later

    gcc-arm-none-eabi-10.3-2021.10

    SDKv2.3 or later

    gcc-arm-none-eabi-9-2019-q4-major

    SDK v2.2 or earlier

    gcc-arm-none-eabi-7-2018-q2-update

    If you want to reinstall including the new compiler, get the latest version of install-tools.sh and run install-tools.sh with the -r option.

    bash install-tools.sh -r
    

    If you want to check the compiler version you have already installed, run arm-none-eabi-gcc -v after source ~/spresenseenv/setup. The version information will be displayed on the last line.

    arm-none-eabi-gcc -v
    (snip)
    gcc version 10.3.1 20210824 (release) (GNU Arm Embedded Toolchain 10.3-2021.10)
    

    And run this command to activate installed tools.

    source ~/spresenseenv/setup
    

    This command must run in every terminal window. If you want to skip this step, please add this command in your ${HOME}/.bashrc.

    The tool chain is installed in spresenseenv/usr/bin under the home directory.
  3. Clone the Spresense SDK with submodule

    git clone --recursive https://github.com/sonydevworld/spresense.git
    
    If you want to update a spresense.git repository that is already downloaded by git clone , please refer to How to get specified Spresense SDK version .

2.1.2. Setup for Windows 10 (for MSYS2)

  1. Install MSYS2

  2. Install development tools

    Run MSYS2 MSYS from start menu, and run following commands.

    MSYS2 MinGW 64-bit and MSYS2 MinGW 32-bit is not supported. Please use MSYS2 MSYS.
    curl -L https://raw.githubusercontent.com/sonydevworld/spresense/master/install-tools.sh > install-tools.sh
    bash install-tools.sh
    

    If you run curl command and install-tools.sh via proxy server, set your proxy server as below.

    export http_proxy=http://<your proxy server>:<port number>
    export https_proxy=http://<your proxy server>:<port number>
    

    The version of the GNU Arm Embedded Toolchain (compiler) is updated in the SDKv2.3 and SDKv3.0 releases.

    SDK version GNU Arm Toolchain version

    SDKv3.0 or later

    gcc-arm-none-eabi-10.3-2021.10

    SDKv2.3 or later

    gcc-arm-none-eabi-9-2019-q4-major

    SDK v2.2 or earlier

    gcc-arm-none-eabi-7-2018-q2-update

    If you want to reinstall including the new compiler, get the latest version of install-tools.sh and run install-tools.sh with the -r option.

    bash install-tools.sh -r
    

    If you want to check the compiler version you have already installed, run arm-none-eabi-gcc -v after source ~/spresenseenv/setup. The version information will be displayed on the last line.

    arm-none-eabi-gcc -v
    (snip)
    gcc version 10.3.1 20210824 (release) (GNU Arm Embedded Toolchain 10.3-2021.10)
    

    And run this command to activate installed tools.

    source ~/spresenseenv/setup
    

    This command must run in every terminal window. If you want to skip this step, please add this command in your ${HOME}/.bashrc.

    The tool chain is installed in /opt/spresenseenv/usr/bin.
  3. Clone the Spresense SDK with submodule

    git clone --recursive https://github.com/sonydevworld/spresense.git
    
    If you want to update a spresense.git repository that is already downloaded by git clone , please refer to How to get specified Spresense SDK version .
  4. Install USB serial driver

    User must install before connecting Spresense board to the PC.

    Please download and install from below.

2.1.3. Setup for Windows 11 (for WSL2)

  1. Install WSL2

    Install WSL2 according to the following procedure

    1. Open PowerShell console

    2. Run wsl command to install WSL2.

      wsl --install
      

      The following command can be used to specify the version of Ubuntu to be installed as WSL2. (The following command is an example of installing Ubuntu 20.04.)

      wsl --install -d Ubuntu-20.04
      
    3. Open the WSL2 console.

      tools wsl2 ubuntu en
    4. When starting up for the first time, you will be asked to create an account as shown below, and enter a user name and password.

      tools wsl2 create account
    5. Once the account is created and the console opens as shown below, WSL2 setup is complete.

      tools wsl2 shell en
  2. Install development tools

    Open the WSL2 console from start menu, and run following commands.

    curl -L https://raw.githubusercontent.com/sonydevworld/spresense/master/install-tools.sh > install-tools.sh
    bash install-tools.sh
    

    If you run curl command and install-tools.sh via proxy server, set your proxy server as below.

    export http_proxy=http://<your proxy server>:<port number>
    export https_proxy=http://<your proxy server>:<port number>
    

    The version of the GNU Arm Embedded Toolchain (compiler) is updated in the SDKv2.3 and SDKv3.0 releases.

    SDK version GNU Arm Toolchain version

    SDKv3.0 or later

    gcc-arm-none-eabi-10.3-2021.10

    SDKv2.3 or later

    gcc-arm-none-eabi-9-2019-q4-major

    SDK v2.2 or earlier

    gcc-arm-none-eabi-7-2018-q2-update

    If you want to reinstall including the new compiler, get the latest version of install-tools.sh and run install-tools.sh with the -r option.

    bash install-tools.sh -r
    

    If you want to check the compiler version you have already installed, run arm-none-eabi-gcc -v after source ~/spresenseenv/setup. The version information will be displayed on the last line.

    arm-none-eabi-gcc -v
    (snip)
    gcc version 10.3.1 20210824 (release) (GNU Arm Embedded Toolchain 10.3-2021.10)
    

    And run this command to activate installed tools.

    source ~/spresenseenv/setup
    

    This command must run in every terminal window. If you want to skip this step, please add this command in your ${HOME}/.bashrc.

    The tool chain is installed in /opt/spresenseenv/usr/bin.
  3. Clone the Spresense SDK with submodule

    git clone --recursive https://github.com/sonydevworld/spresense.git
    
    If you want to update a spresense.git repository that is already downloaded by git clone, please refer to How to get specified Spresense SDK version .
  4. Install USB serial driver

    User must install before connecting Spresense board to the PC.

    Please download and install from below.

2.1.4. Setup for macOS

  1. Install development tools provided by Apple

    Open the Teminal and run following command.

    xcode-select --install
    
  2. Install Python3

  3. Install wget (Necessary to build some of NuttX application tools)

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
    brew install wget
    
  4. Install flock (Necessary to build for SDKv3.2.0 or later)

    brew tap discoteq/discoteq
    brew install flock
    
  5. Install development tools

    curl -L https://raw.githubusercontent.com/sonydevworld/spresense/master/install-tools.sh > install-tools.sh
    bash install-tools.sh
    

    If you run curl command and install-tools.sh via proxy server, set your proxy server as below.

    export http_proxy=http://<your proxy server>:<port number>
    export https_proxy=http://<your proxy server>:<port number>
    

    The version of the GNU Arm Embedded Toolchain (compiler) is updated in the SDKv2.3 and SDKv3.0 releases.

    SDK version GNU Arm Toolchain version

    SDKv3.0 or later

    gcc-arm-none-eabi-10.3-2021.10

    SDKv2.3 or later

    gcc-arm-none-eabi-9-2019-q4-major

    SDK v2.2 or earlier

    gcc-arm-none-eabi-7-2018-q2-update

    If you want to reinstall including the new compiler, get the latest version of install-tools.sh and run install-tools.sh with the -r option.

    bash install-tools.sh -r
    

    If you want to check the compiler version you have already installed, run arm-none-eabi-gcc -v after source ~/spresenseenv/setup. The version information will be displayed on the last line.

    arm-none-eabi-gcc -v
    (snip)
    gcc version 10.3.1 20210824 (release) (GNU Arm Embedded Toolchain 10.3-2021.10)
    

    And run this command to activate installed tools.

    source ~/spresenseenv/setup
    

    This command must run in every terminal window. If you want to skip this step, please add this command in your ${HOME}/.bash_profile.

    The tool chain is installed in spresenseenv/usr/bin under the home directory.
  6. Clone the Spresense SDK with submodule

    git clone --recursive https://github.com/sonydevworld/spresense.git
    
    If you want to update a spresense.git repository that is already downloaded by git clone , please refer to How to get specified Spresense SDK version .
  7. Install USB serial driver

    User must install before connecting Spresense board to the PC.

    Please download and install from below.

    On High Sierra (10.13) and later, the installation of the driver may be blocked. Please allow this driver from System Preferences Security & Privacy pane. See Apple Technical Note TN2459 "User-Approved Kernel Extension Loading" for more information.

2.2. Installation of VSCode

  1. Download the VSCode installer from the following site.

  2. Run the downloaded installer

    • For Windows

      1. Start the installer (VSCodeUserSetup.exe).

      2. Proceed with installation according to the dialog.

    • For macOS

      1. Unzip the installation file (VSCode-darwin-stable.zip).

      2. Move the unzipped Visual Studio Code to the application.

    • For Ubuntu

      1. Install from the downloaded file (code_1.37.1-xxx.deb) with the following command.

        $ sudo dpkg -i code_1.37.1-xxx.deb
  3. Launch the installed VS Code

    vscode vscode installed en

2.3. Installing the Spresense extension

If you have installed the Spresense Extension α version , please uninstall it. If you do not uninstall, the Spresense extension will not work properly.
  1. Search Spresense on the extension screen.

  2. Spresense VSCode IDE will appear in the list and click on it.

  3. Click Install button on the details displayed on the right side of the window.

    vscode spresense install en
  4. The installation is complete when the message Installation is complete appears as shown in the screen below.

    vscode spresense installed en
    The Spresense VSCode IDE will automatically install these extensions for use with C/C++ for Visual Studio Code and Cortex Debug.

2.3.1. Installing the Spresense extension on Remote-WSL2 (Windows 11 only)

In order to develop on WSL2 on Windows 11, it is necessary to open a remote window of VSCode and install the Spresense extension again. Follow the steps below to install the Spresense VSCode IDE on the remote window.

  1. Click the following icon in the lower left corner of the VSCode screen.

    Remote-WSL Icon
  2. Select the New WSL Window using Distro…​

  3. Select the distribution of WSL2 you have installed.

    Remote-WSL Choose Distribution
  4. Confirm that a remote window has opened with the lower left corner of the screen as shown below.

    Remote-WSL Open status
  5. Search for Spresense in the Extensions screen.

  6. Spresense VSCode IDE will appear in the list and click on it.

  7. Click Install button on the details displayed on the right side of the window.

    Remote-WSL Install SpresenseIDE

2.3.2. Setting MSYS2 Installation Path (Windows 10 only)

In this section, we will set the MSYS2 on VS Code.

  1. Press F1 to display the command palette.

  2. Input spresense msys to filtering commands, and select MSYS2 path(Windows only): Location for Msys install path.

    vscode msys2 search en
  3. When the folder selection screen appears, select the MSYS2 path and click Open.

    vscode msys2 folder en
  4. This completes the environment for developing Spresense applications on VS Code.

3. Creating an application project

This chapter explains the procedure for creating the application project myproject in the VS Code workspace.

3.1. Creating a workspace

To start developing your application, create a workspace for Spresense by adding an Spresense SDK folder and a project folder in the workspace. When creating a project, you can create an empty folder and add it to this workspace to create a project.

Here, create a workspace with the following configuration using the "Workspace Setup Wizard".

Setting items Setting details

Spresense SDK folder

C:\msys64\home\user\spresense

Project folder

C:\msys64\home\user\myproject

Workspace file

C:\msys64\home\user\myproject.code-workspace

vscode wizard create workspace overview en
  1. Press F1`key to open command palette and choose `Spresense: Workspace setup wizard .

    To create a new workspace, the workspace (folder) on the window must be closed.
  2. Select the Spresense SDK folder that use for project into Spresense SDK path form.

  3. Select the newly created project folder into Project folder path form.

  4. Click Create to complete the wizard.

  5. "Do you trust the authors of the files in this folder?" dialog box will appear, select Yes.

    vscode setup workspace trust en
    If you do not select Yes in this dialog, the functions of Spresense VSCode IDE, such as building and displaying the serial terminal, will not work properly. If you select No, please refer to Terminal does not open correctly (Windows) and set up to trust the authors of the file.
  6. If Spresense setup: Setup complete. is displayed, setup is complete.

    vscode setup workspace complete en
  7. Select Save Workspace As…​ from File to save a created workspace.

    vscode menu save workspace en
    You can reopen the newly created workspace by opening the saved workspace file from “File”→ “Open Workspace …​”.
  8. If the workspace is completed as shown below, it is complete.

    vscode workspace complete en
You can also create a workspace by adding folders to the workspace in the order of the Spresense SDK, project folder without using the above workspace setup wizard.
To add multiple project folders to the workspace, right-click on the source tree and execute Add folder to workspace…​.

3.2. About files included in the project folder

The project folder contains the following 4 types of files.

  1. Project configuration file

    Files saved in .vscode directly under the project folder. Basically, the files inside are automatically generated, so there is no need to create a new one.

  2. Application commands (created in the following chapters)

    Contains programs to be executed with commands available on the NuttShell console. By implementing the program in this, you can create original commands. For example, the command myapps can be executed with NuttShell for the following.

    NuttShell (NSH) NuttX-8.2
    nsh> myapps
    <<Output result>>
  3. ASMP worker program (created in the following chapter)

    A program that uses the multi-core feature of Spresense . By creating this program and using it from the above application commands, you can add multi-core applications.

  4. Makefile (LibTarget.mk, Make.defs, Makefile) (created in the following chapter)

    This file is required to build the entire project. If this file is changed, it may not build correctly.

3.3. About the Project Menu

Once the workspace is created and the application project is ready to be created, the following Spresense project menu will be available.

image::vscode_project_menu_en.png[width="40%"].

3.3.1. Spresense project menu list

  • Spresense: Add to project folder…​

    Used to add application commands or ASMP workers to the project. See Adding application commands for more information.

  • Spresense: SDK Config

    Used to customize the build configuration of the project. See Build configuration for details.

  • Spresense: Application Build

    Used to build the application you have created. See Build the Project for details.

  • Spresense: Application clean

    Used to delete files created when building an application. Select this menu item to clear the build environment.

  • Spresense: Build and Flash

    Used to build an application and flash it to Spresense. For more information, please refer to Flashing the application into Spresense board and Check operation.

3.3.2. How to open the project menu

The project menu can be opened by right-clicking on the workspace explorer. You can also run the menu by folder, depending on where you right-click.

As shown in the figure below, there is a Spresense SDK folder part and a project folder part, so right-click on the folder of the menu you want to open.

(If you want to open the SDK config in the project folder, right-click inside the red dashed line in the figure below and select SDK Config.)

image::vscode_project_menu_folder_en.png[width="40%"].

4. Create and run application "myapps"

The environment for developing applications in the previous chapters is in place. Here, the procedure to actually create the application "myapps" on VS Code is explained in the following flow. "myapps" is a simple application that only displays "Hello Spresense !!!"

4.1. Adding application commands

This section describes the procedure for adding the application command myapps that only displays Hello Spresense!!!.

Setting items Setting details

Target project folder

C:\msys64\home\user\myproject

Application command name

myapps

vscode new item creation en
  1. Right click on the project folder created in the previous chapter (myproject) and select Spresense: Add to project folder…​.

  2. In the opened Add to Project Folder dialog, select the project folder to which you want to add application commands and click Next.

  3. Select Application Command from the item type and click Next.

  4. Enter the name of the application command you want to add to Application command name. (In this example, it is myapps.)

    vscode wizard item application created en

4.1.1. About added files

File(Folder) Detail

myapps

This folder contains the command program and the Makefile for building application command.

myapps_main.c

The main source file for the command. Simply edit this file after creating a new application.

Make.defs

Makefile for building commands.

Makefile

Makefile for customizing commands. You can describe new added files and flags used for building.

4.2. Application implementation

In this chapter, we will implement the application command program to display Hello Spresense !!!.

4.2.1. Edit the main source code

The main source code (myapps_main.c in this example) is created when an application command is added and displayed in the editor. Edit the main source code as follows:

myapps_main.c
#include <sdk/config.h>
#include <stdio.h>

int myapps_main(int argc, char *argv[])
{
  printf("Hello Spresense!!!\n"); (1)
  return 0;
}
1 Implement the process you want to add.
vscode edit main code file en

4.3. Build configuration

In the previous chapter, you added an application to the project folder and implemented the program. In order to build these programs properly, it is necessary to configure the build according to the function.

This section describes the configuration and steps required to build myapps.

There are no special features other than running Spresense this time, so the following will configure the kernel and SDK.

In SDK v1.5 or earlier, it is necessary to perform kernel config separately from SDK config. Please refer to How to build SDK with SDK v1.5 or earlier for kernel configuration and build methods.
For details of the configuration tool, refer to About Build configuration.
Configuration Detail

SDK

Save default configuration(No selecting presets.)

4.3.1. SDK configuration

Create a new configuration without selecting a preset.

vscode sdk config en
  1. Right click on the project folder and select Spresense: SDK Config from the project menu.

    If another 'Kernel config' or 'SDK config' is already open, please close it beforehand. Only one config window can be open at a time.
  2. Click New to open the SDK preset list.

  3. Click OK.

  4. Click Save to save.

  5. If Configuration has been saved. is displayed, SDK configuration is complete.

    It may take some time to save depending on the environment. Please wait for a completion message.

4.4. Build the project

Up to the previous section, you have created a project, added a program, and configured it.

This section explains how to build the created program into a binary(.spk file) that can be flash into Spresense.

Build application with the NuttX kernel of Spresense SDK. Since various functions are included, it takes considerable time. (Depending on your environment, it may take over ten minutes.)

In SDK v1.5 or earlier, it is necessary to perform kernel build separately from application build. Please refer to How to build SDK with SDK v1.5 or earlier for kernel configuration and build methods.

4.4.1. Building the application

vscode build application en
  1. Right click on the project folder you want to build and select Spresense: Application build from the project menu.

  2. The application build will start, so wait for it to complete.

  3. If Terminal will be reused by tasks, press any key to close it. is displayed, the Application build is complete.

4.4.1.1. About build output files
File(Folder) Detail

out

The folder where the build output files are copied.

myproject.nuttx.spk

This file is written to SPI-Flash on the Spresense board.

myproject.nuttx

An ELF file containing debugging information. Load this file into Spresense for ICE debugging.

4.5. Flashing the application into Spresense board and Check operation

In the previous sections, we explained everything from creating a project to creating a binary that is flashing into Spresense.

This section describes the procedure from flashing the actually created binary to Spresense to checking the operation.

4.6. Setting the serial port

  1. Connect the PC and Spresense via USB.

  2. Press F1 key to display the command palette.

    vscode serial port menu open en
  3. Input spresense serial port to narrow down the command.

  4. Choose Spresense: Serial port selection.

    vscode serial port menu select en
  5. Choose serial port for Spresense from list.

    vscode serial port select en

4.6.1. Flashing build binaries

If you are using Spresense SDK for the first time or updating the version, you need to update the boot loader. Please refer to here to update the boot loader.
vscode flash application en
  1. Right click on the project folder you want to flash the built binary and select Spresense: Build and Flash from the project menu.

  2. The application build will start and wait for completion.

    You can also skip the previous section’s command Spresense: Application build by using this command.
  3. As soon as the build is over, flashing to Spresense will start.

  4. After flashing to Spresense, the serial terminal will open.

4.6.2. Operation check

Enter the myapps command created on the open serial terminal and type the Enter key." Hello Spresense!!!" will displayed.

vscode execute application command en
  1. Type myapps on the opened serial terminal and press the enter key.

  2. The execution result of the created command is displayed.

5. Limitations

5.1. Cannot build a application that is created with SDK v1.5 or earlier by using SDK v2.0 or later

Since Spresense SDK v2.0, the build system is integrated with the kernel, so the configurations are not compatible with SDK v1.5 or earlier.

When building with SDK Version 2.0 or later, delete .vscode in the project folder first and reconfigure the SDK. (We recommend that you make a backup of the entire project.)

5.2. Spresense VSCode IDE may not be used depending on the folder name/path used

Spresense VSCode IDE has the following restrictions depending on the type of characters used in the path of the folder used due to the specifications of some build systems.

  • Restrictions common to all operating systems

    • Case of the folder path contains a space(Example: C:\Users\Sony Taro\project)

      All functions do not work.

If you are using on these conditions, we recommend to create new account for using Spresense VSCode IDE.

6. Troubleshooting

This section explains the problems that may occur when using VS Code and how to deal with them by category. See here if the VS Code does not work well.

6.1. Setup

6.1.1. Terminal does not open correctly (Windows)

In Windows environment, VS Code uses MSYS2 bash as a terminal. If this bash does not open and PowerShell or cmd (command prompt) opens as shown in the following figure, the trust of the workspace may not be reflected correctly. In that case, try the following steps:

  • Setup the trust setting of the workspace

    vscode setup trust en
    1. Press F1 to open the command palette and choose Workspace: Manage Workspace Trust.

    2. In the In a trusted workspace section, select Trusted.

6.2. `Git not found' warning message appears after workspace creation

If you are using the MSYS2 environment on Windows, you may receive the following message after creating a workspace.

image::vscode_setup_git_not_found_en.png[width="100%"].

This is a message from VSCode’s Git extension indicating that Git is not installed. If you want to operate a Git repository on VSCode, please follow the message displayed on VSCode to install Git.

6.3. Build a project

6.3.1. Build does not progress

If the build does not proceed, the load on your PC may have increased, or there may be a problem with the terminal settings. Check the terminal status by following the steps below.

  1. Select TerminalNew Terminal from window menu.

  2. Run the`echo ${SHELL}` command on the terminal opened in the previous step.

  3. If the result is not /bin/bash or /usr/bin/bash, perform the Terminal does not open correctly (Windows).

6.3.2. Build fail

6.3.2.1. "application.mk: No such file or directory" shows in build logs

If the build fails with a message like the one shown below, your project configuration file does not match the installed Spresense VSCode IDE version. In this case, execute Spresense: Update project folder settings from the command palette to update the project setting file.

Makefile:30: /home/user/myproject/.vscode/application.mk: No such file or directory
make[2]: *** No rule to make target '/home/user/myproject/.vscode/application.mk'.  Stop.

or

Makefile:12: /home/user/myproject/.vscode/worker.mk: No such file or directory
make: *** No rule to make target '/home/user/myproject/.vscode/worker.mk'.  Stop.

6.4. About VSCode problems

If the VSCode is updated, problems other than those listed above may occur. (e.g. 2 times texts pasted in 1 time) If you happened such problems with VSCode, please see the VSCode issue page below. It may be fixed in a future release.

7. Appendix

7.1. How to build SDK with SDK v1.5 or earlier

Kernel configuration and build are required for building systems for SDK v1.5 and earlier before an application configuration and build.

This section describes how to configure and build the kernel required to develop using SDK v1.5 or earlier.

7.1.1. Kernel configuration

This is the procedure to configure using the preset release.

vscode kernel config en
  1. Right click on the project folder and select Spresense: Kernel Config from the project menu.

    If another 'Kernel config' or 'SDK config' is already open, please close it beforehand. Only one config window can be open at a time.
  2. Open the New menu and display the list of kernel presets.

  3. Select release from the preset and click OK.

  4. Click Save to save.

  5. If Configuration has been saved. is displayed, kernel configuration is complete.

    It may take some time to save depending on the environment. Please wait for a completion message.
  6. Close the configuration.

7.1.2. Build the kernel

vscode build kernel en
  1. Right click on the project folder you want to build and select Spresense: Kernel build from the project menu.

  2. Wait until the kernel build is complete.

  3. If Terminal will be reused by tasks, press any key to close it. is displayed, the kernel build is complete.

After these configurations and builds are done, you can configure and build the application in the same way as in SDK v2.0 or later.

7.2. Creating a multi-core application "myasmp"

This section explains how to create a multi-core application "myasmp". In this example, the main core program (supervisor) starts a program (worker) that runs on the sub-core, and creates an application that receives the string "Hello ASMP!" From the sub-core. This example use the workspace that created in "myapps" section.

7.2.1. Adding ASMP worker program

This section describes the procedure for adding a multi-core application in which the sub-core sends Hello ASMP! to the main core and displays the characters received by the main core.

Setting items Setting details

Target project folder

C:\msys64\home\user\myproject

ASMP worker name

myapps

Creating a sample application

Yes

Sample application name

asmpApp

vscode new asmp item creation en
  1. Right click on the project folder created in the previous chapter (myproject) and select Spresense: Add to project folder…​.

  2. In the opened Add to Project Folder dialog, select the project folder to which you want to add ASMP worker program and click Next.

  3. Select ASMP worker program from the item type and click Next.

  4. Enter the name of the ASMP worker you want to add to ASMP worker name. (In this example, it is myasmp.)

  5. Since we will also create an application that starts ASMP workers with main core application, check Create a sample application command for using this ASMP worker.

  6. Enter the command name to be created in Sample application name. (In this example, it is asmpApp.)

  7. Click the Create button to add the program file as shown below and the main source file is displayed in the editor.

    vscode wizard item asmp created en
7.2.1.1. About added files
File(Folder) Detail

myasmp_worker

This folder contains worker programs and Makefiles for building them.

myasmp_worker.c

The main source file for the worker. Implement a program that runs on a sub-core.

Makefile

Makefile for customizing workers. You can describe new added files and flags used for building.

include

This is a header file folder for sharing definitions with the main core application.

asmpApp

This folder contains a sample application for using the created worker.

7.2.2. Build configuration

To build a multi-core application, you need to enable feature/asmp in the SDK config preset. Here, configure to enable ASMP.

vscode sdk config asmp en
  1. Right click on the project folder and select Spresense: SDK Config from the project menu.

    If another 'Kernel config' or 'SDK config' is already open, please close it beforehand. Only one config window can be open at a time.
  2. Click New to open the SDK preset list.

  3. Click on the Feature category to switch categories and select asmp.

  4. Click OK.

  5. Click Save to save.

  6. If Configuration has been saved. is displayed, SDK configuration is complete.

    It may take some time to save depending on the environment. Please wait for a completion message.

7.2.3. Build the project

You can build in the same way as the main core application. The ASMP worker will built after the main core application is build.

  1. Right click on the project folder you want to build and select Spresense: Application build from the project menu.

  2. The application build will start, so wait for it to complete.

  3. If Terminal will be reused by tasks, press any key to close it. is displayed, the Application build is complete.

7.2.3.1. About build output files
File(Folder) Detail

myasmp_worker

myasmp_worker.debug

Debug ELF file for ASMP workers.

out

The folder where the build output files are copied.

worker

This is the folder where the ELF file for ASMP workers written to SPI-Flash.

myasmp

ELF file for ASMP worker myasmp.

myproject.nuttx.spk

This file is written to SPI-Flash on the Spresense board.

myproject.nuttx

An ELF file containing debugging information. Load this file into Spresense for ICE debugging.

7.2.4. Flashing the multi-core application into Spresense board and Check operation

You can flash binary into Spresense board in the same way as the main core application. After the main core binary is flashed, the worker ELF file is written to SPI-Flash.

7.2.4.1. Flashing build binaries
  1. Right click on the project folder you want to flash the built binary and select Spresense: Build and Flash from the project menu.

  2. The application build will start and wait for completion.

  3. As soon as the build is over, flashing to Spresense will start.

  4. After flashing to Spresense, the serial terminal will open.

7.2.4.2. Operation check

Enter the asmpApp command created on the opened serial terminal and type the Enter key. Then the Worker said: Hello ASMP! Is displayed.

vscode execute multicore application command en
  1. Type asmpApp on the opened serial terminal and press the enter key.

  2. The execution result of the created command is displayed.

7.3. About Build configuration

Build configuration (kernel config/SDK config) is a tool for configuring the build for application to be developed. It has presets for each purpose.

In SDK v1.5 or earlier, build configuration is divided into two parts, kernel and SDK, and in v2.0 or later, they are integrated and configured using SDK config.

Keyword completion and parsing syntax functions provided by Microsoft’s C/C++ extension will not work correctly unless this configuration is complete. Make sure to complete the configuration before creating the program.

7.3.1. For SDK v1.5 or earlier

  • Kernel configuration

    This is the configuration of NuttX a Realtime OS used in Spresense SDK . Configure OS level settings for programs that run on Spresense.

    For normal use, save with the release preset.

    Preset Detail

    release

    This is a default setting which is the functions of the Spresense SDK basic work through.Use this preset for normal usage.

    debug

    This preset includes settings such as debug log in addition to release.

  • SDK configuration

    Configuration of features specific to Spresense SDK. Audio, camera, GPS, and other features that run on Spresense are configured here. You can also configure the Examples application and system tools here.

    Category of preset Detail

    Device

    Presets for using devices such as sensors and SDcard. Depending on the preset, you may need to connect the device.

    Feature

    Presets for using Spresense functions and system tools.

    Examples

    This is a preset for using the sample application provided in the Spresense SDK.

7.3.2. For SDK v2.0 or later

  • SDK configuration

    Configuration of overall functions in a Spresense SDK (includes a NuttX). Audio, camera, GPS, and other NuttX features that run on Spresense are configured here. You can also configure the Examples application and system tools here.

    Category of preset Detail

    Device

    Presets for using devices such as sensors and SDcard. Depending on the preset, you may need to connect the device.

    Feature

    Presets for using Spresense functions and system tools.

    Examples

    This is a preset for using the sample application provided in the Spresense SDK and NuttX.

7.3.3. Configuration save menu

The functions of the configuration save menu are as follow:

Menu Function

New

You can select a preset configuration provided by Spresense SDK.

Save

Save the build configuration with the set contents.

Load

Open the saved backup configuration file.

Save as

Save the settings to any location. Since it is saved separately from the configuration file used for the build, it is not reflected in the build.

7.4. Installing the boot loader

To use the functions of Spresense and Spresense VSCode IDE, you need to install the latest boot loader. Otherwise, Spresense and Spresense VSCode IDE will not work properly.

This section explains the boot loader installation procedure.

Install the boot loader the first time you use it or when the SDK version is updated.
  1. Type a F1 key to display the command palette.

    vscode bootloader open en
  2. Input spresense bootloader to narrow down the command and choose Spresense: Flash bootloader.

    vscode bootloader select en
  3. Click OK on dialog that showing the message To install the bootloader, you must download the bootloader archive with a web browser…​..

    Download the boot loader from the web site.
    vscode bootloader web confirm en
  4. As the web browser opens, download according to the instructions on the page.

    vscode bootloader webpage1 en
    vscode bootloader webpage2 en
  5. Click on the dialog box to confirm the continuation of the installation.

    vscode bootloader zip confirm en
  6. In the file dialog that appears, select the downloaded ZIP file.

    vscode bootloader zip open en
  7. After selecting the ZIP file, the boot loader installation will begin.

    vscode bootloader flash start en
  8. If the task is completed normally as shown below, the installation of the boot loader is complete.

    vscode bootloader flash finished en

7.5. ICE debugging

7.5.1. Preparing the debugger

7.5.1.2. Mounting the SWD connector

Refer to the hardware documentation for how to mount the SWD connector.

7.5.1.3. OpenOCD settings (Ubuntu only)

In the case of Ubuntu, it is necessary to grant the authority to connect to ICE with the following command. Please do it before connecting ICE

sudo cp ~/spresenseenv/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d/
sudo udevadm control --reload

7.5.2. Debugging the main core with ICE

This section explains how to load the built binary directly into Spresense SRAM and check (debug) the operation.

You can debug by setting a break at a specified location and stopping the program at the specified location, or by writing a Watch statement and stopping at the specified condition.

7.5.2.1. Setting Break points
  1. Open the source code where you want to set the Break point (eg: if you want to set it on the 6th line).

    vscode debug break point en
  2. Click the left edge of the line you want to set (next to the left of the line number) and mark it red.

    vscode debug break point set en

This completes the setting of the Break point.

7.5.2.2. Starting Debug
  1. Click the debug icon from the icon on the left of the window.

    vscode debug open en
  2. elect the debug menu for the created project from the debug configuration list.

    vscode debug select en
  3. Click the Start debugging button.

    vscode debug start button en
  4. Wait for the completion of the debugging process.

    vscode debug prepare en
  5. When the debug control button icon changes as shown below, the preparation is complete.

    vscode debug started en
  6. Click Continue on the icon above and Spresense will start running.

    vscode debug executed en
  7. When processing that passes through the set break point (eg: command execution), the break will occur at the set point.

    vscode debug breaking en
  8. Click Continue button again to release from Break.

    vscode debug continue en