Post · 3 min read· pp. 56–58

USB Debug

PIC16 based legacy protocol

The PIC16-based USB Debug board exposes the CAN bus to a host computer as a USB CDC ACM virtual serial port. The host and board exchange a line-oriented ASCII protocol over the port.

Note

The CDC ACM line settings (baud rate, parity, stop bits) are ignored by the board. Data travels over USB bulk endpoints, so any valid line coding may be used.

Host to Device Commands

Commands are ASCII, case-insensitive, and terminated with a semicolon (;). Multiple commands may be concatenated in one write, and a command may be split across USB packets.

CommandDescription
M<sid>[,<byte>...];Transmit a CAN frame on the bus.
G<level>;Set the maximum debug level (0–5).
S<state>;Enable (1) or disable (0) sensor messages.
L;Report the current debug and sensor-message configuration.

Send a CAN Frame

M is followed by the CAN identifier and zero or more data bytes, separated by commas, and terminated with ;.

  • The identifier is 1–8 hexadecimal digits and is interpreted as a 29-bit CAN identifier.
  • Each data byte is 1–2 hexadecimal digits.
  • Up to 8 data bytes may be sent.
  • Lowercase letters are accepted.

Examples:

default
M7EF;                            # identifier 0x7EF, no data
M777,01,02,03,04,05,06,07,08;    # identifier 0x777, 8 data bytes
MFF,AA,BB;                       # identifier 0xFF, 2 data bytes
m7Ab,cD,Ef;                      # mixed case

Set Debug Level and Sensor Messages

G<level>; sets the maximum debug level, where level is 0 through 5. S<state>; sets whether sensor messages are enabled, where state is 0 (disabled) or 1 (enabled). The current firmware stores and reports these settings but does not use them to filter messages sent to the host.

Read Configuration

L; causes the board to send the current configuration back to the host (see Device to Host Messages).

Device to Host Messages

The board sends ASCII text. Every transfer is terminated with a NUL byte (0x00) on the wire because the CDC driver includes the string terminator in the transfer. Host software should strip the NUL before parsing.

Startup Banner

After initialization the board sends:

default
Finished CAN setup. Waiting for messages.\n\r\0

Received CAN Frames

Each CAN frame received from the bus is reported on its own line:

default
$<SID>:<byte>,<byte>,...,<byte>\n\r\0
  • $ marks the start of a valid CAN frame.
  • <SID> is the identifier as exactly 8 uppercase hexadecimal digits, zero-padded. Received frames are always decoded as 29-bit extended identifiers; the board does not check or report the standard/extended flag.
  • Data bytes are uppercase hexadecimal and comma-separated, with no trailing comma.
  • The line ends with LF, then CR, then NUL.
  • A frame with no data bytes is reported as $<SID>:\n\r\0, with no bytes after the colon.

Examples:

default
$00000123:\n\r\0
$00000123:AB,CD\n\r\0
$000007EF:01,02,03,04,05,06,07,08\n\r\0
$1ABCDEF0:00,11\n\r\0

The number of data bytes is implied by the number of comma-separated fields (zero fields for a frame with no data). Frames carry no timestamp, length field, or checksum.

Configuration Response

In response to L; the board sends:

default
Current Config: Max debug level = <level> & Sensor messages <are|are not> allowed!\r\n\0

Example:

default
Current Config: Max debug level = 0 & Sensor messages are allowed!\r\n\0

Note that this response ends with CR then LF, unlike received CAN frames.