# MCUXpresso Tasks Usage Examples The following sections describe some basic use cases that can be automated using the MCUXpresso Tasks supported by the extension. ## Interaction with MCUXpresso SDK One of the most basic use cases that can be automated is one that interacts with the MCUXpresso SDK. Below is an example of tasks sequence that clones and imports a specific MCUXpresso SDK version, imports an example project and then builds all the build configurations. You'll have to save the tasks definition in a separate `mcuxpresso-tasks.json` file and then execute the sequence using one of the supported methods. Let's assume the file is saved inside `${userHome}` ```json { "version": "1.0.0", "exitVSCodeOnCompletion": false, "tasksCompletionTimeout": 0, "tasks": [ { "type": "MCUXpresso", "version": "1.0", "label": "Install Remote MCUXpresso SDK", "description": "This task installs MCUXpresso SDK v25.06", "id": "task_install_mcuxsdk_v25.06.00", "commandOptions": { "command": "installRemoteRepo", "repoType": "mcuxsdk", "repoRevision": "v25.06.00", "repoDestinationPath": "${userHome}/mcux-vscode/mcuxsdk" }, "runOptions": { "taskOutputFile": "${userHome}/mcux-vscode/taskOutputFiles/installRemoteRepoTask.log" } }, { "type": "MCUXpresso", "version": "1.0", "label": "Import \"Hello World\" Example from MCUXpresso SDK", "commandOptions": { "command": "importExampleFromRepo", "repoPath": "${userHome}/mcux-vscode/mcuxsdk", "repoTemplateID": "hello_world_cm33_core0", "importedProjectName": "my_hello_world", "appType": "freestanding", "exampleLocation": "${userHome}/mcux-vscode/examples", "boardID": "lpcxpresso55s69", "toolchainPath": "${userHome}/.mcuxpressotools/arm-gnu-toolchain-13.2.Rel1-mingw-w64-i686-arm-none-eabi" }, "runOptions": { "taskOutputFile": "${userHome}/mcux-vscode/taskOutputFiles/importExampleFromRepoTask.log" } }, { "type": "MCUXpresso", "version": "1.0", "label": "Build \"Hello World\" example", "commandOptions": { "command": "buildProject", "projectName": "my_hello_world", "buildConfigName": "/.*/" }, "runOptions": { "taskOutputFile": "${userHome}/mcux-vscode/taskOutputFiles/buildProjectTask.log" } } ] } ``` Once the tasks are executed, a report will be generated next to the original tasks file. ## Interaction with Zephyr Similar to the MCUXpresso SDK example, a similar list of tasks can be defined for Zephyr. Please make sure you use the VS Code auto-completion feature to help you create the tasks and ensure that the tasks are defined according to the schema defined in MCUXpresso VS Code extension. ## Erasing and programming a flash device There are dedicated commands that can be executed by an MCUXpresso task, allowing you to erase and program a flash device. Assuming you already imported a "Hello World" example and it was named "my_hello_world", here's an example of a task sequence for erasing and programming a board connected via USB and the debug probe has the serial number listed below: ```json { "version": "1.0.0", "exitVSCodeOnCompletion": false, "tasksCompletionTimeout": 0, "tasks": [ { "type": "MCUXpresso", "version": "1.0", "label": "Erase Flash", "commandOptions": { "command": "eraseFlash", "projectName": "my_hello_world", "debugConfigName": "Debug", "probeSN": "LRAVBQIQ" }, "runOptions": { "taskOutputFile": "${userHome}/mcux-vscode/taskOutputFiles/eraseFlashTask.log" } }, { "type": "MCUXpresso", "version": "1.0", "label": "Program Flash", "commandOptions": { "command": "programFlash", "projectName": "my_hello_world", "debugConfigName": "Debug", "probeSN": "LRAVBQIQ", "resetTargetOnExecution": true }, "runOptions": { "taskOutputFile": "${userHome}/mcux-vscode/taskOutputFiles/programFlashTask.log" } } ] } ``` ## Debugging a project Among the list of available commands, there's also one that allows initiating a debug session. By default, once the debug session is started, the MCUXpresso VS Code extension will automatically resume the target, allowing you to capture application's output. If semihosting support is enabled inside the application, the output will be automatically captured by the extension and saved in the output file specified in the `appOutputFile` property. If UART is used, you'll need to externally configure the terminal and capture the output by other means. The example below assumes that the "Philosophers" Zephyr application has been imported and built. A debug session will be started by using the "Debug" configuration available in the `launch.json` file, available inside the project. ```json { "version": "1.0.0", "exitVSCodeOnCompletion": false, "tasksCompletionTimeout": 0, "tasks": [ { "type": "MCUXpresso", "version": "1.0", "label": "Run and Debug \"Philosophers\" Zephyr Application", "commandOptions": { "command": "runDebugProject", "projectName": "zephyr_philosophers", "probeSN": "LRAVBQIQ", "debugConfigName": "Debug", "debugConfigOverride": { "probeSerialNumber": "LRAVBQIQ" }, "appOutputFile": "${userHome}/mcux-vscode/appOutputFiles/philosophers.log" }, "runOptions": { "taskOutputFile": "${userHome}/mcux-vscode/taskOutputFiles/runDebugZephyrTask.log" } } ] } ``` Once the tasks is executed, debug session will be automatically terminated and report will be generated.