MCUXpresso VSCode Helper Script: Difference between revisions

From Variscite Wiki
No edit summary
No edit summary
Line 21: Line 21:
  $ code --install-extension ms-vscode.cpptools
  $ code --install-extension ms-vscode.cpptools
  $ code --install-extension marus25.cortex-debug
  $ code --install-extension marus25.cortex-debug
==Install Segger JLink==
$ Download JLink_Linux_V760b_x86_64.deb from https://www.segger.com/downloads/jlink/
$ sudo dpkg -i JLink_Linux_V760b_x86_64.deb
The software will be installed in /opt/SEGGER folder
==Install MCUXpresso Toolchain and SDK==
==Install MCUXpresso Toolchain and SDK==
Download and install GNU-ARM bare-metal toolchain:
Download and install GNU-ARM bare-metal toolchain:
Line 39: Line 43:
   }}
   }}
Variscite provides a script to simplify the Project Configuration
Variscite provides a script to simplify the Project Configuration
 
==Configure a single Project==
=Open Visual Studio Code and Configure a Project=
For this example, we will configure the hello_world demo. However, the process is the same for all demos.
$ ./var_add_vscode_support.sh -b {{#var:BOARD_FOLDER}} -e boards/{{#var:BOARD_FOLDER}}/demo_apps/hello_world -t tcm -d /opt/SEGGER/JLink_Linux_V760b_x86_64
==Configure all Projects==
$ ./var_add_vscode_support.sh -b {{#var:BOARD_FOLDER}} -e all -t tcm -d /opt/SEGGER/JLink_Linux_V760b_x86_64
==Open a Demo in VS Code==
==Open a Demo in VS Code==
For this example, we will use the hello_world demo. However, the process is the same for all demos.
For this example, we will use the hello_world demo. However, the process is the same for all demos.
From a terminal, launch VS Code and open the hello_world demo directory:
From a terminal, launch VS Code and open the hello_world demo directory:
  $ code {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/
  $ code {{#var:SDK_PATH}}/freertos-variscite/{{#var:BOARD_FOLDER}}/demo_apps/hello_world/
Line 49: Line 55:


[[File:Vscode_mcuxpresso.png]]
[[File:Vscode_mcuxpresso.png]]
==Configure VS Code Project Files==
Next, we will create the following files:
{| class="wikitable"
|-
|'''.vscode/settings.json'''||VS Code file to configure global environment variables for the SDK/toolchain
|-
|'''.vscode/tasks.json'''||VS Code file to override or add new tasks. Runs <code>armgcc/build_ddr_debug.sh</code> when VS Code build command is executed.
|-
|'''.vscode/c_cpp_properties.json'''||VS Code file to configure include path for IntelliSense.
|}To create a new file or folder in VS Code, right click in the VS Code explorer view and select '''New File''' or '''New Folder'''. Or, use the following buttons:
[[File:Vscode_mcuxpresso_newfile.png]]
Create a new folder named '''.vscode'''. Then, create a new file '''.vscode/settings.json'''
'''.vscode/settings.json:'''
{
    "VARISCITE": {
        /* Configure ARMGCC_DIR per https://variwiki.com/index.php?title=MCUXpresso */
        "ARMGCC_DIR": "${env:HOME}/var-mcuxpresso/{{#var:TOOLCHAIN_FOLDER}}",
        /* SOC Include Path */
        "SOC_INCLUDE_PATH" : "${env:HOME}/var-mcuxpresso/freertos-variscite/devices/{{#var:SDK_DEVICE}}/",
    }
}
Create a new file '''.vscode/tasks.json'''. This configures the VS Code Build task to run the build scripts provided by NXP for the demo projects. Adjust the "command" property to build for ddr or tcm memory per your requirements:
'''.vscode/tasks.json:'''
{
    "version": "2.0.0",
    /* Configure ARMGCC_DIR per https://variwiki.com/index.php?title=MCUXpresso */
    "options": {
        "env": {
            "ARMGCC_DIR": "${config:VARISCITE.ARMGCC_DIR}",
        }
      },
      /* Configure integrated VS Code Terminal */
    "presentation": {
        "echo": false,
        "reveal": "always",
        "focus": true,
        "panel": "dedicated",
        "showReuseMessage": true,
    },
    "tasks": [
        /* Build Task */
        {
            "label": "build",
            "type": "shell",
            "dependsOn": ["clean"],
            "problemMatcher": ["$gcc"],
            "options": {
                "cwd": "${workspaceFolder}/armgcc"
            },
            "command": "./build_ddr_debug.sh",
        },
        /* Clean task */
        {
            "label": "clean",
            "type": "shell",
            "command": "./clean.sh;",
            "problemMatcher": ["$gcc"],
            "options": {
                "cwd": "${workspaceFolder}/armgcc"
            }
        }
    ]
}
Create a new file '''.vscode/c_cpp_properties.json''':
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "${config:VARISCITE.SOC_INCLUDE_PATH}/**"
            ]
        }
    ],
    "version": 4
}
=Build Demo using VS Code=
=Build Demo using VS Code=
After creating the VS Code files in '''.vscode/''', cross compile the project by selecting '''Terminal->Run Build Task...''' or entering <code>Ctrl+Shift+B</code> and selecting '''Build''':
After creating the VS Code files in '''.vscode/''', cross compile the project by selecting '''Terminal->Run Build Task...''' or entering <code>Ctrl+Shift+B</code> and selecting '''Build''':

Revision as of 21:49, 4 January 2022

DART-MX8M-MINI - MCUXpresso 2.10.0 Development with VS Code

Overview

This guide demonstrates how to develop and cross compile applications for the DART-MX8M-MINI Cortex-m4 co-processor using Microsoft Visual Studio Code.

Please visit Variscite's MCUXpresso Guide for additional information about manually building demos, integration with Yocto, running applications from U-Boot and Linux, and JTAG debugging.

Setup Host Computer Environment

Follow the steps below to prepare a fresh Ubuntu 20.04 installation for VS Code debugging:

Install Dependencies

$ sudo apt-get -y update
$ sudo apt-get -y install build-essential gdb gdb-multiarch git cmake

Install VS Code

$ sudo snap install --classic code

Install VS Code Extensions

VS Code has a graphical interface for installing and managing extensions. To learn more, please see Using extensions in Visual Studio Code

For this guide, we will install the required extensions using the command line:

$ code --install-extension ms-vscode.cpptools
$ code --install-extension marus25.cortex-debug

Install Segger JLink

$ Download JLink_Linux_V760b_x86_64.deb from https://www.segger.com/downloads/jlink/
$ sudo dpkg -i JLink_Linux_V760b_x86_64.deb

The software will be installed in /opt/SEGGER folder

Install MCUXpresso Toolchain and SDK

Download and install GNU-ARM bare-metal toolchain:

$ mkdir ~/var-mcuxpresso
$ cd ~/var-mcuxpresso
$ wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
$ tar xvf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2

Download MCUXpresso SDK for the SOM:

$ cd ~/var-mcuxpresso
$ git clone https://github.com/varigit/freertos-variscite -b mcuxpresso_sdk_2.10.x-var01
$ cd freertos-variscite

Add Visual Studio Code support to the Variscite examples

Available Demos

All of the Variscite examples are located under the following folder.

~/var-mcuxpresso/freertos-variscite/boards/dart_mx8mm

Variscite provides a script to simplify the Project Configuration

Configure a single Project

For this example, we will configure the hello_world demo. However, the process is the same for all demos.

$ ./var_add_vscode_support.sh -b boards/dart_mx8mm -e boards/boards/dart_mx8mm/demo_apps/hello_world -t tcm -d /opt/SEGGER/JLink_Linux_V760b_x86_64

Configure all Projects

$ ./var_add_vscode_support.sh -b boards/dart_mx8mm -e all -t tcm -d /opt/SEGGER/JLink_Linux_V760b_x86_64

Open a Demo in VS Code

For this example, we will use the hello_world demo. However, the process is the same for all demos. From a terminal, launch VS Code and open the hello_world demo directory:

$ code ~/var-mcuxpresso/freertos-variscite/boards/dart_mx8mm/demo_apps/hello_world/

VS Code should open and look similiar too:

Vscode mcuxpresso.png

Build Demo using VS Code

After creating the VS Code files in .vscode/, cross compile the project by selecting Terminal->Run Build Task... or entering Ctrl+Shift+B and selecting Build:

Vscode mcuxpresso run build task.png

If the build task completes successfully, the following output files will be generated:

~/var-mcuxpresso/freertos-variscite/boards/dart_mx8mm/demo_apps/hello_world/armgcc/ddr_debug/hello_world.bin
~/var-mcuxpresso/freertos-variscite/boards/dart_mx8mm/demo_apps/hello_world/armgcc/ddr_debug/hello_world.elf

Please visit Variscite's MCUXpresso Guide for instructions to run the demo using U-Boot or the Linux Remote Processor Framework.