Embedded Garage

Firmware and protocols

Bare-metal first, an RTOS when the problem needs one, and protocol stacks written from the standard, so I know what every byte on the wire means.

How I write firmware

  • Bare-metal by default. FreeRTOS when the job has real concurrency.
  • Static allocation only. No heap, so memory use is known at build time.
  • MISRA C:2023 as the coding standard.
  • Protocol stacks written from the published standards instead of vendor middleware.
  • Every protocol implementation checked on the bench, frame by frame, against live bus traffic.
  • A design document, a test procedure and a user manual for each product, so requirements, code and tests can be traced to each other.

Standards I work to

ProtocolStandard
Classical CAN and CAN FDISO 11898-1
ISO-TP transport layerISO 15765-2:2016
UDS diagnosticsISO 14229-1:2020
Modbus RTU and Modbus TCPThe Modbus Organization specifications

UDS services

Diagnostic services I have implemented, on both the tester side and the ECU side of a link. Security Access has its own note: UDS SecurityAccess (0x27), byte by byte.

ServiceName
0x10Diagnostic Session Control
0x11ECU Reset
0x19Read DTC Information
0x22Read Data By Identifier
0x27Security Access
0x2EWrite Data By Identifier
0x2FInput Output Control By Identifier
0x34 to 0x37Request Download, Transfer Data and Request Transfer Exit
0x3ETester Present

ISO-TP on the wire

A CAN frame carries 8 bytes. ISO-TP is how a longer message is split across several frames and put back together. Move the slider to see the frames for any payload length.

20 bytes
    • Sent by the sender
    • Sent by the receiver
    Classical CAN with 8 data bytes and normal addressing. The payload bytes are numbered 00, 01, 02 and so on, so you can follow each one into its frame. Unused bytes are padded with 00 here. The padding value is set by each network, and short frames such as the Flow Control can also be sent without padding.

    The Flow Control frame also sets the pacing between frames. That is covered in the note ISO-TP flow control and STmin timing in practice.

    Platforms

    • STM32 F1, F4 and H7, with STM32CubeIDE and Keil.
    • ESP32 with ESP-IDF and FreeRTOS.
    • PIC16F877A and ATmega328P for smaller jobs.
    • Debugging over JTAG and SWD, with an oscilloscope on the bus.