How to get or set Trinamic TMC stepper motor current in Marlin firmware

In Marlin, you can dynamically configure the stepper motor current for Trinamic stepper drivers like the TMC2208 or the TMC5160.

Changing the motor current via G-Code

The easiest option is by using G-Codes. In order to set the stepper motor current for X , Y and Z to 2 Amperes (2000 mA), use M906 like this:

M906X2000Y2000Z2000

Now save the settings to the EEPROM using

M500

You can also query the current stepper motor current using

M906
X driver current: 2000
Y driver current: 2000
Z driver current: 2000
E driver current: 800
ok

Changing the motor current in the config file

You can also set default stepper motor current values in the Marlin config files. Note that these will be overridden by any value in the EEPROM.

In Configuration_adv.h, look for

#if HAS_TRINAMIC_CONFIG

which contains axis definitions like

#if AXIS_IS_TMC(X)
  #define X_CURRENT       800        // (mA) RMS current. Multiply by 1.414 for peak current.
  #define X_CURRENT_HOME  X_CURRENT  // (mA) RMS current for sensorless homing
  #define X_MICROSTEPS     32        // 0..256
  #define X_RSENSE          0.11
  #define X_CHAIN_POS      -1        // -1..0: Not chained. 1: MCU MOSI connected. 2: Next in chain, ...
  //#define X_INTERPOLATE  true      // Enable to override 'INTERPOLATE' for the X axis
#endif

Change the value in the line

#define X_CURRENT 800 // (mA) RMS current. Multiply by 1.414 for peak current.

so, for example to set 2A (2000 mA), set it to

#define X_CURRENT 2000 // (mA) RMS current. Multiply by 1.414 for peak current.