Skip to content

Commit

Permalink
TMC SPI daisy chain support (experimental) (MarlinFirmware#15081)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob-the-Kuhn authored and thinkyhead committed Aug 30, 2019
1 parent 0bcb644 commit ba91bca
Show file tree
Hide file tree
Showing 105 changed files with 1,592 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1730,78 +1730,91 @@
#define X_CURRENT 800 // (mA) RMS current. Multiply by 1.414 for peak current.
#define X_MICROSTEPS 16 // 0..256
#define X_RSENSE 0.11
#define X_CHAIN_POS 0 // 0 - Not chained, 1 - MCU MOSI connected, 2 - next in chain, ...
#endif

#if AXIS_IS_TMC(X2)
#define X2_CURRENT 800
#define X2_MICROSTEPS 16
#define X2_RSENSE 0.11
#define X2_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(Y)
#define Y_CURRENT 800
#define Y_MICROSTEPS 16
#define Y_RSENSE 0.11
#define Y_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(Y2)
#define Y2_CURRENT 800
#define Y2_MICROSTEPS 16
#define Y2_RSENSE 0.11
#define Y2_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(Z)
#define Z_CURRENT 800
#define Z_MICROSTEPS 16
#define Z_RSENSE 0.11
#define Z_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(Z2)
#define Z2_CURRENT 800
#define Z2_MICROSTEPS 16
#define Z2_RSENSE 0.11
#define Z2_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(Z3)
#define Z3_CURRENT 800
#define Z3_MICROSTEPS 16
#define Z3_RSENSE 0.11
#define Z3_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(E0)
#define E0_CURRENT 800
#define E0_MICROSTEPS 16
#define E0_RSENSE 0.11
#define E0_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(E1)
#define E1_CURRENT 800
#define E1_MICROSTEPS 16
#define E1_RSENSE 0.11
#define E1_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(E2)
#define E2_CURRENT 800
#define E2_MICROSTEPS 16
#define E2_RSENSE 0.11
#define E2_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(E3)
#define E3_CURRENT 800
#define E3_MICROSTEPS 16
#define E3_RSENSE 0.11
#define E3_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(E4)
#define E4_CURRENT 800
#define E4_MICROSTEPS 16
#define E4_RSENSE 0.11
#define E4_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(E5)
#define E5_CURRENT 800
#define E5_MICROSTEPS 16
#define E5_RSENSE 0.11
#define E5_CHAIN_POS 0
#endif

/**
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@

// Extensible UI pin mapping for RepRapDiscount
#define TOUCH_UI_ULTIPANEL ENABLED(LULZBOT_TOUCH_UI) && ANY(AO_EXP1_PINMAP, AO_EXP2_PINMAP, CR10_TFT_PINMAP)

// TMC SPI Chaining
#define TMC_USE_CHAIN (X_CHAIN_POS||Y_CHAIN_POS||Z_CHAIN_POS||X2_CHAIN_POS||Y2_CHAIN_POS||Z2_CHAIN_POS||Z3_CHAIN_POS||E0_CHAIN_POS||E1_CHAIN_POS||E2_CHAIN_POS||E3_CHAIN_POS||E4_CHAIN_POS||E5_CHAIN_POS)
64 changes: 64 additions & 0 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -2128,6 +2128,70 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#error "STEALTHCHOP requires TMC2130, TMC2160, TMC2208, TMC2209, or TMC5160 stepper drivers."
#endif

#if TMC_USE_CHAIN
#if (X_CHAIN_POS && !PIN_EXISTS(X_CS) ) \
|| (Y_CHAIN_POS && !PIN_EXISTS(Y_CS) ) \
|| (Z_CHAIN_POS && !PIN_EXISTS(Z_CS) ) \
|| (X2_CHAIN_POS && !PIN_EXISTS(X2_CS)) \
|| (Y2_CHAIN_POS && !PIN_EXISTS(Y2_CS)) \
|| (Z2_CHAIN_POS && !PIN_EXISTS(Z2_CS)) \
|| (Z3_CHAIN_POS && !PIN_EXISTS(Z3_CS)) \
|| (E0_CHAIN_POS && !PIN_EXISTS(E0_CS)) \
|| (E1_CHAIN_POS && !PIN_EXISTS(E1_CS)) \
|| (E2_CHAIN_POS && !PIN_EXISTS(E2_CS)) \
|| (E3_CHAIN_POS && !PIN_EXISTS(E3_CS)) \
|| (E4_CHAIN_POS && !PIN_EXISTS(E4_CS)) \
|| (E5_CHAIN_POS && !PIN_EXISTS(E5_CS))
#error "With TMC_USE_CHAIN all chained TMC drivers need a CS pin."
#else
#if X_CHAIN_POS
#define CS_COMPARE X_CS_PIN
#elif Y_CHAIN_POS
#define CS_COMPARE Y_CS_PIN
#elif Z_CHAIN_POS
#define CS_COMPARE Z_CS_PIN
#elif X2_CHAIN_POS
#define CS_COMPARE X2_CS_PIN
#elif Y2_CHAIN_POS
#define CS_COMPARE Y2_CS_PIN
#elif Z2_CHAIN_POS
#define CS_COMPARE Z2_CS_PIN
#elif Z3_CHAIN_POS
#define CS_COMPARE Z3_CS_PIN
#elif E0_CHAIN_POS
#define CS_COMPARE E0_CS_PIN
#elif E1_CHAIN_POS
#define CS_COMPARE E1_CS_PIN
#elif E2_CHAIN_POS
#define CS_COMPARE E2_CS_PIN
#elif E3_CHAIN_POS
#define CS_COMPARE E3_CS_PIN
#elif E4_CHAIN_POS
#define CS_COMPARE E4_CS_PIN
#elif E5_CHAIN_POS
#define CS_COMPARE E5_CS_PIN
#else
#error "With TMC_USE_CHAIN some TMC drivers should be chained."
#endif
#if (X_CHAIN_POS && X_CS_PIN != CS_COMPARE) \
|| (Y_CHAIN_POS && Y_CS_PIN != CS_COMPARE) \
|| (Z_CHAIN_POS && Z_CS_PIN != CS_COMPARE) \
|| (X2_CHAIN_POS && X2_CS_PIN != CS_COMPARE) \
|| (Y2_CHAIN_POS && Y2_CS_PIN != CS_COMPARE) \
|| (Z2_CHAIN_POS && Z2_CS_PIN != CS_COMPARE) \
|| (Z3_CHAIN_POS && Z3_CS_PIN != CS_COMPARE) \
|| (E0_CHAIN_POS && E0_CS_PIN != CS_COMPARE) \
|| (E1_CHAIN_POS && E1_CS_PIN != CS_COMPARE) \
|| (E2_CHAIN_POS && E2_CS_PIN != CS_COMPARE) \
|| (E3_CHAIN_POS && E3_CS_PIN != CS_COMPARE) \
|| (E4_CHAIN_POS && E4_CS_PIN != CS_COMPARE) \
|| (E5_CHAIN_POS && E5_CS_PIN != CS_COMPARE)
#error "With TMC_USE_CHAIN all TMC drivers must use the same CS pin."
#endif
#endif
#undef CS_COMPARE
#endif // TMC_USE_CHAIN

#if ENABLED(DELTA) && (ENABLED(STEALTHCHOP_XY) != ENABLED(STEALTHCHOP_Z))
#error "STEALTHCHOP_XY and STEALTHCHOP_Z must be the same on DELTA."
#endif
Expand Down
87 changes: 87 additions & 0 deletions Marlin/src/module/stepper_indirection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,93 @@ void reset_stepper_drivers() {
};
#endif

#if TMC_USE_CHAIN

enum TMC_axis_enum : unsigned char { _, X, Y, Z, X2, Y2, Z2, Z3, E0, E1, E2, E3, E4, E5 };
#define __TMC_CHAIN(Q,V) do{ stepper##Q.set_chain_info(Q,V); }while(0)
#define _TMC_CHAIN(Q) __TMC_CHAIN(Q, Q##_CHAIN_POS)

#if AXIS_HAS_SPI(X) // First set chain array to uninitialized
__TMC_CHAIN(X, 0);
#endif
#if AXIS_HAS_SPI(X2)
__TMC_CHAIN(X2, 0);
#endif
#if AXIS_HAS_SPI(Y)
__TMC_CHAIN(Y, 0);
#endif
#if AXIS_HAS_SPI(Y2)
__TMC_CHAIN(Y2, 0);
#endif
#if AXIS_HAS_SPI(Z)
__TMC_CHAIN(Z, 0);
#endif
#if AXIS_HAS_SPI(Z2)
__TMC_CHAIN(Z2, 0);
#endif
#if AXIS_HAS_SPI(Z3)
__TMC_CHAIN(Z3, 0);
#endif
#if AXIS_HAS_SPI(E0)
__TMC_CHAIN(E0, 0);
#endif
#if AXIS_HAS_SPI(E1)
__TMC_CHAIN(E1, 0);
#endif
#if AXIS_HAS_SPI(E2)
__TMC_CHAIN(E2, 0);
#endif
#if AXIS_HAS_SPI(E3)
__TMC_CHAIN(E3, 0);
#endif
#if AXIS_HAS_SPI(E4)
__TMC_CHAIN(E4, 0);
#endif
#if AXIS_HAS_SPI(E5)
__TMC_CHAIN(E5, 0);
#endif

#if AXIS_HAS_SPI(X) && X_CHAIN_POS // Now set up the SPI chain
_TMC_CHAIN(X);
#endif
#if AXIS_HAS_SPI(X2) && X2_CHAIN_POS
_TMC_CHAIN(X2);
#endif
#if AXIS_HAS_SPI(Y) && Y_CHAIN_POS
_TMC_CHAIN(Y);
#endif
#if AXIS_HAS_SPI(Y2) && Y2_CHAIN_POS
_TMC_CHAIN(Y2);
#endif
#if AXIS_HAS_SPI(Z) && Z_CHAIN_POS
_TMC_CHAIN(Z);
#endif
#if AXIS_HAS_SPI(Z2) && Z2_CHAIN_POS
_TMC_CHAIN(Z2);
#endif
#if AXIS_HAS_SPI(Z3) && Z3_CHAIN_POS
_TMC_CHAIN(Z3);
#endif
#if AXIS_HAS_SPI(E0) && E0_CHAIN_POS
_TMC_CHAIN(E0);
#endif
#if AXIS_HAS_SPI(E1) && E1_CHAIN_POS
_TMC_CHAIN(E1);
#endif
#if AXIS_HAS_SPI(E2) && E2_CHAIN_POS
_TMC_CHAIN(E2);
#endif
#if AXIS_HAS_SPI(E3) && E3_CHAIN_POS
_TMC_CHAIN(E3);
#endif
#if AXIS_HAS_SPI(E4) && E4_CHAIN_POS
_TMC_CHAIN(E4);
#endif
#if AXIS_HAS_SPI(E5) && E5_CHAIN_POS
_TMC_CHAIN(E5);
#endif
#endif // TMC_USE_CHAIN

#if AXIS_IS_TMC(X)
_TMC_INIT(X, STEALTH_AXIS_XY);
#endif
Expand Down
13 changes: 13 additions & 0 deletions config/default/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1730,78 +1730,91 @@
#define X_CURRENT 800 // (mA) RMS current. Multiply by 1.414 for peak current.
#define X_MICROSTEPS 16 // 0..256
#define X_RSENSE 0.11
#define X_CHAIN_POS 0 // 0 - Not chained, 1 - MCU MOSI connected, 2 - next in chain, ...
#endif

#if AXIS_IS_TMC(X2)
#define X2_CURRENT 800
#define X2_MICROSTEPS 16
#define X2_RSENSE 0.11
#define X2_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(Y)
#define Y_CURRENT 800
#define Y_MICROSTEPS 16
#define Y_RSENSE 0.11
#define Y_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(Y2)
#define Y2_CURRENT 800
#define Y2_MICROSTEPS 16
#define Y2_RSENSE 0.11
#define Y2_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(Z)
#define Z_CURRENT 800
#define Z_MICROSTEPS 16
#define Z_RSENSE 0.11
#define Z_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(Z2)
#define Z2_CURRENT 800
#define Z2_MICROSTEPS 16
#define Z2_RSENSE 0.11
#define Z2_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(Z3)
#define Z3_CURRENT 800
#define Z3_MICROSTEPS 16
#define Z3_RSENSE 0.11
#define Z3_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(E0)
#define E0_CURRENT 800
#define E0_MICROSTEPS 16
#define E0_RSENSE 0.11
#define E0_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(E1)
#define E1_CURRENT 800
#define E1_MICROSTEPS 16
#define E1_RSENSE 0.11
#define E1_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(E2)
#define E2_CURRENT 800
#define E2_MICROSTEPS 16
#define E2_RSENSE 0.11
#define E2_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(E3)
#define E3_CURRENT 800
#define E3_MICROSTEPS 16
#define E3_RSENSE 0.11
#define E3_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(E4)
#define E4_CURRENT 800
#define E4_MICROSTEPS 16
#define E4_RSENSE 0.11
#define E4_CHAIN_POS 0
#endif

#if AXIS_IS_TMC(E5)
#define E5_CURRENT 800
#define E5_MICROSTEPS 16
#define E5_RSENSE 0.11
#define E5_CHAIN_POS 0
#endif

/**
Expand Down
Loading

0 comments on commit ba91bca

Please sign in to comment.