The Raspberry Pi and the motherboard’s STM32 communicate over a 2 Mbps UART link, using a custom frame protocol: the bridge (I would have liked to call it chromaping, though…).

The reference implementation lives in bridge.h & bridge.c on the firmware side, and motherboard_bridge.py on the Python side.

Overview

Two flows share the same link:

  • The state stream: at the end of each servo bus cycle (at 200 Hz), the STM32 sends a snapshot of the robot’s state ( STATE_SNAPSHOT) to the Raspberry Pi on its own.
  • Commands: the Raspberry Pi sends a frame, and the STM32 replies to it (or not, depending on the command received).
  sequenceDiagram
    participant RPi as Raspberry Pi
    participant MCU as STM32
    participant BUS as Servos

    Note over RPi,MCU: UART · 2 Mbps
    Note over MCU,BUS: Half-duplex TTL bus · 1 Mbps<br/>Bus cycle: 200 Hz

    RPi-)MCU: SET_POSITIONS
    MCU-)BUS: SYNC WRITE
    MCU->>BUS: SYNC READ
    BUS-->>MCU: Servo state
    MCU-)RPi: STATE_SNAPSHOT

Frame format

Instruction frames and returned frames share the same format:

SYNC_1SYNC_2LENGTHCMDPAYLOADCRC_LCRC_H
Value0x550xAAN + 1CodeDataCRC, low byteCRC, high byte
Size1 byte1 byte1 byte1 byteN bytes1 byte1 byte
  • SYNC_1 / SYNC_2 (header): the sync bytes 0x55 0xAA mark the start of a frame.
  • LENGTH: the number of bytes in CMD and PAYLOAD, i.e. len(payload) + 1. A zero length is invalid.
  • CMD: the command code in an instruction frame, or the response code in a returned frame.
  • PAYLOAD: the command-specific data, 0 bytes or more.
  • CRC: CRC-16 over the bytes from LENGTH to the end of PAYLOAD. It is sent low byte first.

A frame is therefore N + 6 bytes long. The firmware rejects incoming frames longer than 64 bytes. All multi-byte fields are little-endian.

CRC

The Cyclic Redundancy Check (CRC) is a value computed from the bytes of the frame. The sender appends it to the frame, and the receiver computes it again: if the two values differ, the frame was corrupted in transit, so it is ignored.

The computation amounts to dividing the frame’s bytes by a fixed number, the polynomial: the CRC is the remainder of that division. This protocol uses the CRC-16/CCITT-FALSE variant:

ParameterValueMeaning
Size16 bitsThe CRC fits in 2 bytes (CRC_L and CRC_H)
Polynomial0x1021The divisor, i.e. x¹⁶ + x¹² + x⁵ + 1
Initial value0xFFFFThe computation starts with all bits set to 1, so that 0x00 bytes at the start of the frame change the result

Example: PING_BRIDGE (0x01), no payload. The CRC is computed over 01 01 (the length, then the command) and equals 0x3E1F.

Instruction frame: 55 AA 01 01 1F 3E

SyncLengthCMDCRC
0x55 0xAA0x010x01 (PING_BRIDGE)0x1F 0x3E

Returned data frame: 55 AA 01 80 B6 BF. The STM32 acknowledges with OK; the CRC 0xBFB6 is computed over 01 80.

SyncLengthCMDCRC
0x55 0xAA0x010x80 (OK)0xB6 0xBF

Instruction types

CodeCommandPayloadResponse
0x01PING_BRIDGE—OK
0x02SET_POSITIONSTarget positions of the 12 servosNone (ERROR if the payload is too short)
0x03SET_TORQUEServo mask, torque statesNone (ERROR if the payload is too short)
0x04PING_SERVOServo IDOK / ERROR
0x06SET_SERVO_IDCurrent ID, new IDOK / ERROR
0x07SET_LED_COLORTarget, (LED index), R, G, B tripletOK / ERROR
0x08SET_LED_RING_BULKR, G, B triplet of the 18 LEDsOK / ERROR
0x0AWRITE_SERVO_REGISTERID, register, size, valueOK / ERROR
0x0BREAD_SERVO_REGISTERID, register, sizeSERVO_REG_VALUE / ERROR
0x0CGET_VERSION—VERSION

An unknown command code receives ERROR.

SET_POSITIONS and SET_TORQUE are not acknowledged: they are sent on every tick of the control loop, and their effect shows up in the next STATE_SNAPSHOT. The setpoints are queued and go out on the bus at the start of the next cycle.

PING_SERVO, SET_SERVO_ID, WRITE_SERVO_REGISTER and READ_SERVO_REGISTER are relayed onto the servo bus. They wait for the current cycle to finish and can take up to about 225 ms.

Response types

CodeNameMeaning
0x80OKCommand acknowledged
0x81ERRORUnknown, malformed or failed command. Empty payload
0x83STATE_SNAPSHOTRobot state, sent on every bus cycle
0x84SERVO_REG_VALUEReply to READ_SERVO_REGISTER: the register value
0x85VERSIONReply to GET_VERSION: protocol and firmware versions

Payload structures

SET_POSITIONS (0x02): 24 bytes.

FieldTypeNotes
positions[12]uint16Raw target position in steps (0 to 4095), in order of IDs 1 to 12

SET_TORQUE (0x03): 4 bytes.

FieldTypeNotes
maskuint16Servos affected: bit i stands for ID i + 1
onuint16Desired state for each: bit set, torque enabled; bit clear, torque released

SET_LED_COLOR (0x07):

TargetPayloadNotes
0x01 LED_RING_ALL0x01 R G BAll LEDs take the same color
0x02 LED_RING_SINGLE0x02 index R G BA single LED, index 0 to 17

SET_LED_RING_BULK (0x08): 54 bytes, 18 × (R, G, B).

SET_SERVO_ID (0x06): 2 bytes, the current ID then the new ID.

WRITE_SERVO_REGISTER (0x0A): 5 bytes.

FieldTypeNotes
servo_iduint8Target servo
registeruint8Address in the control table
sizeuint81 or 2
valueuint16Always 2 bytes; the high byte is ignored if size is 1

READ_SERVO_REGISTER (0x0B): 3 bytes (servo_id, register, size). The SERVO_REG_VALUE (0x84) reply contains size bytes.

VERSION (0x85): 4 bytes.

FieldTypeNotes
protocoluint8Bridge protocol version (2)
major, minor, patchuint8 × 3Firmware version

Example: GET_VERSION (0x0C) with firmware 2.0.0.

Instruction frame: 55 AA 01 0C B2 EF

Returned data frame: 55 AA 05 85 02 02 00 00 9E CF

SyncLengthCMDPayloadCRC
0x55 0xAA0x050x85 (VERSION)0x02 (protocol 2), 0x02 0x00 0x00 (firmware 2.0.0)0x9E 0xCF

Firmware older than 2.0.0 does not know this command. If the protocol version does not match the SDK’s, chromapi version and chromapi health report it: one of the two needs to be updated.

STATE_SNAPSHOT

STATE_SNAPSHOT (0x83) is 168 bytes:

FieldTypeNotes
sequint8+1 on every cycle. A gap on the Raspberry Pi side means a lost frame
t_usuint32STM32 time at the end of the servo read, in µs (wraps around about every 71 min)
cycle_usuint16Bus cycle duration, write and read, in µs
bus_uVint32Bus voltage, in µV
current_uAint32Current draw, in µA
power_uWint32Power, in µW
servos[12]12 × 10 bytesSee below
imu_acc[3]int16Accelerometer, in m/s² × 100
imu_gyro[3]int16Raw gyroscope, in rad/s × 1000
imu_gyro_corr[3]int16Gyroscope with bias corrected by the Mahony filter, in rad/s × 1000
imu_quat[4]int16Orientation quaternion (w, x, y, z) × 32767
switches_maskuint8Foot switches: bit 0 TL, bit 1 TR, bit 2 BL, bit 3 BR
servo_fresh_maskuint16Bit i set means the servo with ID i + 1 replied during this cycle

If a servo did not reply during the cycle, its servo_fresh_mask bit is 0 and its values are those of a previous cycle. The power measurement is refreshed at 10 Hz.

Each entry of servos[12], in order of IDs 1 to 12:

FieldTypeNotes
positionuint16Position in steps (0 to 4095)
speedint16Speed, in steps/s
loadint16Load, in 0.1% of rated torque
temperatureuint8Temperature, in °C
voltageuint8Voltage, in 0.1 V
currentint16Current, in units of 6.5 mA

Error handling

  • Invalid CRC: the frame is ignored on both sides, and the receiver resynchronizes on the next 0x55 0xAA bytes.
  • ERROR (0x81): the STM32 received a valid frame but could not execute it: unknown command, payload too short, LED index out of range or servo not responding.
  • Timeout: on the SDK side, a command with no reply after one second fails. Reading the state gives up after 50 ms without a STATE_SNAPSHOT.
  • Link loss: with no valid frame from the Raspberry Pi for 60 seconds, the STM32 drops the queued setpoints and releases the torque of all 12 servos. During a shorter silence, each servo keeps its last setpoint.

Servo bus protocol

Between the STM32 and the servos, the Feetech STS3215 protocol is used, on a 1 Mbps half-duplex TTL bus (see actuators). It works as question and answer: the STM32 sends an instruction packet, and only the servo with the matching ID replies. Full details are in the protocol manual and the STS3215 memory table of the stm32-sts3215-lib library.

Instruction packet

HeaderIDLengthInstructionParametersChecksum
0xFF 0xFFIDN + 2InstructionParam_1 ... Param_NChecksum
  • Header: two consecutive 0xFF mark the start of a packet.
  • ID: the servo address, from 0x00 to 0xFD. ID 0xFE addresses every servo on the bus (broadcast): none of them replies, except to a PING.
  • Length: the number of parameters N, plus 2 (instruction and checksum).
  • Checksum: ~(ID + Length + Instruction + Param_1 + ... + Param_N) & 0xFF. Its format and computation differ from the bridge CRC.

Two-byte values are sent low byte first.

Reply packet

HeaderIDLengthStatusParametersChecksum
0xFF 0xFFIDN + 2StatusParam_1 ... Param_NChecksum
  • Status: 0x00 if all is well. Otherwise, each bit flags a servo error (voltage, temperature, overload…).
  • Parameters: the data read, for a read instruction. Empty otherwise.

Instructions

CodeInstructionPurposeUsed by Chromapi
0x01PINGCheck that a servo respondsPING_SERVO, servo detection at startup
0x02READ DATARead from the memory tableREAD_SERVO_REGISTER
0x03WRITE DATAWrite to the memory table, taking effect immediatelyWRITE_SERVO_REGISTER, SET_SERVO_ID
0x04REG WRITEWrite without applying, until the next ACTION—
0x05ACTIONApply pending REG WRITEs—
0x06RESETRestore factory settings—
0x82SYNC READRead the same area from several servos in one requestReading the state of the 12 servos, every cycle
0x83SYNC WRITEWrite the same area to several servos in one packetSET_POSITIONS, SET_TORQUE

Registers used

Excerpt from the memory table: only the registers Chromapi reads or writes are listed. EEPROM registers are kept when powered off, provided the lock (0x37) was opened before writing them.

AddressRegisterBytesAreaUse
0x05ID1EEPROMBus identifier, from 1 to 12
0x0EMaximum voltage1EEPROM85, i.e. 8.5 V
0x0FMinimum voltage1EEPROM60, i.e. 6.0 V
0x13Unloading conditions1EEPROM44: protections enabled
0x15 / 0x16 / 0x17P, D, I coefficients1 eachEEPROM32, 0, 0
0x21Operating mode1EEPROM0: position control
0x28Torque1SRAM0: released, 1: enabled, 128: the current position becomes the center (2048)
0x29Acceleration1SRAM0: no limit
0x2ATarget position2SRAMWritten every cycle by SYNC WRITE
0x37EEPROM lock1SRAM0: open, EEPROM writes are kept; 1: closed
0x38 to 0x46Feedback15SRAMRead every cycle by SYNC READ: position (0x38), speed (0x3A), load (0x3C), voltage (0x3E), temperature (0x3F), current (0x45)

The first start also writes the undocumented register 0x55 (acceleration limit of the internal motion profile) to 254.

Changing the ID

A servo leaves the factory with ID 1, but a reused servo can have any ID. The SDK therefore addresses it by broadcast (0xFE). Example to give it ID 5:

StepFrameMeaning
1FF FF FE 04 03 37 00 C3Open the EEPROM lock (0x37 = 0)
2FF FF FE 04 03 05 05 F0Write the new ID (0x05 = 5)
3FF FF 05 04 03 37 01 BBClose the lock, this time at the new ID 5’s address

Every servo on the bus receives these broadcast frames and would take the same ID. That is why new servos are set up one at a time, with a single servo plugged in.

Full example: from the Raspberry Pi to the servo

The Raspberry Pi sends READ_SERVO_REGISTER(servo_id=1, register=0x38, size=2) to read the position of servo 1. The STM32 relays the request onto the servo bus, then returns the value read:

HopFrameMeaning
RPi → STM3255 AA 04 0B 01 38 02 5B 1DREAD_SERVO_REGISTER(id=1, reg=0x38, size=2)
STM32 → Servo 1FF FF 01 04 02 38 02 BEREAD DATA, register 0x38, 2 bytes
Servo 1 → STM32FF FF 01 04 00 18 05 DDNo error, position 0x0518 (1304)
STM32 → RPi55 AA 03 84 18 05 F9 22SERVO_REG_VALUE = 1304