Trinamic TMCs drivers in Zephyr RTOS

Introduction to the Zephyr RTOS driver for the TMC51xx series of motor ICs from TRINAMIC.

State of the art

The driver supports both SPI and UART communication protocols. It provides a set of console commands to configure the driver and to run the stepper motor in velocity or position mode, using the internal ramp generator. Source code can be downloaded from GitHub.


  • implement the full Sensor API to set/get driver parameters
  • implement step/dir mode

SPI interface

Interfacing with the TMC via SPI is pretty straightforward.

SPI speed is set to 1MHz to be on the safe side, but can be increased up to 4MHz, according to the datasheet.

&spi2 {
    cs-gpios = <&gpiob 12 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;

    tmc0: tmc5160@0 {
        compatible = "trinamic,tmc5160";
        status = "okay";
        label = "TMC5160";
        reg = <0x00>;
        spi-max-frequency = <1000000>;
        //rotation-distance = <1>;    // [mm/turn] not supported yet

UART interface

Interface via UART is a bit more tricky but serves better the case of several TMC drivers connected on the same bus. Here the UART on the “master” (a Nucleo F103RB board) is configured as “single-wire” and uses DMA.

&usart1 {
    dmas = <&dma1 4 0x440>,
            <&dma1 5 0x480>;
    dma-names = "tx", "rx";
    pinctrl-0 = <&usart1_tx_pa9>;

    tmc0: tmc5160 {
        compatible = "trinamic,tmc5160";
        status = "okay";
        label = "TMC5160";

On the ST Nucleo F103RB board the UART2 is used for the consol/debug. Select a different UARTx for the TMC driver.

Shell commands

The driver provides a simple set of commands (below is a subset) that can be used to run a motor or just peek into drivers registers.

# Run motor (address) 0 at 10 rpm
> tmc 0 run 10

# Stop the motor
> tmc 0 run 0

# Rotate motor fwd by 2 turns and back by 1 (incremental positioning)
> tmc 0 turn 2
> tmc 0 turn -1

# Rotate motor to 0 turns (absolute positioning)
> tmc 0 move 0

# Read  current position from the register
> tmc 0 get xactual

Sample applications

Sample applications for connecting a ST Nucleo F103RB board to a TMC5160 via SPI and UART are provided as a starting point.



Load the VSCode workspace provided for a quick start with development.

Project setup

cd <repo root>
west init -l manifest
west update

The provided west manifest is kept small on purpose. It works out-of-the-box for STM32 silicons and shall be modified if you’re targeting a different one. See Zephyr manifest for the complete list of modules


The project comes with a short list of VSCode build tasks for the sample applications, that can be accesses via «CTRL+SHIFT+B».


The TMC5160 driver has been tested with the Nucleo-64 STM32F103RB board, Watterott SilentStepStick TMC5160 (SPI only, UART pins not available), TRINAMIC TMC5160-BOB breakout board, TRINAMIC TMC5160-EVAL and own custom boards based on TMC5130 chips.

COMING SOON - Pictures of the testing setup and wiring, and test procedures (incl. power up order: VM first, then VCC_IO, and cycling of vcc io to reset)