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:
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:
- Most of the debug adapters (including ST-Link) are served by pyOCD using the Arm CMSIS Debugger extension.
- Segger J-Link Server is supported.
- Arm Debugger and the Arm Debugger extension are supported.
- You can also use Arm Keil µVision for debugging a project.
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
andlaunch
configurations are added that let you attach the debug adapter to an already running GDB instance (for example when you have issued aload and run
before) or launch a new debug session. - In the
tasks.json
file, the tasksCMSIS Erase
,CMSIS Load
, andCMSIS 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.
Using J-Link Server
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 withCMSIS Erase
,CMSIS Load
, andCMSIS Run
tasks. - The
launch.json
file is populated withJLink (launch)
andJLink (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:
- Install the Arm Debugger VS Code extension.
- 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
andlaunch
configurations are added that let you attach the debug adapter to an already running GDB instance (for example when you have issued aload and run
before) or launch a new debug session. - In the
tasks.json
file, the tasksCMSIS Erase
,CMSIS Load
, andCMSIS Run
are created.
Keil uVision
Attention
This only works on a Windows PC as µVision runs on Windows.