CTest with IAR C‐SPY Debugger for Arm - iarsystems/cmake-tutorial GitHub Wiki
Setting up ctest with the IAR C-SPY Debugger for Arm attaching to hardware can be performed using cspybat, its command line interface.
This article expands the Run section found in the tutorial.
This guide applies to product versions below:
- IAR Build Tools for Arm V9.70.x
- IAR Embedded Workbench for Arm V9.70.x
The same principles should apply to product versions other than the ones specified above, with eventual minor changes and tweaks.
The non-interactive C-SPY Command Line interface (<path/to/install-dir>/common/bin/CSpyBat) rely on plugins and drivers for the simulator and supported debug probes installed under <path/to/installation-dir>/arm/bin. These drivers differ slightly between the supported operating systems. These differences are highlighted in the table below.
| Driver/Plugin | Filename on Linux (case-sensitive) | Filename on Windows (case-insensitive) |
|---|---|---|
| Processor driver | libarmproc.so |
armproc.dll |
| Simulator driver | libarmsim2.so |
armsim2.dll |
| I-jet driver | libarmjet.so |
armjet.dll |
| J-Link driver | libarmjlink.so |
armjlink.dll |
| ST-Link driver | libarmstlink.so |
armstlink.dll |
| Support plugin | libarmLibsupportUniversal.so |
armLibsupportUniversal.dll |
It is possible to leverage CMake-provided functionality to accommodate such differences transparently, by using CMAKE_SHARED_LIBRARY_PREFIX and CMAKE_SHARED_LIBRARY_SUFFIX.
Important
When using real hardware, the executable must be linked with an appropriate memory layout. The linker configuration can be specified by --config <path-to>/<linker-config-file>.icf. For example, when using the STM32F407VG device with the tutorial project, rebuild the project using its stock linker configuration:
# Infers other required information from CMAKE_C_COMPILER
cmake_path(GET CMAKE_C_COMPILER PARENT_PATH BIN_DIR)
cmake_path(GET BIN_DIR PARENT_PATH TOOLKIT_DIR)
cmake_path(GET TOOLKIT_DIR FILENAME TOOLKIT)
target_link_options(tutorial PRIVATE
--config ${TOOLKIT_DIR}/config/linker/ST/stm32f407xG.icf
--cpu=cortex-m4
--semihosting)The output ELF file is referred by where tgt will be tutorial for following examples. Rebuild the project after changing the CMakeLists.txt configuration file.
Adding a test that will be performed directly on hardware requires additional parameters for driving the used probe correctly. The example below uses the IAR I-jet probe for attaching to a STM32F407VG target:
add_test(NAME tutorialTest
COMMAND ${BIN_DIR}/../../common/bin/CSpyBat
# C-SPY drivers for the Arm simulator via command line interface
${BIN_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${TOOLKIT}PROC${CMAKE_SHARED_LIBRARY_SUFFIX}
${BIN_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${TOOLKIT}JET${CMAKE_SHARED_LIBRARY_SUFFIX}
--plugin=${BIN_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${TOOLKIT}LibsupportUniversal${CMAKE_SHARED_LIBRARY_SUFFIX}
# I-jet flash loader
--flash_loader=${TOOLKIT_DIR}/config/flashloader/ST/FlashSTM32F4xxx.board
# The target executable (built with debug information)
--debug_file=$<TARGET_FILE:tutorial>
# Limit the maximum execution time (milliseconds)
--timeout=5000
# C-SPY driver options
--backend
# Selected CPU architecture
--cpu=cortex-m4
# Selected FPU
--fpu=VFPv4_SP
# Arm semihosting support (for `printf()`)
--semihosting
# Target device
--device=STM32F407VG
# Device Description File
-p ${TOOLKIT_DIR}/config/debugger/ST/STM32F407VG.ddf
# I-jet: Power the target (up to 420 mA)
--jet_power_from_probe=switch_off
# I-jet: driver interface
--drv_interface=SWD)Adding a test that will be performed directly on hardware requires additional parameters for driving the used probe correctly. The example below uses the SEGGER J-Link probe for attaching to a STM32F407VG target:
add_test(NAME tutorialTest
COMMAND ${BIN_DIR}/../../common/bin/CSpyBat
# C-SPY drivers for the Arm simulator via command line interface
${BIN_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${TOOLKIT}PROC${CMAKE_SHARED_LIBRARY_SUFFIX}
${BIN_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${TOOLKIT}JLINK${CMAKE_SHARED_LIBRARY_SUFFIX}
--plugin=${BIN_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${TOOLKIT}LibsupportUniversal${CMAKE_SHARED_LIBRARY_SUFFIX}
# The target executable (built with debug information)
--debug_file=$<TARGET_FILE:tutorial>
# Limit the maximum execution time (milliseconds)
--timeout=5000
# C-SPY driver options
--backend
# Selected CPU architecture
--cpu=cortex-m4
# Selected FPU
--fpu=VFPv4_SP
# Arm semihosting support (for `printf()`)
--semihosting
# Target device
--device=STM32F407VG
# Device Description File
-p ${TOOLKIT_DIR}/config/debugger/ST/STM32F407VG.ddf
# J-Link: communication port
--drv_communication=USB0
# J-Link: driver interface
--drv_interface=SWD)