Embedded Garage

ISO-TP flow control and STmin timing in practice

The standard gives you one byte to set the pacing between consecutive frames. Getting it wrong does not raise an error. It makes multi-frame transfers flaky in a way that is easy to blame on something else.

By Sanket S. Shahane. All notes

Where STmin lives

ISO 15765-2 (ISO-TP) splits any payload larger than a single CAN frame into a First Frame (FF) followed by Consecutive Frames (CF). Before the sender can push out those consecutive frames, the receiver replies with a Flow Control (FC) frame that carries three fields: FS (flow status — clear to send, wait, or overflow), BS (block size — how many consecutive frames to send before waiting for another FC), and STmin (separation time minimum — the minimum gap the sender must leave between consecutive frames).

STmin is the field that causes the most field failures, because it's the one field where "technically spec-compliant" and "actually works with this ECU" can disagree.

How STmin is encoded

STmin is a single byte, and the spec splits its range into two encodings:

Byte valueMeaning
0x00No minimum separation time (send back-to-back)
0x01–0x7F1–127 ms, in 1 ms steps
0x80–0xF0Reserved — not valid
0xF1–0xF9100–900 μs, in 100 μs steps
0xFA–0xFFReserved — not valid

Two things go wrong here regularly. First, some stacks receive a reserved value — usually from a corrupted or misinterpreted FC frame — and instead of rejecting it per spec, silently clamp or ignore it, which hides a real bus problem. Second, the sub-millisecond range (0xF1–0xF9) requires timer resolution most bit-banged or loosely-scheduled implementations don't actually have, so a receiver that legitimately needs 500 μs spacing gets frames closer together than it asked for.

What "ignoring STmin" looks like in practice

An ECU that can't keep up with the requested pacing doesn't usually reject the transfer outright. What you see instead is one of:

  • Consecutive frames arriving out of the expected sequence number order, because the receiver's buffer state fell behind
  • A transfer that works reliably at low bus load and fails intermittently once other CAN traffic is competing for arbitration
  • A receiver sending an FC overflow (FS = 0x2) mid-transfer instead of at the start, because internal buffering assumed the sender would honor STmin exactly and it didn't

None of these produce an error code that points at STmin. They look like a flaky bus, a buffer bug, or a timing-dependent heisenbug — which is exactly why this is worth writing down.

Pacing consecutive frames correctly

The practical fix is straightforward once you know where to look: don't just delay by STmin — decode it correctly, and give yourself margin against your own scheduler jitter rather than the spec's bare minimum.

/**
 * @brief  Decode an ISO 15765-2 STmin byte into microseconds.
 * @param  stmin  Raw STmin byte from a Flow Control frame.
 * @return Separation time in microseconds. A reserved value returns the
 *         largest defined time, so the sender fails slow, never fast.
 */
static uint32_t eg_isotp_stmin_to_us(uint8_t stmin)
{
    uint32_t time_us;                              /* Result, in microseconds. */

    if (stmin <= 0x7FU)                            /* 0x00 to 0x7F: 0 to 127 ms in 1 ms steps. */
    {
        time_us = (uint32_t)stmin * 1000UL;        /* Milliseconds to microseconds. */
    }
    else if ((stmin >= 0xF1U) && (stmin <= 0xF9U))  /* 0xF1 to 0xF9: 100 to 900 us in 100 us steps. */
    {
        time_us = ((uint32_t)stmin - 0xF0UL) * 100UL;   /* Step count times 100 us. */
    }
    else                                           /* Reserved value: not valid on the wire. */
    {
        time_us = 127000UL;                        /* Fall back to the longest defined time. */
    }

    return time_us;                                /* Single exit point, as MISRA C prefers. */
}

Falling back to the largest defined value on a reserved byte — rather than 0, and rather than silently accepting whatever was received — is a deliberate choice: it fails toward "too slow, but correct," which is recoverable, instead of "too fast," which is what actually corrupts a transfer.

The margin question

The spec defines STmin as a minimum, which means a sender is always allowed to wait longer. On a bare-metal or lightly-loaded RTOS system, sending exactly at the requested STmin using a busy-wait can work. On a system where the CAN send call is dispatched from a task that can be preempted, timer jitter of even a few hundred microseconds against a tight STmin will occasionally violate it. In practice, adding a small fixed margin — a few hundred microseconds — above the decoded STmin before triggering the next consecutive frame costs almost nothing in throughput and removes an entire category of intermittent failure that's expensive to reproduce on a bench.

Takeaway

STmin timing bugs don't announce themselves. They show up as "it works on my bench but not in the vehicle," or "it fails once every few hundred transfers." If a multi-frame UDS exchange is flaky in a way that correlates with bus load or transfer size rather than a specific service ID, decode the FC frame's STmin field on a bus trace before looking anywhere else.