Skip to content
Eliott65Sondewiki
Contents

CMSIS-DAP over the network

OpenOCD can already send its CMSIS-DAP commands over the network. The probe only had to understand them: that is the job of its CMSIS-DAP processor, written for the project.

The transport

OpenOCD’s CMSIS-DAP over TCP module puts an 8-byte header in front of each command: a signature (“DAP”), the length, the type (request or response) and a reserved byte, little-endian. A command carries at most 1,024 bytes, and the default port is 4441.

OpenOCD asks the probe how many commands it accepts in advance, then chains them without waiting for each response. This is valuable over Wi-Fi: the network latency is partly hidden. The probe accepts 8 in advance, and only produces a response when there is room for it in the transmit buffer.

The CMSIS-DAP processor

The heart of the probe is a CMSIS-DAP processor written for the project, in portable C. It only knows SWD at the transfer level (“read this register”, “write this register”), so it runs on the Pico W as well as on the PC.

  • The commands implemented are those OpenOCD uses, taken from its code: information, connect and disconnect, transfer configuration, single and block transfers, abort, delays, target reset, pins, clock, SWD sequences.
  • The RP2040’s core selection: the RP2040 has two cores behind a single “multidrop” debug port. OpenOCD picks the core with a particular SWD sequence, which the probe passes on as is.
  • The details that matter: posted reads (a read’s value arrives with the next one), checking the last write, retrying when the target answers “wait” (WAIT), value matching, blocks split to the size of a packet.

The simulated target

To try without hardware, the repository contains a simulated target: the RP2040’s debug port with its two cores (silent until one is selected), its power-up, its memory access and 64 KiB of RAM. A TCP server on the PC presents it as a probe.

The real OpenOCD connects to it, reads the RP2040’s identifier, examines the target, writes and reads back words, bytes, half-words and a 4 KiB block.

A precaution on the OpenOCD side

In the development version of OpenOCD used, the TCP module’s default port is not replaced by its value: OpenOCD tries the text CMSIS_DAP_TCP_PORT. So always give cmsis-dap tcp port 4441. See How to use it.

Sources in the repository : docs/adr/ADR-0001-cmsis-dap-par-tcp.md, docs/journal/01-cmsis-dap-tcp.md.