Run and Debug Custom Firmware with Visual Studio Code

As shown in Custom Firmware Development ModusToolbox can be used to setup a custom firmware application using Visual Studio Code (VSC). This page will walk a user though the basics of setting up VSC, and running or debugging an application.

Setup

This section will outline the software required to run custom firmware on the IF820 in VSC.

Visual Studio Code Extensions

A few extensions are required, and a number of other extensions, such as code formatting tools can be used.

Cortex-Debug

Cortex-Debug

C/C++ Extension Pack

C/C++ Extension Pack

pyOCD

To install pyOCD, see the Installing section of the documentation on the pyOCD website.

Please note that pyOCD also has it’s own software prerequisites (such as Python) which are also outlined in the documentation link above.

Please also note that when running any of the sample applications with EZ-Serial, the pyOCD dependencies are installed automatically since they are part of the requirements.txt file.

pyOCD Configuration

To debug using pyOCD a configuration section needs to be added to the launch.json file in the .vscode folder of the project.

The configuration is shown below so that it can be copied and then pasted into launch.json

{
    "name": "PyOCD Debug",
    "cwd": "${workspaceFolder}",
    "executable": "./build/CYBT-243053-EVAL/Debug/project_name.elf",
    "request": "attach",
    "type": "cortex-debug",
    "servertype": "pyocd",
    "interface": "swd",
    "targetId": "cortex_m"
}

configuration

Note: the targetID property cortex_m is the closest match at the time of this writing. Infineon is working on creating a CMIS-Pack for the specific Cortex M that is used on the Vela IF820. In the future that can be used in place of the cortex-m value.

Make File

To enable debugging open the makefile and set ENABLE_DEBUG property to 1 as shown in the image below.

MakeFile

Set ARM Toolchain Path

In the user settings (settings.json) the ARM Toolchain should point to the one that ModusToolbox uses.

ARM Toolchain

Building the project

The tasks.json file is setup to run common build actions. Simply click the Terminal-Run menu option

Terminal-Run

Then select the appropriate task, such as “Build[Debug]”

Build Tasks

Selecting a Debugger

To select a debugger, such as the pyOCD debugger described above, navigate to the “Run & Debug” menu and select the debugger from the dropdown menu as shown below.

Debugger

Debugging Project

When debugging is started, the project will stop at BUSY_WAIT_TILL_MANUAL_CONTINUE_IF_DEBUG_ENABLED. To continue debugging the user has to set the spar_debug_enable variable to 1 and then continue debugging. This is shown in the image below.

Debugging