Take your STM32 debugging in VS Code to the next level. This hands-on guide shows how to move from basic breakpoints to advanced system insight using the IAR C-SPY Debug extension, covering simulator setup, hardware debugging with ST-LINK, and powerful features like trace, code coverage, and profiling with IAR I-jet Trace. Read the full article or watch the video for a step-by-step, hands-on guide.
VS Code has become the world’s most widely used IDE, and with STM32Cube extensions, it brings the STM32 ecosystem into a modern, flexible development environment. Developers benefit from a powerful C/C++ editor, CMake and Ninja-based builds, seamless Git integration, and one-click debugging, covering the full project lifecycle.
CMake further adds flexibility, enabling teams to choose their preferred IDE and OS while maintaining CI/CD workflows essential for modern embedded development. Once your STM32 project is up and running in VS Code, you can take debugging to the next level with the IAR C-SPY Debug extension for VS Code. What starts as a lightweight setup quickly evolves into a professional-grade embedded analysis environment, designed for real-world complexity.
If you’re new to STM32Cube for VS Code, we recommend starting with ST’s official guides:
- How to create projects using the STM32 VS Code Extension
- Get started with STM32Cube for VS Code: from installation to debugging
From debugging to deep system insight With IAR C-SPY, debugging goes beyond breakpoints and variable inspection. You gain access to Listwindows, a powerful, spreadsheet-like visualization system that gives you deep insight into your running system. In this hands-on demo, we’ll explore both foundational and advanced capabilities:
Core debugging views
- Core registers and custom register groups
- Symbolic memory with direct variable navigation
- Live Watch expressions
Advanced analysis features
- ETM/SWO trace
- Functional profiling
- Real-time code coverage
Together, STM32Cube for VS Code and IAR create a strong combination:
- STM32Cube provides a fast, flexible entry point into the STM32 ecosystem
- The IAR toolchain and IAR C-SPY adds deterministic builds, advanced trace, deep analysis, and professional debugging tools trusted in safety- and security-critical environments What you’ll learn in this guide In this tutorial, you’ll:
- Set up debugging in VS Code using the IAR C-SPY extension
- Run your application in the Simulator
- Move to real hardware debugging with ST-LINK
- Unlock advanced features like trace, code coverage, and functional profiling, directly inside VS Code
Install the extension In VS Code:
- Press Ctrl + Shift + X
- Search for @publisher:IAR
- Click Install
You can also access the extension via the VS Code Marketplace or GitHub. More details at https://www.iar.com/vscode Note: You’ll need the IAR toolchain for Arm installed locally. You can download a free evaluation version of the IAR Embedded Workbench for Arm here: https://www.iar.com/embedded-development-tools/free-trials Try it yourself To follow along with the demo:
- Watch the full walkthrough video: https://youtu.be/BTy6QhbMY94
- Download the example project: https://github.com/iarsystems/vscode_demo_st/archive/refs/heads/main.zip
Start by creating a debug configuration:
<project-folder>/.vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "cspy",
"name": "C-SPY: Simulator",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"stopOnEntry": true,
"workbenchPath": "C:/iar/ewarm-9.70.1",
"target": "arm",
"driver": "Simulator",
"driverOptions": [
"--cpu=Cortex-M4",
"--semihosting"
]
}
]
}
Now:
- Open main.c
- Set a breakpoint (e.g. on ++counter;)
- Press F5 You can now step through code, inspect variables, and view output. At this point, you have standard debugging. Now we level up.
Add a second configuration:
{
"type": "cspy",
"name": "C-SPY: ST-LINK",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"stopOnEntry": true,
"workbenchPath": "C:/iar/ewarm-9.70.1",
"target": "arm",
"driver": "ST-LINK",
"leaveTargetRunning": false,
"driverOptions": [
"--device=STM32F407VG",
"--cpu=Cortex-M4",
"-p C:/iar/ewarm-9.70.1/arm/config/debugger/ST/STM32F407VG.ddf",
"--semihosting",
"--drv_communication=USB0",
"--drv_interface=SWD"
]
}
You can now:
- Flash the target
- Start debugging
- Run and stop directly on STM32 hardware
Tip: driverOptions supports full C-SPY command-line parameters, with autocomplete directly in VS Code.
Traditional debuggers show variables. C-SPY shows your system. Open the Listwindows view in VS Code. These views act like a live spreadsheet of your target, enabling:
- Registers
- Symbolic memory
- Live Watch
- Trace
- Code coverage
- Profiling
Real-world debugging examples Debugging peripheral issues (register-level insight) When a peripheral behaves unexpectedly:
- Create a custom register group (e.g. SPI)
- Run your application Instantly see:
- Which register changed
- Which bit flipped
- Exactly when it happened (highlighted) Tracking memory corruption When your system crashes after runtime:
- Navigate directly to variables in Symbolic Memory
- Monitor them in Live Watch Quickly identify:
- Corrupted pointers
- Buffer overruns
- Stack issues
- RTOS-related anomalies
When bugs are too fast for breakpoints, traditional debugging falls short, you simply can’t stop execution at the right moment. This is where trace and browse mode come in, allowing you to go back in time and analyze what already happened, step by step.
- Enable trace
- Open the trace timeline
- Jump into Browse Mode Now you can step back in time and see exactly what led to the issue.
Notice that to enable this level of insight, an I-jet Trace probe is required, as it provides the hardware support needed to record and replay execution for deep analysis.
Code coverage for validation and security Code coverage ensures that your code is actually executed, not just assumed to be tested. With C-SPY, you get instruction-level precision, beyond traditional tools like gcov. You can analyze:
- Coverage per function
- Branch coverage inside conditions
- Untested code paths
This is especially valuable for:
- Safety workflows
- Security validation
- Test completeness
Functional profiling (find performance bottlenecks) Enable functional profiling to understand runtime behavior:
- Which functions consume the most time
- Execution frequency
- Performance hotspots Instead of guessing, you measure.
Advanced workflow tip: Launch vs Attach C-SPY supports flexible debug workflows:
- One configuration to flash and launch
- Another to attach to a running system Ideal for:
- Long-running issues
- Field-like scenarios
- Non-intrusive debugging
STM32Cube for VS Code provides a strong, flexible foundation for STM32 development. But when your project grows in complexity, when you need deeper insight into registers, memory behavior, execution flow, and performance, the IAR C-SPY Debug extension takes you further. It transforms VS Code into a professional embedded debugging and analysis platform, helping you:
- Find issues faster
- Validate behavior with confidence
- Optimize performance with real data Ready to see it in action? Watch the demo and try it yourself.