Free · Daily brief + weekly playbookDaily 60-sec AI Voice Brief + Weekly Production AI Agent PlaybookGet the brief →
ReleaseCode / SDK · ActionableHabr AI→ original

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

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.

AI-processed from Habr AI; edited by Hamidun News
Claude debugs an STM32 microcontroller in VS Code and tunes motor PID in 15 minutes
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
16 toolsbreakpoints, stepping, FreeRTOS stack, RTT logs
Key metric #2A single Node.js file with no npm dependencies, works with any DAP adapter
No authenticationit 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."

Story

Key Questions Answered

What are the key details on 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.

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.

What are the key details on 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.

ZK
Zhemal Khamidun — Head of AI at Alpina Digital · MIPT (academic supervisor of the Tech Entrepreneurship department). Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Free · Waitlist · Hermes + DeepSeek

Free 2-Day Vibecoding & AI Agents Intensive

Day 1: the autonomous Hermes + DeepSeek AI agent — vibecoding and development on par with Claude Code / Codex / Gemini. Led by Jemal Hamidun, Head of AI at Alpina Digital and academic supervisor at MIPT. Right after you register with our bot Nika: the recording + 11 materials from the previous intensive.

Join the waitlist →Nomad AI Workspace
Jemal Hamidun

Editor-in-chief · Cite this analysis

Jemal Hamidun

Head of AI at Alpina Digital · Academic Supervisor of the Tech Entrepreneurship Department at MIPT

Head of AI & CPO of AlpinaGPT at Alpina Digital, Academic Lead of Tech Entrepreneurship at MIPT. Founder of Hamidun News and Vibe Academy.

Ready-to-paste citation for journalists, blogs and Telegram channels

Source: Hamidun News — Claude debugs an STM32 microcontroller in VS Code and tunes motor PID in 15 minutes https://news.hamidun.com/en/news/18706/claude-debugs-an-stm32-microcontroller-in-vs-code-and-tunes

What do you think?
Loading comments…