MCUXpresso Tasks Introduction

This section focuses on one type of tasks automation supported by the MCUXpresso for VS Code extension. More specifically, the extension allows execution of MCUXpresso-specific tasks that help automate various tasks, like importing an SDK, importing an example project, or building a specific project. This can be achieved by defining custom MCUXpresso tasks.

Note that VS Code was not designed to be used as a command line tool and this introduces some limitations and challenges when it comes to automating tasks. Therefore, please take a look at Notes and limitations section to understand the current constraints.

Tasks can be defined in mcuxpresso-tasks.json files and executed using the MCUXpresso Tasks system. Moreover, the same tasks can be plugged into the tasks.json file, that is available in a VS Code project.

There are three commands dedicated to interation with MCUXpresso Tasks system:

  • Generate Sample Tasks File

  • Validate Tasks File

  • Execute Tasks from File

Generating a sample tasks file

To help you get started with MCUXpresso tasks, the extension provides a command to generate a sample tasks file with predefined tasks. This allows you to quickly understand the structure and capabilities of MCUXpresso tasks.

To generate a sample tasks file, you can use the “Generate Sample Tasks File” command, which will create a mcuxpresso-tasks.json file in the folder you specify.

Validating a tasks file

The extension provides a “Validate Tasks File” command that helps you verify a specific file against the schema defined for MCUXpresso tasks.

If you edit your mcuxpresso-tasks.json file inside VS Code, the file is automatically validated against the required schema. In case of errors, they will be listed inside the Problems view. You’ll have to make sure that a tasks file is valid against the schema, otherwise none of the tasks will be executed.

Executing MCUXpresso tasks

You can define MCUXpresso tasks in two ways:

  1. Inside tasks.json file located in the project.

  2. In a dedicated mcuxpresso-tasks.json file.

There are several ways to execute MCUXpresso tasks, as described in the following sections.

Executing tasks from “tasks.json”

In order to execute tasks defined inside tasks.json, you’ll need to use VS Code’s mechanisms that allow execution of various tasks. Open command palette (Ctrl-Shift-P), type “Tasks: Run Task” and select it, type “MCUXpresso” and select it, choose the task from the list in order to start execution. A dedicated terminal item will open inside the Terminal view, showing the progress and results of the task execution.

Executing tasks using the dedicated command

Execution of a task from an mcuxpresso-tasks.json file can be done similarly by opening the command palette (Ctrl-Shift-P), typing “Execute Tasks from File”, and then browse to the specific mcuxpresso-tasks.json file you want to run. Validation will happen behind the scenes , and if the task schema is correct, each task will be executed. A dedicated terminal will be created for each task. Once the execution of all tasks is complete, a results file will be created next to the original tasks file. The results file will contain the list of all tasks executed, their status, and any potential error messages.

{
    "version": "1.0",
    "tasksResults": [
        {
            "label": "Install \"doom_mcx\" product from ACH",
            "id": "install_doom_mcx"
            "executionResult": "TASK_SUCCEEDED",
            "executionOutputFilePaths": [
                "C:/Users/NXP/mcux-vscode/taskOutputFiles/installAchProductTask.log"
            ]
        }
    ]
}

Executing tasks automatically at VS Code startup

A list of MCUXpresso tasks can also be executed automatically when VS Code starts-up. To achieve this, you’ll need to set the MCUXPRESSO_TASKS_FILE environment variable to point to the mcuxpresso-tasks.json file you want to execute, then start VS Code. As described in the previous section, once the sequence of tasks is complete, a results file will be generated with the execution status of each task.

Note that VS Code can also close itself automatically after task execution. This can be achieved by specifying "exitVSCodeOnCompletion": true when defining tasks in the mcuxpresso-tasks.json configuration.