🔧 Merge TMC26X with TMC config (#24373)

This commit is contained in:
Manuel McLure 2022-11-26 18:30:59 -08:00 committed by Scott Lahteine
parent 6185b50dbe
commit 360e03797f
7 changed files with 74 additions and 192 deletions

View File

@ -2669,167 +2669,33 @@
//#define FILAMENT_UNLOAD_ALL_EXTRUDERS // Allow M702 to unload all extruders above a minimum target temp (as set by M302)
#endif
/**
* TMC26X Stepper Driver options
*
* The TMC26XStepper library is required for this stepper driver.
* https://github.com/trinamic/TMC26XStepper
* @section tmc/tmc26x
*/
#if HAS_DRIVER(TMC26X)
#if AXIS_DRIVER_TYPE_X(TMC26X)
#define X_MAX_CURRENT 1000 // (mA)
#define X_SENSE_RESISTOR 91 // (mOhms)
#define X_MICROSTEPS 16 // Number of microsteps
#endif
#if AXIS_DRIVER_TYPE_X2(TMC26X)
#define X2_MAX_CURRENT 1000
#define X2_SENSE_RESISTOR 91
#define X2_MICROSTEPS X_MICROSTEPS
#endif
#if AXIS_DRIVER_TYPE_Y(TMC26X)
#define Y_MAX_CURRENT 1000
#define Y_SENSE_RESISTOR 91
#define Y_MICROSTEPS 16
#endif
#if AXIS_DRIVER_TYPE_Y2(TMC26X)
#define Y2_MAX_CURRENT 1000
#define Y2_SENSE_RESISTOR 91
#define Y2_MICROSTEPS Y_MICROSTEPS
#endif
#if AXIS_DRIVER_TYPE_Z(TMC26X)
#define Z_MAX_CURRENT 1000
#define Z_SENSE_RESISTOR 91
#define Z_MICROSTEPS 16
#endif
#if AXIS_DRIVER_TYPE_Z2(TMC26X)
#define Z2_MAX_CURRENT 1000
#define Z2_SENSE_RESISTOR 91
#define Z2_MICROSTEPS Z_MICROSTEPS
#endif
#if AXIS_DRIVER_TYPE_Z3(TMC26X)
#define Z3_MAX_CURRENT 1000
#define Z3_SENSE_RESISTOR 91
#define Z3_MICROSTEPS Z_MICROSTEPS
#endif
#if AXIS_DRIVER_TYPE_Z4(TMC26X)
#define Z4_MAX_CURRENT 1000
#define Z4_SENSE_RESISTOR 91
#define Z4_MICROSTEPS Z_MICROSTEPS
#endif
#if AXIS_DRIVER_TYPE_I(TMC26X)
#define I_MAX_CURRENT 1000
#define I_SENSE_RESISTOR 91
#define I_MICROSTEPS 16
#endif
#if AXIS_DRIVER_TYPE_J(TMC26X)
#define J_MAX_CURRENT 1000
#define J_SENSE_RESISTOR 91
#define J_MICROSTEPS 16
#endif
#if AXIS_DRIVER_TYPE_K(TMC26X)
#define K_MAX_CURRENT 1000
#define K_SENSE_RESISTOR 91
#define K_MICROSTEPS 16
#endif
#if AXIS_DRIVER_TYPE_U(TMC26X)
#define U_MAX_CURRENT 1000
#define U_SENSE_RESISTOR 91
#define U_MICROSTEPS 16
#endif
#if AXIS_DRIVER_TYPE_V(TMC26X)
#define V_MAX_CURRENT 1000
#define V_SENSE_RESISTOR 91
#define V_MICROSTEPS 16
#endif
#if AXIS_DRIVER_TYPE_W(TMC26X)
#define W_MAX_CURRENT 1000
#define W_SENSE_RESISTOR 91
#define W_MICROSTEPS 16
#endif
#if AXIS_DRIVER_TYPE_E0(TMC26X)
#define E0_MAX_CURRENT 1000
#define E0_SENSE_RESISTOR 91
#define E0_MICROSTEPS 16
#endif
#if AXIS_DRIVER_TYPE_E1(TMC26X)
#define E1_MAX_CURRENT 1000
#define E1_SENSE_RESISTOR 91
#define E1_MICROSTEPS E0_MICROSTEPS
#endif
#if AXIS_DRIVER_TYPE_E2(TMC26X)
#define E2_MAX_CURRENT 1000
#define E2_SENSE_RESISTOR 91
#define E2_MICROSTEPS E0_MICROSTEPS
#endif
#if AXIS_DRIVER_TYPE_E3(TMC26X)
#define E3_MAX_CURRENT 1000
#define E3_SENSE_RESISTOR 91
#define E3_MICROSTEPS E0_MICROSTEPS
#endif
#if AXIS_DRIVER_TYPE_E4(TMC26X)
#define E4_MAX_CURRENT 1000
#define E4_SENSE_RESISTOR 91
#define E4_MICROSTEPS E0_MICROSTEPS
#endif
#if AXIS_DRIVER_TYPE_E5(TMC26X)
#define E5_MAX_CURRENT 1000
#define E5_SENSE_RESISTOR 91
#define E5_MICROSTEPS E0_MICROSTEPS
#endif
#if AXIS_DRIVER_TYPE_E6(TMC26X)
#define E6_MAX_CURRENT 1000
#define E6_SENSE_RESISTOR 91
#define E6_MICROSTEPS E0_MICROSTEPS
#endif
#if AXIS_DRIVER_TYPE_E7(TMC26X)
#define E7_MAX_CURRENT 1000
#define E7_SENSE_RESISTOR 91
#define E7_MICROSTEPS E0_MICROSTEPS
#endif
#endif // TMC26X
// @section tmc_smart
/**
* To use TMC2130, TMC2160, TMC2660, TMC5130, TMC5160 stepper drivers in SPI mode
* connect your SPI pins to the hardware SPI interface on your board and define
* the required CS pins in your `pins_MYBOARD.h` file. (e.g., RAMPS 1.4 uses AUX3
* pins `X_CS_PIN 53`, `Y_CS_PIN 49`, etc.).
* You may also use software SPI if you wish to use general purpose IO pins.
* Trinamic Smart Drivers
*
* To use TMC2208 stepper UART-configurable stepper drivers connect #_SERIAL_TX_PIN
* to the driver side PDN_UART pin with a 1K resistor.
* To use the reading capabilities, also connect #_SERIAL_RX_PIN to PDN_UART without
* a resistor.
* The drivers can also be used with hardware serial.
* To use TMC2130, TMC2160, TMC2660, TMC5130, TMC5160 stepper drivers in SPI mode:
* - Connect your SPI pins to the Hardware SPI interface on the board.
* Some boards have simple jumper connections! See your board's documentation.
* - Define the required Stepper CS pins in your `pins_MYBOARD.h` file.
* (See the RAMPS pins, for example.)
* - You can also use Software SPI with GPIO pins instead of Hardware SPI.
*
* TMCStepper library is required to use TMC stepper drivers.
* To use TMC220x stepper drivers with Serial UART:
* - Connect PDN_UART to the #_SERIAL_TX_PIN through a 1K resistor.
* For reading capabilities also connect PDN_UART to #_SERIAL_RX_PIN with no resistor.
* Some boards have simple jumper connections! See your board's documentation.
* - These drivers can also be used with Hardware Serial.
*
* The TMC26XStepper library is required for TMC26X stepper drivers.
* https://github.com/MarlinFirmware/TMC26XStepper
*
* The TMCStepper library is required for other TMC stepper drivers.
* https://github.com/teemuatlut/TMCStepper
*
* @section tmc/config
*/
#if HAS_TRINAMIC_CONFIG
#if HAS_TRINAMIC_CONFIG || HAS_TMC26X
#define HOLD_MULTIPLIER 0.5 // Scales down the holding current from run current
@ -2839,17 +2705,17 @@
*/
#define INTERPOLATE true
#if AXIS_IS_TMC(X)
#if AXIS_IS_TMC_CONFIG(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 16 // 0..256
#define X_RSENSE 0.11
#define X_RSENSE 0.11 // Multiplied x1000 for TMC26X
#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
//#define X_HOLD_MULTIPLIER 0.5 // Enable to override 'HOLD_MULTIPLIER' for the X axis
#endif
#if AXIS_IS_TMC(X2)
#if AXIS_IS_TMC_CONFIG(X2)
#define X2_CURRENT 800
#define X2_CURRENT_HOME X2_CURRENT
#define X2_MICROSTEPS X_MICROSTEPS
@ -2859,7 +2725,7 @@
//#define X2_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(Y)
#if AXIS_IS_TMC_CONFIG(Y)
#define Y_CURRENT 800
#define Y_CURRENT_HOME Y_CURRENT
#define Y_MICROSTEPS 16
@ -2869,7 +2735,7 @@
//#define Y_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(Y2)
#if AXIS_IS_TMC_CONFIG(Y2)
#define Y2_CURRENT 800
#define Y2_CURRENT_HOME Y2_CURRENT
#define Y2_MICROSTEPS Y_MICROSTEPS
@ -2879,7 +2745,7 @@
//#define Y2_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(Z)
#if AXIS_IS_TMC_CONFIG(Z)
#define Z_CURRENT 800
#define Z_CURRENT_HOME Z_CURRENT
#define Z_MICROSTEPS 16
@ -2889,7 +2755,7 @@
//#define Z_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(Z2)
#if AXIS_IS_TMC_CONFIG(Z2)
#define Z2_CURRENT 800
#define Z2_CURRENT_HOME Z2_CURRENT
#define Z2_MICROSTEPS Z_MICROSTEPS
@ -2899,7 +2765,7 @@
//#define Z2_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(Z3)
#if AXIS_IS_TMC_CONFIG(Z3)
#define Z3_CURRENT 800
#define Z3_CURRENT_HOME Z3_CURRENT
#define Z3_MICROSTEPS Z_MICROSTEPS
@ -2909,7 +2775,7 @@
//#define Z3_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(Z4)
#if AXIS_IS_TMC_CONFIG(Z4)
#define Z4_CURRENT 800
#define Z4_CURRENT_HOME Z4_CURRENT
#define Z4_MICROSTEPS Z_MICROSTEPS
@ -2919,7 +2785,7 @@
//#define Z4_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(I)
#if AXIS_IS_TMC_CONFIG(I)
#define I_CURRENT 800
#define I_CURRENT_HOME I_CURRENT
#define I_MICROSTEPS 16
@ -2929,7 +2795,7 @@
//#define I_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(J)
#if AXIS_IS_TMC_CONFIG(J)
#define J_CURRENT 800
#define J_CURRENT_HOME J_CURRENT
#define J_MICROSTEPS 16
@ -2939,7 +2805,7 @@
//#define J_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(K)
#if AXIS_IS_TMC_CONFIG(K)
#define K_CURRENT 800
#define K_CURRENT_HOME K_CURRENT
#define K_MICROSTEPS 16
@ -2949,7 +2815,7 @@
//#define K_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(U)
#if AXIS_IS_TMC_CONFIG(U)
#define U_CURRENT 800
#define U_CURRENT_HOME U_CURRENT
#define U_MICROSTEPS 8
@ -2959,7 +2825,7 @@
//#define U_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(V)
#if AXIS_IS_TMC_CONFIG(V)
#define V_CURRENT 800
#define V_CURRENT_HOME V_CURRENT
#define V_MICROSTEPS 8
@ -2969,7 +2835,7 @@
//#define V_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(W)
#if AXIS_IS_TMC_CONFIG(W)
#define W_CURRENT 800
#define W_CURRENT_HOME W_CURRENT
#define W_MICROSTEPS 8
@ -2979,7 +2845,7 @@
//#define W_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(E0)
#if AXIS_IS_TMC_CONFIG(E0)
#define E0_CURRENT 800
#define E0_MICROSTEPS 16
#define E0_RSENSE 0.11
@ -2988,7 +2854,7 @@
//#define E0_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(E1)
#if AXIS_IS_TMC_CONFIG(E1)
#define E1_CURRENT 800
#define E1_MICROSTEPS E0_MICROSTEPS
#define E1_RSENSE 0.11
@ -2997,7 +2863,7 @@
//#define E1_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(E2)
#if AXIS_IS_TMC_CONFIG(E2)
#define E2_CURRENT 800
#define E2_MICROSTEPS E0_MICROSTEPS
#define E2_RSENSE 0.11
@ -3006,7 +2872,7 @@
//#define E2_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(E3)
#if AXIS_IS_TMC_CONFIG(E3)
#define E3_CURRENT 800
#define E3_MICROSTEPS E0_MICROSTEPS
#define E3_RSENSE 0.11
@ -3015,7 +2881,7 @@
//#define E3_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(E4)
#if AXIS_IS_TMC_CONFIG(E4)
#define E4_CURRENT 800
#define E4_MICROSTEPS E0_MICROSTEPS
#define E4_RSENSE 0.11
@ -3024,7 +2890,7 @@
//#define E4_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(E5)
#if AXIS_IS_TMC_CONFIG(E5)
#define E5_CURRENT 800
#define E5_MICROSTEPS E0_MICROSTEPS
#define E5_RSENSE 0.11
@ -3033,7 +2899,7 @@
//#define E5_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(E6)
#if AXIS_IS_TMC_CONFIG(E6)
#define E6_CURRENT 800
#define E6_MICROSTEPS E0_MICROSTEPS
#define E6_RSENSE 0.11
@ -3042,7 +2908,7 @@
//#define E6_HOLD_MULTIPLIER 0.5
#endif
#if AXIS_IS_TMC(E7)
#if AXIS_IS_TMC_CONFIG(E7)
#define E7_CURRENT 800
#define E7_MICROSTEPS E0_MICROSTEPS
#define E7_RSENSE 0.11
@ -3144,6 +3010,7 @@
* Use Trinamic's ultra quiet stepping mode.
* When disabled, Marlin will use spreadCycle stepping mode.
*/
#if HAS_STEALTHCHOP
#define STEALTHCHOP_XY
#define STEALTHCHOP_Z
#define STEALTHCHOP_I
@ -3153,6 +3020,7 @@
#define STEALTHCHOP_V
#define STEALTHCHOP_W
#define STEALTHCHOP_E
#endif
/**
* Optimize spreadCycle chopper parameters by using predefined parameter sets
@ -3335,7 +3203,7 @@
*/
#define TMC_ADV() { }
#endif // HAS_TRINAMIC_CONFIG
#endif // HAS_TRINAMIC_CONFIG || HAS_TMC26X
// @section i2cbus

View File

@ -125,6 +125,8 @@
|| AXIS_DRIVER_TYPE(A,TMC2660) \
|| AXIS_DRIVER_TYPE(A,TMC5130) || AXIS_DRIVER_TYPE(A,TMC5160) )
#define AXIS_IS_TMC_CONFIG(A) ( AXIS_IS_TMC(A) || AXIS_DRIVER_TYPE(A,TMC26X) )
// Test for a driver that uses SPI - this allows checking whether a _CS_ pin
// is considered sensitive
#define AXIS_HAS_SPI(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \

View File

@ -36,6 +36,8 @@ struct IF { typedef R type; };
template <class L, class R>
struct IF<true, L, R> { typedef L type; };
#define ALL_AXIS_NAMES X, X2, Y, Y2, Z, Z2, Z3, Z4, I, J, K, U, V, W, E0, E1, E2, E3, E4, E5, E6, E7
#define NUM_AXIS_GANG(V...) GANG_N(NUM_AXES, V)
#define NUM_AXIS_CODE(V...) CODE_N(NUM_AXES, V)
#define NUM_AXIS_LIST(V...) LIST_N(NUM_AXES, V)

View File

@ -994,8 +994,8 @@
#undef CALIBRATION_MEASURE_IMIN
#undef CALIBRATION_MEASURE_IMAX
#if NUM_AXES < 3
#undef Z_IDLE_HEIGHT
#undef STEALTHCHOP_Z
#undef Z_IDLE_HEIGHT
#undef Z_PROBE_SLED
#undef Z_SAFE_HOMING
#undef HOME_Z_FIRST
@ -1005,6 +1005,7 @@
#undef CNC_WORKSPACE_PLANES
#if NUM_AXES < 2
#undef STEALTHCHOP_Y
#undef QUICK_HOME
#endif
#endif
#endif

View File

@ -681,6 +681,17 @@
constexpr float arm[] = AXIS_RELATIVE_MODES;
static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _LOGICAL_AXES_STR "elements.");
// Consolidate TMC26X, validate migration (#24373)
#define _ISMAX_1(A) defined(A##_MAX_CURRENT)
#define _ISSNS_1(A) defined(A##_SENSE_RESISTOR)
#if DO(ISMAX,||,ALL_AXIS_NAMES)
#error "*_MAX_CURRENT is now set with *_CURRENT."
#elif DO(ISSNS,||,ALL_AXIS_NAMES)
#error "*_SENSE_RESISTOR (in Milli-Ohms) is now set with *_RSENSE (in Ohms), so you must divide values by 1000."
#endif
#undef _ISMAX_1
#undef _ISSNS_1
/**
* Probe temp compensation requirements
*/

View File

@ -34,7 +34,7 @@
#include "TMC26X.h"
#define _TMC26X_DEFINE(ST) TMC26XStepper stepper##ST(200, ST##_CS_PIN, ST##_STEP_PIN, ST##_DIR_PIN, ST##_MAX_CURRENT, ST##_SENSE_RESISTOR)
#define _TMC26X_DEFINE(ST) TMC26XStepper stepper##ST(200, ST##_CS_PIN, ST##_STEP_PIN, ST##_DIR_PIN, ST##_CURRENT, int(ST##_RSENSE * 1000))
#if AXIS_DRIVER_TYPE_X(TMC26X)
_TMC26X_DEFINE(X);

View File

@ -1023,8 +1023,6 @@ void reset_trinamic_drivers() {
// 2. For each axis in use, static_assert using a constexpr function, which counts the
// number of matching/conflicting axis. If the value is not exactly 1, fail.
#define ALL_AXIS_NAMES X, X2, Y, Y2, Z, Z2, Z3, Z4, I, J, K, U, V, W, E0, E1, E2, E3, E4, E5, E6, E7
#if ANY_AXIS_HAS(HW_SERIAL)
// Hardware serial names are compared as strings, since actually resolving them cannot occur in a constexpr.
// Using a fixed-length character array for the port name allows this to be constexpr compatible.