OpenOCD (Open On-Chip Debugger) connects a host computer to a microcontroller through a hardware debug probe. It supports firmware flashing and interactive debugging over SWD or JTAG, including reset, halt, resume, single-stepping, breakpoints, and memory access. section 2.5.2 section 6.5.5
In a GDB session, OpenOCD acts as the GDB server. GDB communicates with it over a TCP socket using the remote serial protocol; OpenOCD communicates with the probe over USB, and the probe drives the target’s debug lines. section 6.5.5
To set up a basic session:
- Install OpenOCD using your platform’s package manager. On Windows, use the official binaries or install it through WSL. section 2.5.2
- Create an openocd.cfg file identifying both the probe interface and the target chip. Shipped configurations are in the installation’s scripts/interface and scripts/target directories; their location varies by platform. section 2.5.2 section 6.5.5
- Run openocd from the configuration file’s directory. Its GDB server listens on port 3333; connect from GDB with target extended-remote :3333. section 6.5.5
source [find interface/stlink.cfg] source [find target/stm32f1x.cfg]
This minimal configuration selects an ST-Link probe and an STM32F1 target. Older OpenOCD releases used separate ST-Link variant files; current versions use stlink.cfg with auto-detection. section 6.5.5
openocd -f openocd.cfg -c "program target/thumbv7m-none-eabi/release/ your_project verify reset exit"
This example programs a built firmware image, verifies it, resets the target, and exits. Replace the image path with the firmware to flash. section 2.5.2
GDB with OpenOCD offers detailed, hardware-specific investigation but involves more explicit setup and manual steps. A probe-rs and defmt workflow favors faster iterations and compact logging, with less emphasis on deep hardware analysis. section 2.6.5
