🪲 Debugging Zephyr RTOS in VS Code

Muhammad Waleed Badar
2 min readJan 28, 2025

--

Setting Up Zephyr RTOS Debugging in VSCode for STM32 Development

Debugging embedded systems can be challenging, but with Visual Studio Code and the right configuration, you can create a seamless debugging experience for Zephyr RTOS applications. This guide walks through setting up a debugging environment for STM32F3 Discovery board using VSCode, OpenOCD, and the Cortex-Debug extension.

Prerequisites

Before starting, ensure you have:

  • Zephyr RTOS SDK installed
  • Visual Studio Code with Cortex-Debug extension
  • OpenOCD installed

Environment Setup

First, we need to set up our environment variables in PowerShell. These variables help VSCode locate the necessary tools and source files:

setx ZEPHYR_BASE "C:\Users\walid\zephyrproject\zephyr"
setx ZEPHYR_SDK_INSTALL_DIR "C:\Users\walid\zephyr-sdk-0.16.8"

These commands create persistent environment variables pointing to:

  • The Zephyr RTOS base directory
  • The Zephyr SDK installation directory

VSCode Debug Configuration

Create or update your .vscode/launch.json file with the following configuration:

{
"version": "0.0.1",
"configurations": [
{
"name": "Cortex Debug",
"cwd": "${env:ZEPHYR_BASE}",
"executable": "${env:ZEPHYR_BASE}/build/zephyr/zephyr.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"runToEntryPoint": "main",
"device": "STM32F303VC",
"configFiles": [
"board/stm32f3discovery.cfg"
],
"gdbPath": "${env:ZEPHYR_SDK_INSTALL_DIR}/arm-zephyr-eabi/bin/arm-zephyr-eabi-gdb.exe",
"armToolchainPath": "${env:ZEPHYR_SDK_INSTALL_DIR}/arm-zephyr-eabi/bin"
}
]
}

Let’s break down the key configuration elements:

  1. Working Directory: Set to ${env:ZEPHYR_BASE} to ensure proper file resolution
  2. Executable: Points to the compiled Zephyr ELF file
  3. Debug Server: Uses OpenOCD for communication with the target
  4. Entry Point: Automatically runs to main() function
  5. Target Device: Specified as STM32F303VC
  6. OpenOCD Config: Uses the STM32F3 Discovery board configuration
  7. GDB Path: Points to the Zephyr SDK’s GDB executable
  8. Toolchain Path: References the ARM toolchain directory

Usage

With this configuration in place, you can start debugging using VSCode’s debug view (F5)

Conclusion

This setup provides a professional debugging environment for Zephyr RTOS development on STM32 platforms. The integration between VSCode, OpenOCD, and Cortex-Debug creates a powerful toolchain for embedded development.

--

--

Muhammad Waleed Badar
Muhammad Waleed Badar

Written by Muhammad Waleed Badar

I am passionate about Embedded Systems, IoT Development and Electronics HW Design. Exploring The Zephyr Project 🪁 while solving real-world problem using tech!⚡

No responses yet