---
id: 18706
lang: en
title: "Claude debugs an STM32 microcontroller in VS Code and tunes motor PID in 15 minutes"
published_at: "2026-11-30 14:29:48"
source_name: "Habr AI"
source_url: "https://habr.com/ru/articles/1114064/?utm_campaign=1114064&utm_source=habrahabr&utm_medium=rss"
canonical_url: "https://news.hamidun.com/en/news/18706"
categories: ["llm", "autonomous"]
publisher: "AI News by Jemal Hamidun (news.hamidun.com)"
---

# Claude debugs an STM32 microcontroller in VS Code and tunes motor PID in 15 minutes

> **Краткая суть (BLUF):** AI agents write code for STM32 microcontrollers, but they debug the board in the dark, and a human then combs through the logs.  The Bare Metal Debug MCP extension gives Claude 16 VS Code debugger tools, and every action the agent takes is visible in the editor. In 15 minutes, the agent tuned the PID coefficients (the motor controller settings) on its own and spotted a badly assembled motor. For embedded work, it is better to give the agent your debugger than a separate gdb.  - 16 tools: breakpoints, stepping, FreeRTOS stack, RTT logs - A single Node.js file with no npm dependencies, works with any DAP adapter - No authentication: it listens only on 127.0.0.1, do not expose it externally

AI assistants write code reasonably well, but problems start as soon as the work reaches a real board. Take the STM32 microcontroller: it is a widespread family of chips that control motors, sensors, and other hardware. Normally, an agent quietly starts a gdb server (the program used to debug firmware), checks and changes something, and then you reread the logs and try to figure out what it did. The author of the Bare Metal Debug MCP extension solved this differently: the agent works in the same debug session as the human, directly in VS Code. MCP (Model Context Protocol) is an open protocol from Anthropic through which an agent receives a list of tools and calls them like ordinary functions. The extension has 16 such tools, and with them Claude tuned the PID coefficients on its own in 15 minutes. These are the numbers that determine how smoothly and precisely a motor holds the required speed.

## One Session for Two

The author borrowed the idea from SiLabs, who built an extension that exposes VS Code's built-in debugger as an MCP server. The author generalized the approach: his extension works with any DAP adapter (the standard "bridge" between the editor and the debugger) installed in VS Code, not only with one vendor's chips.

In practice, it looks like this. The agent sets a breakpoint, and it appears in the gutter to the left of the code. The program stops on that line, and variable values are visible in the VARIABLES panel. A human can set a breakpoint at any moment, and the agent will continue from there. In addition, the extension mirrors SEGGER RTT data (the firmware's log and command channel) into the Output panel, so you see both the logs and the commands the agent sends to the device.

The architecture is simple: the agent connects to the extension over MCP (Streamable HTTP on localhost), and the extension works with any installed debugger through the vscode.debug API and raw DAP. All 16 tools cover the standard debugging cycle: starting and stopping a session, pause, continue, stepping, breakpoints (including conditional breakpoints and logpoints), the call stack with FreeRTOS tasks, viewing, evaluating, and writing variables, plus three RTT commands. The code itself is a single file in plain Node.js with no npm dependencies.

## Why Not Plain gdb

The author compared his approach with two similar projects: gdb-mcp (a wrapper around GDB/LLDB) and embedded-debugger-mcp (a Rust server built on probe-rs or OpenOCD). Both share three drawbacks.

- Double ownership of the probe. If the agent starts its own gdb server, your debugger in the editor stops working: there is only one J-Link probe.
- Reinventing the ecosystem. Cortex-debug already shows RTOS stacks, peripherals via SVD, flashing, and RTT reading. A separate server has to be taught all of this again.
- No transparency. The agent works "in the dark," and its actions must be reconstructed from logs.

The practical conclusion: the agent does not need to deploy its own debugging stack; it uses what is already configured in the project. Plus, one shared session means fewer conflicts over the single probe.

## Example: PID in 15 Minutes

The author's most illustrative case is tuning PID coefficients for motor drivers. The job is tedious: change a number, run, look, repeat. The author added several commands to the RTT console for controlling the drivers and told the agent: "Tune the PID coefficients."

Over the next 15 minutes, the agent changed the parameters itself, ran the motors, checked the result, and adjusted the values. It not only found suitable coefficients but also noticed that one motor behaved differently under the same settings. The agent suspected a wiring defect, and this was confirmed. If the coefficients resided in RAM, it could change them directly in memory without reflashing the driver configuration.

## Limitations

The author honestly lists the drawbacks:

- No authentication. The server listens only on 127.0.0.1 but has no token, so it must not be exposed externally. The agent does support a remote gdb server; you just need to specify its IP.
- RTT works out of the box only for J-Link (port 19021). For OpenOCD and Black Magic Probe, the port is connected manually via debug_rtt_connect.
- One VS Code window means one port (from the range 7800–7899, stable for the project). The scenario of "many agents in one window" is not supported.
- There are no watchpoints or "edit and continue": the author has not needed them yet.

## How to Try It

The extension is available in the VS Code Marketplace. For Claude Code, it is enough to place a .mcp.json file in the project root with the address http://127.0.0.1:7819/mcp. The extension creates this file itself, but it is worth adding it to .gitignore. Then you open the project, connect the probe, and tell the agent: "debug why X." It checks the status itself, launches the configuration, and sets breakpoints, while you see the same things in your own editor. For embedded work, this is a noticeable step from "the agent writes code" to "the agent works through the hardware in front of you."

---
- **Первоисточник:** [Habr AI](https://habr.com/ru/articles/1114064/?utm_campaign=1114064&utm_source=habrahabr&utm_medium=rss)
- **Каноническая ссылка:** https://news.hamidun.com/en/news/18706
- **Экосистема автора:** [Бесплатный интенсив по вайбкодингу — предзапись в Нике](https://t.me/vibecodeguidebot?start=agent_intensive_news_md) · [Nomad AI](https://nomadnet.ai) · [Telegram @jemal_hamidun](https://t.me/jemal_hamidun)
