From 894762259b072407504ee584103680b103310026 Mon Sep 17 00:00:00 2001 From: Fabio Santos Date: Sat, 8 Feb 2020 19:01:57 -0800 Subject: [PATCH] Coolstep for TMC2130, 2209, 5130, 5160 (#16790) --- Marlin/Configuration.h | 5 - Marlin/Configuration_adv.h | 160 +++++++++++++++ Marlin/src/HAL/HAL_AVR/inc/SanityCheck.h | 2 +- Marlin/src/HAL/HAL_DUE/inc/SanityCheck.h | 2 +- Marlin/src/HAL/HAL_ESP32/inc/SanityCheck.h | 2 +- Marlin/src/HAL/HAL_LINUX/inc/SanityCheck.h | 2 +- Marlin/src/HAL/HAL_SAMD51/inc/SanityCheck.h | 2 +- Marlin/src/HAL/HAL_STM32/HAL.cpp | 4 +- Marlin/src/HAL/HAL_STM32F1/inc/SanityCheck.h | 2 +- .../src/HAL/HAL_STM32_F4_F7/inc/SanityCheck.h | 2 +- .../src/HAL/HAL_TEENSY31_32/inc/SanityCheck.h | 2 +- .../src/HAL/HAL_TEENSY35_36/inc/SanityCheck.h | 2 +- Marlin/src/MarlinCore.cpp | 2 +- Marlin/src/core/drivers.h | 29 ++- Marlin/src/feature/tmc_util.cpp | 31 +-- Marlin/src/feature/tmc_util.h | 23 ++- Marlin/src/inc/SanityCheck.h | 58 +++++- Marlin/src/module/stepper.cpp | 2 +- Marlin/src/module/stepper/trinamic.cpp | 185 ++++++++++++++---- Marlin/src/pins/lpc1768/pins_GMARSH_X6_REV1.h | 2 +- Marlin/src/pins/lpc1769/pins_TH3D_EZBOARD.h | 4 +- Marlin/src/pins/mega/pins_MIGHTYBOARD_REVE.h | 6 +- Marlin/src/pins/pins.h | 22 +++ Marlin/src/pins/ramps/pins_Z_BOLT_X_SERIES.h | 4 +- .../pins/stm32/pins_BTT_SKR_MINI_E3_V1_0.h | 4 +- 25 files changed, 473 insertions(+), 86 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 99a254969c..a8e518098d 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -674,11 +674,6 @@ //#define X_DRIVER_TYPE A4988 //#define Y_DRIVER_TYPE A4988 //#define Z_DRIVER_TYPE A4988 -//#define X2_DRIVER_TYPE A4988 -//#define Y2_DRIVER_TYPE A4988 -//#define Z2_DRIVER_TYPE A4988 -//#define Z3_DRIVER_TYPE A4988 -//#define Z4_DRIVER_TYPE A4988 //#define E0_DRIVER_TYPE A4988 //#define E1_DRIVER_TYPE A4988 //#define E2_DRIVER_TYPE A4988 diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index f5a561b4c2..2d4931a722 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -2275,6 +2275,166 @@ #define E6_HYBRID_THRESHOLD 30 #define E7_HYBRID_THRESHOLD 30 + /** + * CoolStep. Currently supported for TMC2130, TMC2209, TMC5130 and TMC5160 only. + * This mode allows for cooler steppers and energy savings. + * The driver will switch to coolStep when stepper speed is over COOLSTEP_THRESHOLD mm/s. + * + * If SG_RESULT goes below COOLSTEP_LOWER_LOAD_THRESHOLD * 32 stepper current will be increased. + * Set to 0 to disable CoolStep. + * + * If SG_RESULT goes above (COOLSTEP_LOWER_LOAD_THRESHOLD + COOLSTEP_UPPER_LOAD_THRESHOLD + 1) * 32 + * stepper current will be decreased. + * + * SEUP sets the increase step width. Value range is 0..3 and computed as 2^SEUP. + * SEDN sets the decrease delay. Value range is 0..3, 0 being the slowest. + * SEIMIN sets the lower current limit. 0: 1/2 of IRUN, 1:1/4 of IRUN + */ + + #if AXIS_HAS_COOLSTEP(X) + #define X_COOLSTEP_SPEED_THRESHOLD 5 + #define X_COOLSTEP_LOWER_LOAD_THRESHOLD 7 + #define X_COOLSTEP_UPPER_LOAD_THRESHOLD 0 + #define X_COOLSTEP_SEUP 2 + #define X_COOLSTEP_SEDN 0 + #define X_COOLSTEP_SEIMIN 1 + #endif + + #if AXIS_HAS_COOLSTEP(X2) + #define X2_COOLSTEP_SPEED_THRESHOLD 5 + #define X2_COOLSTEP_LOWER_LOAD_THRESHOLD 7 + #define X2_COOLSTEP_UPPER_LOAD_THRESHOLD 0 + #define X2_COOLSTEP_SEUP 2 + #define X2_COOLSTEP_SEDN 0 + #define X2_COOLSTEP_SEIMIN 1 + #endif + + #if AXIS_HAS_COOLSTEP(Y) + #define Y_COOLSTEP_SPEED_THRESHOLD 5 + #define Y_COOLSTEP_LOWER_LOAD_THRESHOLD 7 + #define Y_COOLSTEP_UPPER_LOAD_THRESHOLD 0 + #define Y_COOLSTEP_SEUP 2 + #define Y_COOLSTEP_SEDN 0 + #define Y_COOLSTEP_SEIMIN 1 + #endif + + #if AXIS_HAS_COOLSTEP(Y2) + #define Y2_COOLSTEP_SPEED_THRESHOLD 5 + #define Y2_COOLSTEP_LOWER_LOAD_THRESHOLD 7 + #define Y2_COOLSTEP_UPPER_LOAD_THRESHOLD 0 + #define Y2_COOLSTEP_SEUP 2 + #define Y2_COOLSTEP_SEDN 0 + #define Y2_COOLSTEP_SEIMIN 1 + #endif + + #if AXIS_HAS_COOLSTEP(Z) + #define Z_COOLSTEP_SPEED_THRESHOLD 5 + #define Z_COOLSTEP_LOWER_LOAD_THRESHOLD 7 + #define Z_COOLSTEP_UPPER_LOAD_THRESHOLD 0 + #define Z_COOLSTEP_SEUP 2 + #define Z_COOLSTEP_SEDN 0 + #define Z_COOLSTEP_SEIMIN 1 + #endif + + #if AXIS_HAS_COOLSTEP(Z2) + #define Z2_COOLSTEP_SPEED_THRESHOLD 5 + #define Z2_COOLSTEP_LOWER_LOAD_THRESHOLD 7 + #define Z2_COOLSTEP_UPPER_LOAD_THRESHOLD 0 + #define Z2_COOLSTEP_SEUP 2 + #define Z2_COOLSTEP_SEDN 0 + #define Z2_COOLSTEP_SEIMIN 1 + #endif + + #if AXIS_HAS_COOLSTEP(Z3) + #define Z3_COOLSTEP_SPEED_THRESHOLD 5 + #define Z3_COOLSTEP_LOWER_LOAD_THRESHOLD 7 + #define Z3_COOLSTEP_UPPER_LOAD_THRESHOLD 0 + #define Z3_COOLSTEP_SEUP 2 + #define Z3_COOLSTEP_SEDN 0 + #define Z3_COOLSTEP_SEIMIN 1 + #endif + + #if AXIS_HAS_COOLSTEP(Z4) + #define Z4_COOLSTEP_SPEED_THRESHOLD 5 + #define Z4_COOLSTEP_LOWER_LOAD_THRESHOLD 7 + #define Z4_COOLSTEP_UPPER_LOAD_THRESHOLD 0 + #define Z4_COOLSTEP_SEUP 2 + #define Z4_COOLSTEP_SEDN 0 + #define Z4_COOLSTEP_SEIMIN 1 + #endif + + #if AXIS_HAS_COOLSTEP(E0) + #define E0_COOLSTEP_SPEED_THRESHOLD 5 + #define E0_COOLSTEP_LOWER_LOAD_THRESHOLD 7 + #define E0_COOLSTEP_UPPER_LOAD_THRESHOLD 0 + #define E0_COOLSTEP_SEUP 2 + #define E0_COOLSTEP_SEDN 0 + #define E0_COOLSTEP_SEIMIN 1 + #endif + + #if AXIS_HAS_COOLSTEP(E1) + #define E1_COOLSTEP_SPEED_THRESHOLD 5 + #define E1_COOLSTEP_LOWER_LOAD_THRESHOLD 7 + #define E1_COOLSTEP_UPPER_LOAD_THRESHOLD 0 + #define E1_COOLSTEP_SEUP 2 + #define E1_COOLSTEP_SEDN 0 + #define E1_COOLSTEP_SEIMIN 1 + #endif + + #if AXIS_HAS_COOLSTEP(E2) + #define E2_COOLSTEP_SPEED_THRESHOLD 5 + #define E2_COOLSTEP_LOWER_LOAD_THRESHOLD 7 + #define E2_COOLSTEP_UPPER_LOAD_THRESHOLD 0 + #define E2_COOLSTEP_SEUP 2 + #define E2_COOLSTEP_SEDN 0 + #define E2_COOLSTEP_SEIMIN 1 + #endif + + #if AXIS_HAS_COOLSTEP(E3) + #define E3_COOLSTEP_SPEED_THRESHOLD 5 + #define E3_COOLSTEP_LOWER_LOAD_THRESHOLD 7 + #define E3_COOLSTEP_UPPER_LOAD_THRESHOLD 0 + #define E3_COOLSTEP_SEUP 2 + #define E3_COOLSTEP_SEDN 0 + #define E3_COOLSTEP_SEIMIN 1 + #endif + + #if AXIS_HAS_COOLSTEP(E4) + #define E4_COOLSTEP_SPEED_THRESHOLD 5 + #define E4_COOLSTEP_LOWER_LOAD_THRESHOLD 7 + #define E4_COOLSTEP_UPPER_LOAD_THRESHOLD 0 + #define E4_COOLSTEP_SEUP 2 + #define E4_COOLSTEP_SEDN 0 + #define E4_COOLSTEP_SEIMIN 1 + #endif + + #if AXIS_HAS_COOLSTEP(E5) + #define E5_COOLSTEP_SPEED_THRESHOLD 5 + #define E5_COOLSTEP_LOWER_LOAD_THRESHOLD 7 + #define E5_COOLSTEP_UPPER_LOAD_THRESHOLD 0 + #define E5_COOLSTEP_SEUP 2 + #define E5_COOLSTEP_SEDN 0 + #define E5_COOLSTEP_SEIMIN 1 + #endif + + #if AXIS_HAS_COOLSTEP(E6) + #define E6_COOLSTEP_SPEED_THRESHOLD 5 + #define E6_COOLSTEP_LOWER_LOAD_THRESHOLD 7 + #define E6_COOLSTEP_UPPER_LOAD_THRESHOLD 0 + #define E6_COOLSTEP_SEUP 2 + #define E6_COOLSTEP_SEDN 0 + #define E6_COOLSTEP_SEIMIN 1 + #endif + + #if AXIS_HAS_COOLSTEP(E7) + #define E7_COOLSTEP_SPEED_THRESHOLD 5 + #define E7_COOLSTEP_LOWER_LOAD_THRESHOLD 7 + #define E7_COOLSTEP_UPPER_LOAD_THRESHOLD 0 + #define E7_COOLSTEP_SEUP 2 + #define E7_COOLSTEP_SEDN 0 + #define E7_COOLSTEP_SEIMIN 1 + #endif + /** * Use StallGuard2 to home / probe X, Y, Z. * diff --git a/Marlin/src/HAL/HAL_AVR/inc/SanityCheck.h b/Marlin/src/HAL/HAL_AVR/inc/SanityCheck.h index d24a2781c0..87864bcaf6 100644 --- a/Marlin/src/HAL/HAL_AVR/inc/SanityCheck.h +++ b/Marlin/src/HAL/HAL_AVR/inc/SanityCheck.h @@ -60,6 +60,6 @@ #error "TMCStepper includes SoftwareSerial.h which is incompatible with ENDSTOP_INTERRUPTS_FEATURE. Disable ENDSTOP_INTERRUPTS_FEATURE to continue." #endif -#if TMC_HAS_SW_SERIAL && ENABLED(MONITOR_DRIVER_STATUS) +#if HAS_TMC_SW_SERIAL && ENABLED(MONITOR_DRIVER_STATUS) #error "MONITOR_DRIVER_STATUS causes performance issues when used with SoftwareSerial-connected drivers. Disable MONITOR_DRIVER_STATUS or use hardware serial to continue." #endif diff --git a/Marlin/src/HAL/HAL_DUE/inc/SanityCheck.h b/Marlin/src/HAL/HAL_DUE/inc/SanityCheck.h index 0de4e705bd..0f7be7955f 100644 --- a/Marlin/src/HAL/HAL_DUE/inc/SanityCheck.h +++ b/Marlin/src/HAL/HAL_DUE/inc/SanityCheck.h @@ -56,6 +56,6 @@ #error "FAST_PWM_FAN is not yet implemented for this platform." #endif -#if TMC_HAS_SW_SERIAL +#if HAS_TMC_SW_SERIAL #error "TMC220x Software Serial is not supported on this platform." #endif diff --git a/Marlin/src/HAL/HAL_ESP32/inc/SanityCheck.h b/Marlin/src/HAL/HAL_ESP32/inc/SanityCheck.h index 9f19fd920b..b6ad7a3c4b 100644 --- a/Marlin/src/HAL/HAL_ESP32/inc/SanityCheck.h +++ b/Marlin/src/HAL/HAL_ESP32/inc/SanityCheck.h @@ -29,7 +29,7 @@ #error "FAST_PWM_FAN is not yet implemented for this platform." #endif -#if TMC_HAS_SW_SERIAL +#if HAS_TMC_SW_SERIAL #error "TMC220x Software Serial is not supported on this platform." #endif diff --git a/Marlin/src/HAL/HAL_LINUX/inc/SanityCheck.h b/Marlin/src/HAL/HAL_LINUX/inc/SanityCheck.h index 9898c01db4..a3238b088b 100644 --- a/Marlin/src/HAL/HAL_LINUX/inc/SanityCheck.h +++ b/Marlin/src/HAL/HAL_LINUX/inc/SanityCheck.h @@ -34,6 +34,6 @@ #error "FAST_PWM_FAN is not yet implemented for this platform." #endif -#if TMC_HAS_SW_SERIAL +#if HAS_TMC_SW_SERIAL #error "TMC220x Software Serial is not supported on this platform." #endif diff --git a/Marlin/src/HAL/HAL_SAMD51/inc/SanityCheck.h b/Marlin/src/HAL/HAL_SAMD51/inc/SanityCheck.h index 163bf1278c..d0bc2275bf 100644 --- a/Marlin/src/HAL/HAL_SAMD51/inc/SanityCheck.h +++ b/Marlin/src/HAL/HAL_SAMD51/inc/SanityCheck.h @@ -47,6 +47,6 @@ #warning "Did you activate the SmartEEPROM? See https://github.com/GMagician/SAMD51-SmartEEprom-Activator" #endif -#if TMC_HAS_SW_SERIAL +#if HAS_TMC_SW_SERIAL #error "TMC220x Software Serial is not supported on this platform." #endif diff --git a/Marlin/src/HAL/HAL_STM32/HAL.cpp b/Marlin/src/HAL/HAL_STM32/HAL.cpp index f21ec53ce4..5d8c686af3 100644 --- a/Marlin/src/HAL/HAL_STM32/HAL.cpp +++ b/Marlin/src/HAL/HAL_STM32/HAL.cpp @@ -28,7 +28,7 @@ #include "../../inc/MarlinConfig.h" #include "../shared/Delay.h" -#if TMC_HAS_SW_SERIAL +#if HAS_TMC_SW_SERIAL #include "SoftwareSerial.h" #endif @@ -87,7 +87,7 @@ void HAL_init() { while (!LL_PWR_IsActiveFlag_BRR()); #endif // EEPROM_EMULATED_SRAM - #if TMC_HAS_SW_SERIAL + #if HAS_TMC_SW_SERIAL SoftwareSerial::setInterruptPriority(SWSERIAL_TIMER_IRQ_PRIO, 0); #endif } diff --git a/Marlin/src/HAL/HAL_STM32F1/inc/SanityCheck.h b/Marlin/src/HAL/HAL_STM32F1/inc/SanityCheck.h index 25e5d0f1f8..b8ebc446d6 100644 --- a/Marlin/src/HAL/HAL_STM32F1/inc/SanityCheck.h +++ b/Marlin/src/HAL/HAL_STM32F1/inc/SanityCheck.h @@ -37,7 +37,7 @@ #error "FAST_PWM_FAN is not yet implemented for this platform." #endif -#if !defined(HAVE_SW_SERIAL) && TMC_HAS_SW_SERIAL +#if !defined(HAVE_SW_SERIAL) && HAS_TMC_SW_SERIAL #warning "With TMC2208/9 consider using SoftwareSerialM with HAVE_SW_SERIAL and appropriate SS_TIMER." #error "Missing SoftwareSerial implementation." #endif diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/inc/SanityCheck.h b/Marlin/src/HAL/HAL_STM32_F4_F7/inc/SanityCheck.h index 058c8d9dde..e04258fa07 100644 --- a/Marlin/src/HAL/HAL_STM32_F4_F7/inc/SanityCheck.h +++ b/Marlin/src/HAL/HAL_STM32_F4_F7/inc/SanityCheck.h @@ -36,6 +36,6 @@ #error "FAST_PWM_FAN is not yet implemented for this platform." #endif -#if TMC_HAS_SW_SERIAL +#if HAS_TMC_SW_SERIAL #error "TMC220x Software Serial is not supported on this platform." #endif diff --git a/Marlin/src/HAL/HAL_TEENSY31_32/inc/SanityCheck.h b/Marlin/src/HAL/HAL_TEENSY31_32/inc/SanityCheck.h index 04efaaa670..9268868596 100644 --- a/Marlin/src/HAL/HAL_TEENSY31_32/inc/SanityCheck.h +++ b/Marlin/src/HAL/HAL_TEENSY31_32/inc/SanityCheck.h @@ -33,6 +33,6 @@ #error "FAST_PWM_FAN is not yet implemented for this platform." #endif -#if TMC_HAS_SW_SERIAL +#if HAS_TMC_SW_SERIAL #error "TMC220x Software Serial is not supported on this platform." #endif diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/inc/SanityCheck.h b/Marlin/src/HAL/HAL_TEENSY35_36/inc/SanityCheck.h index 37ef55e02d..f42bd63b17 100644 --- a/Marlin/src/HAL/HAL_TEENSY35_36/inc/SanityCheck.h +++ b/Marlin/src/HAL/HAL_TEENSY35_36/inc/SanityCheck.h @@ -33,6 +33,6 @@ #error "FAST_PWM_FAN is not yet implemented for this platform." #endif -#if TMC_HAS_SW_SERIAL +#if HAS_TMC_SW_SERIAL #error "TMC220x Software Serial is not supported on this platform." #endif diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index bb418b1e9d..08b9e8a162 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -892,7 +892,7 @@ void setup() { SERIAL_ECHOLNPGM("start"); SERIAL_ECHO_START(); - #if TMC_HAS_SPI + #if HAS_TMC_SPI #if DISABLED(TMC_USE_SW_SPI) SPI.begin(); #endif diff --git a/Marlin/src/core/drivers.h b/Marlin/src/core/drivers.h index 7e0f3b6551..a9a3d5bcc4 100644 --- a/Marlin/src/core/drivers.h +++ b/Marlin/src/core/drivers.h @@ -52,7 +52,7 @@ #define _TMC5160_STANDALONE 0x5160B #define _DRIVER_ID(V) _CAT(_, V) -#define _AXIS_DRIVER_TYPE(A,T) (_DRIVER_ID(A##_DRIVER_TYPE) == _CAT(_, T)) +#define _AXIS_DRIVER_TYPE(A,T) (_DRIVER_ID(A##_DRIVER_TYPE) == _DRIVER_ID(T)) #define AXIS_DRIVER_TYPE_X(T) _AXIS_DRIVER_TYPE(X,T) #define AXIS_DRIVER_TYPE_Y(T) _AXIS_DRIVER_TYPE(Y,T) @@ -148,19 +148,32 @@ || AXIS_DRIVER_TYPE(A,TMC5130) \ || AXIS_DRIVER_TYPE(A,TMC5160) ) +#define AXIS_HAS_SG_RESULT(A) ( AXIS_DRIVER_TYPE(A,TMC2130) \ + || AXIS_DRIVER_TYPE(A,TMC2160) \ + || AXIS_DRIVER_TYPE(A,TMC2208) \ + || AXIS_DRIVER_TYPE(A,TMC2209) ) + +#define AXIS_HAS_COOLSTEP(A) ( AXIS_DRIVER_TYPE(A,TMC2130) \ + || AXIS_DRIVER_TYPE(A,TMC2209) \ + || AXIS_DRIVER_TYPE(A,TMC5130) \ + || AXIS_DRIVER_TYPE(A,TMC5160) ) + +#define _OR_EAH(N,T) || AXIS_HAS_##T(E##N) +#define E_AXIS_HAS(T) (0 RREPEAT2(E_STEPPERS, _OR_EAH, T)) + #define ANY_AXIS_HAS(T) ( AXIS_HAS_##T(X) || AXIS_HAS_##T(X2) \ || AXIS_HAS_##T(Y) || AXIS_HAS_##T(Y2) \ || AXIS_HAS_##T(Z) || AXIS_HAS_##T(Z2) \ - || AXIS_HAS_##T(Z3) \ - || AXIS_HAS_##T(E0) || AXIS_HAS_##T(E1) \ - || AXIS_HAS_##T(E2) || AXIS_HAS_##T(E3) \ - || AXIS_HAS_##T(E4) || AXIS_HAS_##T(E5) \ - || AXIS_HAS_##T(E6) || AXIS_HAS_##T(E7) ) + || AXIS_HAS_##T(Z3) || AXIS_HAS_##T(Z4) \ + || E_AXIS_HAS(T) ) #define HAS_STEALTHCHOP ANY_AXIS_HAS(STEALTHCHOP) #define HAS_STALLGUARD ANY_AXIS_HAS(STALLGUARD) -#define TMC_HAS_SPI ANY_AXIS_HAS(SPI) -#define TMC_HAS_SW_SERIAL ANY_AXIS_HAS(SW_SERIAL) +#define HAS_SG_RESULT ANY_AXIS_HAS(SG_RESULT) +#define HAS_COOLSTEP ANY_AXIS_HAS(COOLSTEP) +#define HAS_TMC_UART ANY_AXIS_HAS(UART) +#define HAS_TMC_SPI ANY_AXIS_HAS(SPI) +#define HAS_TMC_SW_SERIAL ANY_AXIS_HAS(SW_SERIAL) // // Stretching 'drivers.h' to include LPC/SAMD51 SD options diff --git a/Marlin/src/feature/tmc_util.cpp b/Marlin/src/feature/tmc_util.cpp index c09939173a..11a81559df 100644 --- a/Marlin/src/feature/tmc_util.cpp +++ b/Marlin/src/feature/tmc_util.cpp @@ -629,6 +629,15 @@ default: break; } } + + #if HAS_DRIVER(TMC2209) + static void _tmc_parse_drv_status(TMC2209Stepper &st, const TMC_drv_status_enum i) { + switch (i) { + case TMC_SG_RESULT: SERIAL_PRINT(st.SG_RESULT(), DEC); break; + default: _tmc_parse_drv_status(static_cast(st), i); break; + } + } + #endif #endif #if HAS_DRIVER(TMC2660) @@ -891,24 +900,24 @@ TMC_REPORT("stealthChop", TMC_STEALTHCHOP); TMC_REPORT("msteps\t", TMC_MICROSTEPS); TMC_REPORT("tstep\t", TMC_TSTEP); - TMC_REPORT("pwm\nthreshold", TMC_TPWMTHRS); + TMC_REPORT("PWM thresh.", TMC_TPWMTHRS); TMC_REPORT("[mm/s]\t", TMC_TPWMTHRS_MMS); TMC_REPORT("OT prewarn", TMC_OTPW); #if ENABLED(MONITOR_DRIVER_STATUS) - TMC_REPORT("OT prewarn has\n" - "been triggered", TMC_OTPW_TRIGGERED); + TMC_REPORT("triggered\n OTP\t", TMC_OTPW_TRIGGERED); #endif TMC_REPORT("off time", TMC_TOFF); TMC_REPORT("blank time", TMC_TBL); - TMC_REPORT("hysteresis\n-end\t", TMC_HEND); - TMC_REPORT("-start\t", TMC_HSTRT); + TMC_REPORT("hysteresis\n -end\t", TMC_HEND); + TMC_REPORT(" -start\t", TMC_HSTRT); TMC_REPORT("Stallguard thrs", TMC_SGT); - DRV_REPORT("DRVSTATUS", TMC_DRV_CODES); - #if HAS_TMCX1X0 - DRV_REPORT("stallguard\t", TMC_STALLGUARD); + #if HAS_TMCX1X0 || HAS_TMC220x DRV_REPORT("sg_result", TMC_SG_RESULT); - DRV_REPORT("fsactive\t", TMC_FSACTIVE); + #endif + #if HAS_TMCX1X0 + DRV_REPORT("stallguard", TMC_STALLGUARD); + DRV_REPORT("fsactive", TMC_FSACTIVE); #endif DRV_REPORT("stst\t", TMC_STST); DRV_REPORT("olb\t", TMC_OLB); @@ -1103,7 +1112,7 @@ #endif // USE_SENSORLESS -#if TMC_HAS_SPI +#if HAS_TMC_SPI #define SET_CS_PIN(st) OUT_WRITE(st##_CS_PIN, HIGH) void tmc_init_cs_pins() { #if AXIS_HAS_SPI(X) @@ -1155,7 +1164,7 @@ SET_CS_PIN(E7); #endif } -#endif // TMC_HAS_SPI +#endif // HAS_TMC_SPI template static bool test_connection(TMC &st) { diff --git a/Marlin/src/feature/tmc_util.h b/Marlin/src/feature/tmc_util.h index 2c0a87703e..584076e478 100644 --- a/Marlin/src/feature/tmc_util.h +++ b/Marlin/src/feature/tmc_util.h @@ -110,6 +110,7 @@ class TMCMarlin : public TMC, public TMCStorage { inline void refresh_stepping_mode() { this->en_pwm_mode(this->stored.stealthChop_enabled); } inline bool get_stealthChop_status() { return this->en_pwm_mode(); } #endif + #if ENABLED(HYBRID_THRESHOLD) uint32_t get_pwm_thrs() { return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]); @@ -121,6 +122,7 @@ class TMCMarlin : public TMC, public TMCStorage { #endif } #endif + #if USE_SENSORLESS inline int16_t homing_threshold() { return TMC::sgt(); } void homing_threshold(int16_t sgt_val) { @@ -135,6 +137,13 @@ class TMCMarlin : public TMC, public TMCStorage { #endif #endif + uint32_t get_cool_thrs() { + return _tmc_thrs(this->microsteps(), this->TCOOLTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]); + } + void set_cool_thrs(const uint32_t thrs) { + TMC::TCOOLTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID])); + } + #if HAS_LCD_MENU inline void refresh_stepper_current() { rms_current(this->val_mA); } @@ -149,6 +158,7 @@ class TMCMarlin : public TMC, public TMCStorage { static constexpr int8_t sgt_min = -64, sgt_max = 63; }; + template class TMCMarlin : public TMC2208Stepper, public TMCStorage { public: @@ -172,6 +182,7 @@ class TMCMarlin : public TMC220 inline void refresh_stepping_mode() { en_spreadCycle(!this->stored.stealthChop_enabled); } inline bool get_stealthChop_status() { return !this->en_spreadCycle(); } #endif + #if ENABLED(HYBRID_THRESHOLD) uint32_t get_pwm_thrs() { return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]); @@ -217,6 +228,7 @@ class TMCMarlin : public TMC220 inline void refresh_stepping_mode() { en_spreadCycle(!this->stored.stealthChop_enabled); } inline bool get_stealthChop_status() { return !this->en_spreadCycle(); } #endif + #if ENABLED(HYBRID_THRESHOLD) uint32_t get_pwm_thrs() { return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]); @@ -228,6 +240,14 @@ class TMCMarlin : public TMC220 #endif } #endif + + uint32_t get_cool_thrs() { + return _tmc_thrs(this->microsteps(), this->TCOOLTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]); + } + void set_cool_thrs(const uint32_t thrs) { + TMC2209Stepper::TCOOLTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID])); + } + #if USE_SENSORLESS inline int16_t homing_threshold() { return TMC2209Stepper::SGTHRS(); } void homing_threshold(int16_t sgt_val) { @@ -241,7 +261,6 @@ class TMCMarlin : public TMC220 #if HAS_LCD_MENU inline void refresh_stepper_current() { rms_current(this->val_mA); } - #if ENABLED(HYBRID_THRESHOLD) inline void refresh_hybrid_thrs() { set_pwm_thrs(this->stored.hybrid_thrs); } #endif @@ -391,7 +410,7 @@ void test_tmc_connection(const bool test_x, const bool test_y, const bool test_z #endif // USE_SENSORLESS -#if TMC_HAS_SPI +#if HAS_TMC_SPI void tmc_init_cs_pins(); #endif diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index ed5ddce34d..7d7592cb19 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -2040,6 +2040,62 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS #error "LED_USER_PRESET_STARTUP is required for FYSETC_MINI_12864 2.x displays." #endif +/** + * Make sure CoolStep settings exist + */ +#if HAS_COOLSTEP + #define NEEDS_COOLSTEP(A) AXIS_HAS_COOLSTEP(A) && !(defined(A##_COOLSTEP_SPEED_THRESHOLD) && defined(A##_COOLSTEP_LOWER_LOAD_THRESHOLD) && defined(A##_COOLSTEP_UPPER_LOAD_THRESHOLD) && defined(A##_COOLSTEP_SEUP) && defined(A##_COOLSTEP_SEDN) && defined(A##_COOLSTEP_SEIMIN)) + #if NEEDS_COOLSTEP(X) + #error "X COOLSTEP settings must be defined in Configuration_adv.h." + #endif + #if NEEDS_COOLSTEP(X2) + #error "X2 COOLSTEP settings must be defined in Configuration_adv.h." + #endif + #if NEEDS_COOLSTEP(Y) + #error "Y COOLSTEP settings must be defined in Configuration_adv.h." + #endif + #if NEEDS_COOLSTEP(Y2) + #error "Y2 COOLSTEP settings must be defined in Configuration_adv.h." + #endif + #if NEEDS_COOLSTEP(Z) + #error "Z COOLSTEP settings must be defined in Configuration_adv.h." + #endif + #if NEEDS_COOLSTEP(Z2) + #error "Z2 COOLSTEP settings must be defined in Configuration_adv.h." + #endif + #if NEEDS_COOLSTEP(Z3) + #error "Z3 COOLSTEP settings must be defined in Configuration_adv.h." + #endif + #if NEEDS_COOLSTEP(Z4) + #error "Z4 COOLSTEP settings must be defined in Configuration_adv.h." + #endif + #if NEEDS_COOLSTEP(E0) + #error "E0 COOLSTEP settings must be defined in Configuration_adv.h." + #endif + #if NEEDS_COOLSTEP(E1) + #error "E1 COOLSTEP settings must be defined in Configuration_adv.h." + #endif + #if NEEDS_COOLSTEP(E2) + #error "E2 COOLSTEP settings must be defined in Configuration_adv.h." + #endif + #if NEEDS_COOLSTEP(E3) + #error "E3 COOLSTEP settings must be defined in Configuration_adv.h." + #endif + #if NEEDS_COOLSTEP(E4) + #error "E4 COOLSTEP settings must be defined in Configuration_adv.h." + #endif + #if NEEDS_COOLSTEP(E5) + #error "E5 COOLSTEP settings must be defined in Configuration_adv.h." + #endif + #if NEEDS_COOLSTEP(E6) + #error "E6 COOLSTEP settings must be defined in Configuration_adv.h." + #endif + #if NEEDS_COOLSTEP(E7) + #error "E7 COOLSTEP settings must be defined in Configuration_adv.h." + #endif + #undef NEEDS_COOLSTEP +#endif + /** * Check existing CS pins against enabled TMC SPI drivers. */ @@ -2650,6 +2706,6 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2) * Check to make sure MONITOR_DRIVER_STATUS isn't enabled * on boards where TMC drivers share the SPI bus with SD. */ -#if TMC_HAS_SPI && ALL(MONITOR_DRIVER_STATUS, SDSUPPORT, USES_SHARED_SPI) +#if HAS_TMC_SPI && ALL(MONITOR_DRIVER_STATUS, SDSUPPORT, USES_SHARED_SPI) #error "MONITOR_DRIVER_STATUS and SDSUPPORT cannot be used together on boards with shared SPI." #endif diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index dcc13eca58..c739abe26a 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -1496,7 +1496,7 @@ void Stepper::stepper_pulse_phase_isr() { #define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP #define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN - // Determine if pulses are needed + // Determine if a pulse is needed using Bresenham #define PULSE_PREP(AXIS) do{ \ delta_error[_AXIS(AXIS)] += advance_dividend[_AXIS(AXIS)]; \ step_needed[_AXIS(AXIS)] = (delta_error[_AXIS(AXIS)] >= 0); \ diff --git a/Marlin/src/module/stepper/trinamic.cpp b/Marlin/src/module/stepper/trinamic.cpp index 69eaaa5c5c..a9f6f08f48 100644 --- a/Marlin/src/module/stepper/trinamic.cpp +++ b/Marlin/src/module/stepper/trinamic.cpp @@ -36,7 +36,19 @@ #include enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E }; -#define _TMC_INIT(ST, STEALTH_INDEX) tmc_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, stealthchop_by_axis[STEALTH_INDEX]) +#define _TMC_INIT_1(ST, STEALTH_INDEX) tmc_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS) +#define _TMC_INIT_2(ST, STEALTH_INDEX) tmc_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, stealthchop_by_axis[STEALTH_INDEX], ST##_HYBRID_THRESHOLD) +#define _TMC_INIT_3(ST, STEALTH_INDEX) tmc_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, stealthchop_by_axis[STEALTH_INDEX], ST##_HYBRID_THRESHOLD, ST##_COOLSTEP_SPEED_THRESHOLD, ST##_COOLSTEP_LOWER_LOAD_THRESHOLD, ST##_COOLSTEP_UPPER_LOAD_THRESHOLD, ST##_COOLSTEP_SEUP, ST##_COOLSTEP_SEDN, ST##_COOLSTEP_SEIMIN) +#define _TMC_INIT_TMC2660(ST, STEALTH_INDEX) _TMC_INIT_1(ST, STEALTH_INDEX) +#define _TMC_INIT_TMC2160(ST, STEALTH_INDEX) _TMC_INIT_2(ST, STEALTH_INDEX) +#define _TMC_INIT_TMC2208(ST, STEALTH_INDEX) _TMC_INIT_2(ST, STEALTH_INDEX) +#define _TMC_INIT_TMC5130(ST, STEALTH_INDEX) _TMC_INIT_3(ST, STEALTH_INDEX) +#define _TMC_INIT_TMC5160(ST, STEALTH_INDEX) _TMC_INIT_3(ST, STEALTH_INDEX) +#define _TMC_INIT_TMC2130(ST, STEALTH_INDEX) _TMC_INIT_3(ST, STEALTH_INDEX) +#define _TMC_INIT_TMC2209(ST, STEALTH_INDEX) _TMC_INIT_3(ST, STEALTH_INDEX) +#define __TMC_INIT(DRV, ST, STEALTH_INDEX) _TMC_INIT_##DRV(ST, STEALTH_INDEX) +#define _TMC_INIT(DRV, ST, STEALTH_INDEX) __TMC_INIT(DRV, ST, STEALTH_INDEX) +#define TMC_INIT(ST, STEALTH_INDEX) _TMC_INIT(ST##_DRIVER_TYPE, ST, STEALTH_INDEX) // IC = TMC model number // ST = Stepper object letter @@ -122,7 +134,19 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E }; #if HAS_DRIVER(TMC2130) template - void tmc_init(TMCMarlin &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const bool stealth) { + void tmc_init( + TMCMarlin &st, + const uint16_t mA, + const uint16_t microsteps, + const bool stealth, + const uint32_t hyb_thrs, + const uint32_t cool_thrs, + const uint8_t cool_semin, + const uint8_t cool_semax, + const uint8_t cool_seup, + const uint8_t cool_sedn, + const bool cool_seimin + ) { st.begin(); CHOPCONF_t chopconf{0}; @@ -152,18 +176,33 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E }; st.PWMCONF(pwmconf.sr); #if ENABLED(HYBRID_THRESHOLD) - st.set_pwm_thrs(thrs); + st.set_pwm_thrs(hyb_thrs); #else - UNUSED(thrs); + UNUSED(hyb_thrs); #endif + st.set_cool_thrs(cool_thrs); // (mm/s) + COOLCONF_t coolconf{0}; + coolconf.semin = cool_semin; + coolconf.semax = cool_semax; + coolconf.seup = cool_seup; + coolconf.sedn = cool_sedn; + coolconf.seimin = cool_seimin; + st.COOLCONF(coolconf.sr); + st.GSTAT(); // Clear GSTAT } #endif // TMC2130 #if HAS_DRIVER(TMC2160) template - void tmc_init(TMCMarlin &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const bool stealth) { + void tmc_init( + TMCMarlin &st, + const uint16_t mA, + const uint16_t microsteps, + const bool stealth, + const uint32_t hyb_thrs + ) { st.begin(); CHOPCONF_t chopconf{0}; @@ -196,9 +235,9 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E }; st.PWMCONF(pwmconf.sr); #if ENABLED(HYBRID_THRESHOLD) - st.set_pwm_thrs(thrs); + st.set_pwm_thrs(hyb_thrs); #else - UNUSED(thrs); + UNUSED(hyb_thrs); #endif st.GSTAT(); // Clear GSTAT @@ -440,7 +479,13 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E }; #if HAS_DRIVER(TMC2208) template - void tmc_init(TMCMarlin &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const bool stealth) { + void tmc_init( + TMCMarlin &st, + const uint16_t mA, + const uint16_t microsteps, + const bool stealth, + const uint32_t hyb_thrs + ) { TMC2208_n::GCONF_t gconf{0}; gconf.pdn_disable = true; // Use UART gconf.mstep_reg_select = true; // Select microsteps with UART @@ -476,9 +521,9 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E }; st.PWMCONF(pwmconf.sr); #if ENABLED(HYBRID_THRESHOLD) - st.set_pwm_thrs(thrs); + st.set_pwm_thrs(hyb_thrs); #else - UNUSED(thrs); + UNUSED(hyb_thrs); #endif st.GSTAT(0b111); // Clear @@ -488,7 +533,19 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E }; #if HAS_DRIVER(TMC2209) template - void tmc_init(TMCMarlin &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const bool stealth) { + void tmc_init( + TMCMarlin &st, + const uint16_t mA, + const uint16_t microsteps, + const bool stealth, + const uint32_t hyb_thrs, + const uint32_t cool_thrs, + const uint8_t cool_semin, + const uint8_t cool_semax, + const uint8_t cool_seup, + const uint8_t cool_sedn, + const bool cool_seimin + ) { TMC2208_n::GCONF_t gconf{0}; gconf.pdn_disable = true; // Use UART gconf.mstep_reg_select = true; // Select microsteps with UART @@ -524,11 +581,20 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E }; st.PWMCONF(pwmconf.sr); #if ENABLED(HYBRID_THRESHOLD) - st.set_pwm_thrs(thrs); + st.set_pwm_thrs(hyb_thrs); #else - UNUSED(thrs); + UNUSED(hyb_thrs); #endif + st.set_cool_thrs(cool_thrs); // (mm/s) + COOLCONF_t coolconf{0}; + coolconf.semin = cool_semin; + coolconf.semax = cool_semax; + coolconf.seup = cool_seup; + coolconf.sedn = cool_sedn; + coolconf.seimin = cool_seimin; + st.COOLCONF(coolconf.sr); + st.GSTAT(0b111); // Clear delay(200); } @@ -536,7 +602,11 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E }; #if HAS_DRIVER(TMC2660) template - void tmc_init(TMCMarlin &st, const uint16_t mA, const uint16_t microsteps, const uint32_t, const bool) { + void tmc_init( + TMCMarlin &st, + const uint16_t mA, + const uint16_t microsteps + ) { st.begin(); TMC2660_n::CHOPCONF_t chopconf{0}; @@ -563,7 +633,19 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E }; #if HAS_DRIVER(TMC5130) template - void tmc_init(TMCMarlin &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const bool stealth) { + void tmc_init( + TMCMarlin &st, + const uint16_t mA, + const uint16_t microsteps, + const bool stealth, + const uint32_t hyb_thrs, + const uint32_t cool_thrs, + const uint8_t cool_semin, + const uint8_t cool_semax, + const uint8_t cool_seup, + const uint8_t cool_sedn, + const bool cool_seimin + ) { st.begin(); CHOPCONF_t chopconf{0}; @@ -593,18 +675,39 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E }; st.PWMCONF(pwmconf.sr); #if ENABLED(HYBRID_THRESHOLD) - st.set_pwm_thrs(thrs); + st.set_pwm_thrs(hyb_thrs); #else - UNUSED(thrs); + UNUSED(hyb_thrs); #endif + st.set_cool_thrs(cool_thrs); // (mm/s) + COOLCONF_t coolconf{0}; + coolconf.semin = cool_semin; + coolconf.semax = cool_semax; + coolconf.seup = cool_seup; + coolconf.sedn = cool_sedn; + coolconf.seimin = cool_seimin; + st.COOLCONF(coolconf.sr); + st.GSTAT(); // Clear GSTAT } #endif // TMC5130 #if HAS_DRIVER(TMC5160) template - void tmc_init(TMCMarlin &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const bool stealth) { + void tmc_init( + TMCMarlin &st, + const uint16_t mA, + const uint16_t microsteps, + const bool stealth, + const uint32_t hyb_thrs, + const uint32_t cool_thrs, + const uint8_t cool_semin, + const uint8_t cool_semax, + const uint8_t cool_seup, + const uint8_t cool_sedn, + const bool cool_seimin + ) { st.begin(); CHOPCONF_t chopconf{0}; @@ -637,10 +740,20 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E }; st.PWMCONF(pwmconf.sr); #if ENABLED(HYBRID_THRESHOLD) - st.set_pwm_thrs(thrs); + st.set_pwm_thrs(hyb_thrs); #else - UNUSED(thrs); + UNUSED(hyb_thrs); #endif + + st.set_cool_thrs(cool_thrs); // (mm/s) + COOLCONF_t coolconf{0}; + coolconf.semin = cool_semin; + coolconf.semax = cool_semax; + coolconf.seup = cool_seup; + coolconf.sedn = cool_sedn; + coolconf.seimin = cool_seimin; + st.COOLCONF(coolconf.sr); + st.GSTAT(); // Clear GSTAT } #endif // TMC5160 @@ -718,52 +831,52 @@ void reset_trinamic_drivers() { }; #if AXIS_IS_TMC(X) - _TMC_INIT(X, STEALTH_AXIS_XY); + TMC_INIT(X, STEALTH_AXIS_XY); #endif #if AXIS_IS_TMC(X2) - _TMC_INIT(X2, STEALTH_AXIS_XY); + TMC_INIT(X2, STEALTH_AXIS_XY); #endif #if AXIS_IS_TMC(Y) - _TMC_INIT(Y, STEALTH_AXIS_XY); + TMC_INIT(Y, STEALTH_AXIS_XY); #endif #if AXIS_IS_TMC(Y2) - _TMC_INIT(Y2, STEALTH_AXIS_XY); + TMC_INIT(Y2, STEALTH_AXIS_XY); #endif #if AXIS_IS_TMC(Z) - _TMC_INIT(Z, STEALTH_AXIS_Z); + TMC_INIT(Z, STEALTH_AXIS_Z); #endif #if AXIS_IS_TMC(Z2) - _TMC_INIT(Z2, STEALTH_AXIS_Z); + TMC_INIT(Z2, STEALTH_AXIS_Z); #endif #if AXIS_IS_TMC(Z3) - _TMC_INIT(Z3, STEALTH_AXIS_Z); + TMC_INIT(Z3, STEALTH_AXIS_Z); #endif #if AXIS_IS_TMC(Z4) - _TMC_INIT(Z4, STEALTH_AXIS_Z); + TMC_INIT(Z4, STEALTH_AXIS_Z); #endif #if AXIS_IS_TMC(E0) - _TMC_INIT(E0, STEALTH_AXIS_E); + TMC_INIT(E0, STEALTH_AXIS_E); #endif #if AXIS_IS_TMC(E1) - _TMC_INIT(E1, STEALTH_AXIS_E); + TMC_INIT(E1, STEALTH_AXIS_E); #endif #if AXIS_IS_TMC(E2) - _TMC_INIT(E2, STEALTH_AXIS_E); + TMC_INIT(E2, STEALTH_AXIS_E); #endif #if AXIS_IS_TMC(E3) - _TMC_INIT(E3, STEALTH_AXIS_E); + TMC_INIT(E3, STEALTH_AXIS_E); #endif #if AXIS_IS_TMC(E4) - _TMC_INIT(E4, STEALTH_AXIS_E); + TMC_INIT(E4, STEALTH_AXIS_E); #endif #if AXIS_IS_TMC(E5) - _TMC_INIT(E5, STEALTH_AXIS_E); + TMC_INIT(E5, STEALTH_AXIS_E); #endif #if AXIS_IS_TMC(E6) - _TMC_INIT(E6, STEALTH_AXIS_E); + TMC_INIT(E6, STEALTH_AXIS_E); #endif #if AXIS_IS_TMC(E7) - _TMC_INIT(E7, STEALTH_AXIS_E); + TMC_INIT(E7, STEALTH_AXIS_E); #endif #if USE_SENSORLESS diff --git a/Marlin/src/pins/lpc1768/pins_GMARSH_X6_REV1.h b/Marlin/src/pins/lpc1768/pins_GMARSH_X6_REV1.h index 514da67c64..28445962ac 100644 --- a/Marlin/src/pins/lpc1768/pins_GMARSH_X6_REV1.h +++ b/Marlin/src/pins/lpc1768/pins_GMARSH_X6_REV1.h @@ -82,7 +82,7 @@ // // TMC2208 UART pins // -#if HAS_DRIVER(TMC2208) +#if HAS_TMC_UART #define X_SERIAL_TX_PIN P1_00 #define X_SERIAL_RX_PIN P1_00 #define Y_SERIAL_TX_PIN P1_09 diff --git a/Marlin/src/pins/lpc1769/pins_TH3D_EZBOARD.h b/Marlin/src/pins/lpc1769/pins_TH3D_EZBOARD.h index d86558a49d..8f7d00bb3b 100644 --- a/Marlin/src/pins/lpc1769/pins_TH3D_EZBOARD.h +++ b/Marlin/src/pins/lpc1769/pins_TH3D_EZBOARD.h @@ -74,9 +74,9 @@ #define E1_DIR_PIN P2_13 #define E1_ENABLE_PIN P4_29 -#if HAS_DRIVER(TMC2208) +#if HAS_TMC_UART // - // TMC2208 stepper drivers + // TMC220x stepper drivers // Software serial // #define X_SERIAL_TX_PIN P0_04 diff --git a/Marlin/src/pins/mega/pins_MIGHTYBOARD_REVE.h b/Marlin/src/pins/mega/pins_MIGHTYBOARD_REVE.h index 929c3ee687..6d3102172b 100644 --- a/Marlin/src/pins/mega/pins_MIGHTYBOARD_REVE.h +++ b/Marlin/src/pins/mega/pins_MIGHTYBOARD_REVE.h @@ -264,11 +264,11 @@ #define SD_DETECT_PIN 9 // H6 // -//TMC 2208 +// TMC 220x // -#if HAS_DRIVER(TMC2208) +#if HAS_TMC_UART /** - * TMC2208 stepper drivers + * TMC220x stepper drivers * * Hardware serial communication ports. * If undefined software serial is used according to the pins below diff --git a/Marlin/src/pins/pins.h b/Marlin/src/pins/pins.h index 35e73e9d3f..a1c2ad6b83 100644 --- a/Marlin/src/pins/pins.h +++ b/Marlin/src/pins/pins.h @@ -1189,12 +1189,18 @@ #define _PEXI(p,q) __PEXI(p,q) #define __EPIN(p,q) E##p##_##q##_PIN #define _EPIN(p,q) __EPIN(p,q) +#define __EDRV(p) E##p##_DRIVER_TYPE +#define _EDRV(p) __EDRV(p) #define DIAG_REMAPPED(p,q) (PIN_EXISTS(q) && _EPIN(p##_E_INDEX, DIAG) == q##_PIN) // The X2 axis, if any, should be the next open extruder port #define X2_E_INDEX E_STEPPERS #if EITHER(DUAL_X_CARRIAGE, X_DUAL_STEPPER_DRIVERS) + #ifndef X2_DRIVER_TYPE + #define X2_DRIVER_TYPE _EDRV(X2_E_INDEX) + #endif + #ifndef X2_STEP_PIN #define X2_STEP_PIN _EPIN(X2_E_INDEX, STEP) #define X2_DIR_PIN _EPIN(X2_E_INDEX, DIR) @@ -1268,6 +1274,10 @@ // The Y2 axis, if any, should be the next open extruder port #if ENABLED(Y_DUAL_STEPPER_DRIVERS) + #ifndef Y2_DRIVER_TYPE + #define Y2_DRIVER_TYPE _EDRV(Y2_E_INDEX) + #endif + #ifndef Y2_STEP_PIN #define Y2_STEP_PIN _EPIN(Y2_E_INDEX, STEP) #define Y2_DIR_PIN _EPIN(Y2_E_INDEX, DIR) @@ -1336,6 +1346,10 @@ // The Z2 axis, if any, should be the next open extruder port #if NUM_Z_STEPPER_DRIVERS >= 2 + #ifndef Z2_DRIVER_TYPE + #define Z2_DRIVER_TYPE _EDRV(Z2_E_INDEX) + #endif + #ifndef Z2_STEP_PIN #define Z2_STEP_PIN _EPIN(Z2_E_INDEX, STEP) #define Z2_DIR_PIN _EPIN(Z2_E_INDEX, DIR) @@ -1403,6 +1417,10 @@ #endif #if NUM_Z_STEPPER_DRIVERS >= 3 + #ifndef Z3_DRIVER_TYPE + #define Z3_DRIVER_TYPE _EDRV(Z3_E_INDEX) + #endif + #ifndef Z3_STEP_PIN #define Z3_STEP_PIN _EPIN(Z3_E_INDEX, STEP) #define Z3_DIR_PIN _EPIN(Z3_E_INDEX, DIR) @@ -1470,6 +1488,10 @@ #endif #if NUM_Z_STEPPER_DRIVERS >= 4 + #ifndef Z4_DRIVER_TYPE + #define Z4_DRIVER_TYPE _EDRV(Z4_E_INDEX) + #endif + #ifndef Z4_STEP_PIN #define Z4_STEP_PIN _EPIN(Z4_E_INDEX, STEP) #define Z4_DIR_PIN _EPIN(Z4_E_INDEX, DIR) diff --git a/Marlin/src/pins/ramps/pins_Z_BOLT_X_SERIES.h b/Marlin/src/pins/ramps/pins_Z_BOLT_X_SERIES.h index a1005c51ec..9808646d32 100644 --- a/Marlin/src/pins/ramps/pins_Z_BOLT_X_SERIES.h +++ b/Marlin/src/pins/ramps/pins_Z_BOLT_X_SERIES.h @@ -193,9 +193,9 @@ #endif #endif -#if HAS_DRIVER(TMC2208) +#if HAS_TMC_UART /** - * TMC2208 stepper drivers + * TMC220x stepper drivers * * Hardware serial communication ports. * If undefined software serial is used according to the pins below diff --git a/Marlin/src/pins/stm32/pins_BTT_SKR_MINI_E3_V1_0.h b/Marlin/src/pins/stm32/pins_BTT_SKR_MINI_E3_V1_0.h index 461cd347a6..f909cce83a 100644 --- a/Marlin/src/pins/stm32/pins_BTT_SKR_MINI_E3_V1_0.h +++ b/Marlin/src/pins/stm32/pins_BTT_SKR_MINI_E3_V1_0.h @@ -26,10 +26,10 @@ #define BOARD_INFO_NAME "BIGTREE SKR Mini E3" /** - * TMC2209 stepper drivers + * TMC220x stepper drivers * Hardware serial communication ports. */ -#if HAS_DRIVER(TMC2209) +#if HAS_TMC_UART #define X_HARDWARE_SERIAL Serial4 #define Y_HARDWARE_SERIAL Serial4 #define Z_HARDWARE_SERIAL Serial4