| 1 | --- |
| 2 | title: Remote probe protocol |
| 3 | --- |
| 4 | |
| 5 | PyOCD provides a server and client for sharing and accessing debug probes across a TCP/IP |
| 6 | network connection. This document describes the protocol design, available commands, and semantics. |
| 7 | |
| 8 | Protocol |
| 9 | -------- |
| 10 | |
| 11 | The protocol is very simple. Each request from the client is a single line comprised of the |
| 12 | request encoded as JSON and followed by a single LF character (0x0A). The response from the server |
| 13 | is the same format, with a JSON encoded reply plus LF. |
| 14 | |
| 15 | A unique request ID is sent with every request. The response includes the ID of the request to |
| 16 | which it belongs. |
| 17 | |
| 18 | All requests are sent by the client. (A notification system from server to client may be added.) |
| 19 | |
| 20 | ### Request structure |
| 21 | |
| 22 | ``` |
| 23 | { |
| 24 | "id": <int>, |
| 25 | "request": <str>, |
| 26 | "arguments": [ |
| 27 | ] |
| 28 | } |
| 29 | ``` |
| 30 | |
| 31 | The `arguments` key is a list of any arguments for the command. It may be elided if there are no |
| 32 | arguments required. |
| 33 | |
| 34 | ### Response structure |
| 35 | |
| 36 | ``` |
| 37 | { |
| 38 | "id": <int>, |
| 39 | "status": <int>, |
| 40 | ["error": <str>,] |
| 41 | ["result": <value>] |
| 42 | } |
| 43 | ``` |
| 44 | |
| 45 | A successful response must have a `status` value of 0. A non-zero `status` indicates that an error |
| 46 | occurred, and must be accompanied by an `error` key with an error message (may be the empty string). |
| 47 | If the response is successful, then a `result` key may be included with the return value of the |
| 48 | command. If there is no return value, then `result` is excluded. |
| 49 | |
| 50 | Commands |
| 51 | -------- |
| 52 | |
| 53 | The commands in the table below correspond directly to the methods of `DebugProbe`. |
| 54 | |
| 55 | |
| 56 | Command | Arguments | Result |
| 57 | -------------------------|----------------------------------------------------|---------------- |
| 58 | `hello` | version:int | |
| 59 | `readprop` | | |
| 60 | `open` | | |
| 61 | `close` | | |
| 62 | `lock` | | |
| 63 | `unlock` | | |
| 64 | `connect` | protocol:str | |
| 65 | `disconnect` | | |
| 66 | `swj_sequence` | length:int, bits:int | |
| 67 | `set_clock` | freq:int | |
| 68 | `reset` | | |
| 69 | `assert_reset` | asserted:bool | |
| 70 | `is_reset_asserted` | | |
| 71 | `flush` | | |
| 72 | `read_dp` | addr:int | int |
| 73 | `write_dp` | addr:int, data:int | |
| 74 | `read_ap` | addr:int | int |
| 75 | `write_ap` | addr:int, data:int | |
| 76 | `read_ap_multiple` | addr:int, count:int | List[int] |
| 77 | `write_ap_multiple` | addr:int, data:List[int] | |
| 78 | `swo_start` | baudrate:int | |
| 79 | `swo_stop` | | |
| 80 | `swo_read` | | List[int] |
| 81 | `get_memory_interface_for_ap` | ap_address_version:int, ap_nominal_address:int | Option[int] |
| 82 | `read_mem` | handle:int, addr:int, xfer_size:int | int |
| 83 | `write_mem` | handle:int, addr:int, value:int, xfer_size:int | |
| 84 | `read_block32` | handle:int, addr:int, word_count:int | List[int] |
| 85 | `write_block32` | handle:int, addr:int, data:List[int] | |
| 86 | `read_block8` | handle:int, addr:int, word_count:int | List[int] |
| 87 | `write_block8` | handle:int, addr:int, data:List[int] | |
| 88 | |
| 89 | |
| 90 | Semantics |
| 91 | --------- |
| 92 | |
| 93 | The `hello` command includes the version of the remote probe protocol supported by the client. The |
| 94 | server will return an error if this version doesn't match the version of the protocol supported by |
| 95 | the server. |
| 96 | |
| 97 | Multiple clients may connect to a single remote probe. The server manages the requests to ensure |
| 98 | that the underlying probe is only opened and connected once. The first client to connect a probe |
| 99 | gets to choose the wire protocol (e.g., SWD or JTAG); subsequent connect are effectively ignored. |
| 100 | Counts of clients who have opened and connected the probe are maintained so it is disconnected |
| 101 | and closed when the last client disconnects and closes. |
| 102 | |
| 103 |