Debug the application

Debugging is an essential task for every embedded developer. The CMSIS view offers action buttons to start a debug session. The Run and Debug View lets you connect to the target.

Refer to the Arm CMSIS Debugger extension for a detailed description of debug features.

Debug on hardware

Attention

Make sure that your project and target are set up correctly and that the project can be loaded and run.

Keil Studio extension handles debugging as follows:

Generate launch.json and tasks.json

For each processor core, one debug server port is created. The underlying protocol is GDB MI using a GDB server. The server accesses the processor core via JTAG or SWD through a corresponding debug adapter.

Debug adapter support

Keil Studio support various debug adapters and and GDB server implementations from different vendors:

Using pyOCD

pyOCD is a Python-based tool and API for debugging and programming. It supports many debug adapters via the CMSIS-DAP protocol.

In the CMSIS view, open the Manage Solution dialog and go to the Debug Adapter section. Select one of the debug adapters named xyz@pyOCD.

The following JSON files are created automatically:

  • In the launch.json file, attach and launch configurations are added that let you attach the debug adapter to an already running GDB instance (for example when you have issued a load and run before) or launch a new debug session.
  • In the tasks.json file, the tasks CMSIS Erase, CMSIS Load, and CMSIS Run are created.

Note

Before entering a debug session, make sure that you have met the prerequisites of your debug adapter.

Command line usage

pyOCD can be also used on the command line. In a Terminal, issue for example:

pyocd list      --cbuild-run MyProject+TargetHW.cbuild-run.yml   // details of debug connection (scan JTAG, SWD)
pyocd gdbserver --cbuild-run MyProject+TargetHW.cbuild-run.yml   // start debug server, load command: flash
pyocd load      --cbuild-run MyProject+TargetHW.cbuild-run.yml   // flash and run application
pyocd erase     --cbuild-run MyProject+TargetHW.cbuild-run.yml   // erase image on device

Selecting a debug adapter

Todo

Explain how to select a CMSIS-DAP probe in case multiple are connected.

Attention

Make sure that the J-Link software is installed on your machine before attempting to use a J-Link adapter.

In the CMSIS view, open the Manage Solution dialog and go to the Debug Adapter section. Select "JLink Server".

The following JSON files are created automatically:

  • The tasks.json file is populated with CMSIS Erase, CMSIS Load, and CMSIS Run tasks.
  • The launch.json file is populated with JLink (launch) and JLink (attach) configurations.

Arm Debugger

You can use the Arm Debugger with Keil Studio.

Prerequisites

Before you can launch a debug session using Arm Debugger, you need to:

  1. Install the Arm Debugger VS Code extension.
  2. Add the Arm Debugger to your vcpkg-configuration.json file, for example:
    "arm:debuggers/arm/armdbg": "6.6.0"

Setup for Arm Debugger

In the CMSIS view, open the Manage Solution dialog and go to the Debug Adapter section. Select one of the debug adapters named xyz@Arm-Debugger.

The following JSON files are created automatically:

  • In the launch.json file, attach and launch configurations are added that let you attach the debug adapter to an already running GDB instance (for example when you have issued a load and run before) or launch a new debug session.
  • In the tasks.json file, the tasks CMSIS Erase, CMSIS Load, and CMSIS Run are created.

Keil uVision

Attention

This only works on a Windows PC as µVision runs on Windows.

Debug in simulation