oss

OpenOCD carries the debugger's instructions to the chip

4 sources 0 primary sources November 17, 2026

Loading reads and saves…
Text

A microcontroller can go silent before it has printed a single useful message. To investigate, a developer needs another route into the chip: a connection that can inspect memory and stop execution without relying on the application's own logging. OpenOCD, the Open On-Chip Debugger, supplies the software link between a host computer and that hardware debugging route. Following a command through its configuration files, debug adapter, and target support explains what a successful connection actually establishes.[1]

The STM32F3DISCOVERY makes this arrangement unusually visible. Its circuit board carries both the microcontroller running the application and a second microcontroller belonging to the built-in ST-LINK programmer/debugger. The two USB connectors have different jobs: the one marked USB ST-LINK reaches the debugging side; USB USER connects to the application microcontroller.[2]

STM32F3DISCOVERY development board with its USB connectors, microcontrollers, pin headers, and ring of user LEDs.
The STM32F3DISCOVERY carries the application microcontroller and its ST-LINK programmer/debugger on one board. Photograph from the Embedded Rust Book's hardware introduction.[2]

Three configuration files describe three different things

On the computer, GDB handles the debugging conversation with the programmer. OpenOCD presents a server that GDB can talk to, then uses a debug adapter to reach the chip's debug hardware. The adapter may be a separate box or, as on the Discovery, part of the development board. JTAG and SWD are possible transports on the hardware side of that connection.[1]

OpenOCD's configuration directories follow these separate responsibilities. An interface/ file describes the adapter. A target/ file describes the chip and the debug targets it contains. A board/ file brings those pieces together with details belonging to the circuit board, such as external memory and initialization. The same processor can appear on boards whose memory wiring and startup requirements differ.[1]

The project's STM32F3DISCOVERY board file in release 0.12.0 is short enough to follow directly. It loads interface/stlink.cfg, selects hla_swd, loads target/stm32f3x.cfg, and sets reset_config srst_only. Those lines choose an adapter configuration, a transport through that adapter, a chip configuration, and a reset arrangement.[3]

This division helps locate a failure. Recognizing the USB adapter establishes one part of the path; it does not establish that the selected chip configuration or board reset wiring is correct. Treating every connection problem as a missing host driver skips the other parts described by the configuration.

The examples here follow that release's board file and manual. A different board, hardware revision, or adapter needs its corresponding configuration; the filenames are part of the hardware description.

The executable on the computer and the program in flash

For the supported Discovery setup, OpenOCD can be started with:

openocd -f board/stm32f3discovery.cfg

A target-aware GDB, such as arm-none-eabi-gdb, can then connect with target extended-remote localhost:3333. GDB speaks its remote debugging protocol to OpenOCD on the host; OpenOCD handles the route onward to the board.[1]

There is an easily missed distinction here. Starting GDB with firmware.elf, or issuing file firmware.elf, gives GDB the executable and its symbol information on the computer. That lets it associate addresses with functions and source locations. Reading this file does not, by itself, install those bytes in the microcontroller.[4]

The command load performs the transfer to target memory. Whether a program section belongs in RAM or flash depends on its destination address. With valid flash-bank configuration, OpenOCD supplies a memory map; GDB uses that map to select its flash-programming protocol for flash regions. info mem exposes the map that GDB is using.[1]

Consider the consequence of rebuilding a program and opening the new ELF while leaving an older build on the board. The host's account of the program and the target's contents can disagree. A familiar function name in the debugger is therefore insufficient evidence that the intended firmware was programmed. This follows from the separation between file selection and target loading.[1][4]

The Embedded Rust Book demonstrates the distinction on this same board: it starts OpenOCD, opens the compiled program in GDB, connects, and explicitly issues load. Its separate compilation settings and memory layout also show how much has already been decided before OpenOCD receives the first programming request.[2]

Reset has a job of its own

Stopping execution and restarting the machine introduce another set of operations. OpenOCD distinguishes reset halt, which resets and halts the target, from reset init, which also runs the configured initialization sequence. reset run resets and allows execution to proceed. Their availability and behavior depend on the hardware and reset configuration.[1]

Inside GDB, the monitor command passes an instruction to OpenOCD. Thus monitor reset halt crosses the software boundary explicitly: GDB forwards the request, and OpenOCD performs the target operation. A halted processor can then be examined without assuming it has reached the application's normal startup state.[1]

Initialization matters because the debugger may arrive before the application's boot code has prepared the board. OpenOCD's configuration guide assigns board-specific memory and clock setup to reset initialization handlers. A connection to the processor and usable external memory are separate achievements.[1]

For a prepared STM32F3DISCOVERY firmware image, the manual combines the programming sequence into one shell command:

openocd -f board/stm32f3discovery.cfg \
  -c "program firmware.elf verify reset exit"

The command changes the board's firmware. Its sequence initializes OpenOCD, resets and prepares the target, erases and writes the relevant flash, performs the requested verification, resets into execution, and closes OpenOCD. The optional words describe distinct stages. Omitting verify removes that verification step; omitting reset removes the requested final reset into execution.[1]

Verification compares the programmed image with what was supplied. It does not establish that the application will behave correctly after startup. A successfully written image can still contain an application bug; that is when the ability to halt, inspect, and step becomes useful again.

The practical value of this architecture is that a silent board can be approached in stages. The adapter can be identified, the target reached, the intended image written, and execution examined. Each result answers a narrower question than “does debugging work?” On the Discovery, the little controller beside the USB cable is the physical reminder: even when the application stops talking, there is another participant available to carry the conversation.

Sources

  1. OpenOCD, User’s Guide, release 0.12.0 — project purpose and adapters, configuration responsibilities, GDB connections and programming, target-state commands, and the flash-programming sequence
  2. The Embedded Rust Book — the hardware introduction and photograph, and an independent worked example of compilation, memory layout, and debugging with OpenOCD and GDB
  3. OpenOCD source repository, stm32f3discovery.cfg, tag v0.12.0 — the board configuration used in this article.
  4. GNU GDB manual, “Commands to Specify Files” — executable and symbol-file selection on the host.
Previous TurtleStitch makes a small program worth wearing Next How to write a comma with four fingers

Recommended In oss

Matched by subject and format