UDS diagnostics
The drive uses UDS (ISO 14229) over ISO-TP (ISO 15765-2) for identity, settings, fault codes, calibration and firmware updates. This page covers the transport, the services and sessions, how to read identity and fault codes, and what negative responses mean. Service IDs and frame formats here are from the standards. The drive's CAN IDs, data identifiers and fault codes are not defined yet.
Status
| Item | Value |
|---|---|
| Request CAN ID (host to drive) | TBD |
| Response CAN ID (drive to host) | TBD |
| Functional (all drives) request CAN ID | TBD |
| ISO-TP frame length and padding | TBD |
| Supported services | TBD |
| Data identifiers (DIDs) | TBD |
| Security access levels and algorithm | TBD |
| Diagnostic trouble codes (DTCs) | TBD |
ISO-TP transport
A UDS message can be longer than one CAN frame. ISO-TP splits it into frames on the sending side and joins them on the receiving side. The high nibble of the first data byte gives the frame type.
| High nibble | Frame type | Content |
|---|---|---|
| 0 | Single frame | The whole message. In a frame of up to 8 bytes, the low nibble is the length (1 to 7). In a CAN FD frame longer than 8 bytes, byte 0 is 0x00 and byte 1 is the length (up to 62). |
| 1 | First frame | Start of a longer message, with its total length. |
| 2 | Consecutive frame | The next part, with a 4-bit sequence number. |
| 3 | Flow control | Sent by the receiver after a first frame: continue, wait or overflow, plus block size and minimum gap between frames (STmin). |
A request that fits in one frame can be sent with cansend. This reads DID 0xF18C, which ISO 14229-1 defines as the ECU serial number. Whether the drive uses this DID is TBD.
cansend can0 <request-id>#0322F18C
03 is the single-frame length, 22 the service, F18C the DID. If the drive requires padded 8-byte frames (TBD), add filler bytes after the request.
If the response is longer than 7 bytes, the drive sends a first frame and waits for flow control, which cansend cannot send. Use the Python example below. To watch ISO-TP traffic decoded, use:
isotpdump -s <request-id> -d <response-id> can0
Services
A positive response repeats the service ID plus 0x40. A negative response is 7F <service ID> <negative response code>.
| Service ID | Service | Positive response | Function |
|---|---|---|---|
| 0x10 | DiagnosticSessionControl | 0x50 | Change session |
| 0x11 | ECUReset | 0x51 | Restart the drive |
| 0x14 | ClearDiagnosticInformation | 0x54 | Clear stored fault codes |
| 0x19 | ReadDTCInformation | 0x59 | Read fault codes |
| 0x22 | ReadDataByIdentifier | 0x62 | Read identity, settings, health, calibration |
| 0x27 | SecurityAccess | 0x67 | Unlock protected services (seed and key) |
| 0x2E | WriteDataByIdentifier | 0x6E | Write settings |
| 0x31 | RoutineControl | 0x71 | Start, stop or get the result of a routine |
| 0x34 | RequestDownload | 0x74 | Start a firmware download |
| 0x36 | TransferData | 0x76 | Send one block of the download |
| 0x37 | RequestTransferExit | 0x77 | End the download |
| 0x3E | TesterPresent | 0x7E | Keep a non-default session open |
The drive uses DiagnosticSessionControl (0x10) and ECUReset (0x11) to restart into its bootloader for a firmware update; see Firmware updates. For the other functions the table gives the standard ISO 14229-1 service. The drive's list of supported services is TBD.
Sessions
| 0x10 sub-function | Session | Use |
|---|---|---|
| 0x01 | Default | Normal operation. The drive starts in this session. |
| 0x02 | Programming | Firmware updates. |
| 0x03 | Extended diagnostic | Settings and routines. |
Which services each session allows on the drive is TBD.
The positive response to 0x10 carries the drive's response timing:
request: 10 03
response: 50 03 <P2 high> <P2 low> <P2* high> <P2* low>
P2 is the normal response time in ms. P2* is the extended time after a "response pending" (NRC 0x78), in units of 10 ms. The drive's values are TBD.
A non-default session ends by itself if no request arrives for 5 s (S3 server timeout, ISO 14229-2). To keep it open, send TesterPresent with the suppress-positive-response bit set, about every 2 s:
cansend can0 <request-id>#023E80
Read identity and fault codes
The drive reports its serial number, hardware revision and firmware version, and its health (load, temperature and faults). ISO 14229-1 defines identifiers for some of these; whether the drive uses them is TBD.
| Item | Drive DID | ISO 14229-1 identifier |
|---|---|---|
| Serial number | TBD | 0xF18C ECU serial number |
| Hardware revision | TBD | 0xF193 system supplier ECU hardware version number |
| Firmware version | TBD | 0xF195 system supplier ECU software version number |
| Load | TBD | — |
| Temperature | TBD | — |
This script opens an extended session, reads the DIDs you pass, reads all stored fault codes and returns to the default session. It uses python-can, python-can-isotp and udsoncan (see Getting started for installation).
import sys
import can
import isotp
import udsoncan
import udsoncan.configs
from udsoncan.client import Client
from udsoncan.connections import PythonIsoTpConnection
from udsoncan.services import DiagnosticSessionControl
request_id = int(sys.argv[1], 0) # CAN ID the host sends on: TBD
response_id = int(sys.argv[2], 0) # CAN ID the drive answers on: TBD
dids = [int(d, 0) for d in sys.argv[3:]] # data identifiers to read: TBD
class RawCodec(udsoncan.DidCodec):
"""Return a data record as bytes, whatever its length."""
def encode(self, value):
return bytes(value)
def decode(self, payload):
return payload
def __len__(self):
raise udsoncan.DidCodec.ReadAllRemainingData
bus = can.Bus(interface="socketcan", channel="can0", fd=True)
notifier = can.Notifier(bus, [])
address = isotp.Address(isotp.AddressingMode.Normal_11bits, txid=request_id, rxid=response_id)
params = {"can_fd": True, "bitrate_switch": True, "tx_data_length": 64} # drive values TBD
stack = isotp.NotifierBasedCanStack(bus, notifier, address=address, params=params)
config = dict(udsoncan.configs.default_client_config)
config["data_identifiers"] = {did: RawCodec for did in dids}
try:
with Client(PythonIsoTpConnection(stack), config=config, request_timeout=2) as client:
client.change_session(DiagnosticSessionControl.Session.extendedDiagnosticSession)
for did in dids:
value = client.read_data_by_identifier(did).service_data.values[did]
print(f"DID 0x{did:04X}: {value.hex(' ')}")
for dtc in client.get_dtc_by_status_mask(0xFF).service_data.dtcs:
print(f"DTC 0x{dtc.id:06X} status 0x{dtc.status.get_byte_as_int():02X}")
client.change_session(DiagnosticSessionControl.Session.defaultSession)
finally:
notifier.stop()
bus.shutdown()
Run it with the drive's CAN IDs and the DIDs to read:
python3 uds_read.py <request-id> <response-id> <DID TBD> [<DID TBD> ...]
On a classic CAN bus, set params = {"tx_data_length": 8} and open the bus without fd=True.
Fault code format
19 02 FF (report DTCs by status mask, mask 0xFF) returns 59 02 <availability mask>, then 4 bytes per fault code: a 3-byte DTC and its status byte.
| Status bit | Meaning |
|---|---|
| 0 | testFailed: the fault is present now |
| 1 | testFailedThisOperationCycle |
| 2 | pendingDTC |
| 3 | confirmedDTC: the fault is stored |
| 4 | testNotCompletedSinceLastClear |
| 5 | testFailedSinceLastClear |
| 6 | testNotCompletedThisOperationCycle |
| 7 | warningIndicatorRequested |
To clear all stored fault codes, send 14 FF FF FF. The drive's DTC list is TBD; Troubleshooting will list it.
Write settings and read calibration
Settings are written with WriteDataByIdentifier (0x2E), usually in the extended session and after SecurityAccess (0x27). Calibration is readable over UDS. The DIDs, the session each needs and the security level are TBD. See Configuration and Calibration.
Negative response codes
| NRC | Name | What to do |
|---|---|---|
| 0x10 | generalReject | Retry. If it repeats, read the fault codes. |
| 0x11 | serviceNotSupported | The drive does not support this service. |
| 0x12 | subFunctionNotSupported | Check the sub-function byte. |
| 0x13 | incorrectMessageLengthOrInvalidFormat | Check the request length and the DID data length. |
| 0x22 | conditionsNotCorrect | The drive is not in a state that allows the request. |
| 0x24 | requestSequenceError | Send the services in the required order. |
| 0x31 | requestOutOfRange | Check the DID, routine ID or value. |
| 0x33 | securityAccessDenied | Unlock with SecurityAccess (0x27) first. |
| 0x35 | invalidKey | The key does not match the seed. |
| 0x36 | exceedNumberOfAttempts | Too many wrong keys. Wait, then request a new seed. |
| 0x37 | requiredTimeDelayNotExpired | Wait before the next SecurityAccess attempt. |
| 0x70 | uploadDownloadNotAccepted | The drive refused the download request. |
| 0x72 | generalProgrammingFailure | Writing to memory failed. |
| 0x73 | wrongBlockSequenceCounter | A TransferData block was lost or repeated. |
| 0x78 | requestCorrectlyReceived-ResponsePending | Keep waiting, up to P2*. udsoncan does this for you. |
| 0x7E | subFunctionNotSupportedInActiveSession | Change session first. |
| 0x7F | serviceNotSupportedInActiveSession | Change session first. |
Which NRC the drive returns in each case is TBD.