From c3229e1b3461b6da8373e7a24a7eeb131912a15b Mon Sep 17 00:00:00 2001 From: teemuatlut Date: Wed, 3 Oct 2018 10:48:49 +0300 Subject: [PATCH] Migrate to a new TMC library (#11943) --- Marlin/src/Marlin.cpp | 3 + Marlin/src/core/drivers.h | 6 +- Marlin/src/core/language.h | 5 + Marlin/src/feature/tmc_util.cpp | 288 ++++------- Marlin/src/feature/tmc_util.h | 169 ++++--- Marlin/src/gcode/feature/trinamic/M906.cpp | 2 +- .../src/gcode/feature/trinamic/M911-M915.cpp | 250 +++++----- Marlin/src/gcode/gcode.cpp | 6 +- Marlin/src/gcode/gcode.h | 6 +- Marlin/src/inc/Conditionals_post.h | 9 +- Marlin/src/module/configuration_store.cpp | 450 ++++++++---------- Marlin/src/module/stepper_indirection.cpp | 406 +++++++--------- Marlin/src/module/stepper_indirection.h | 125 ++--- platformio.ini | 10 +- 14 files changed, 781 insertions(+), 954 deletions(-) diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp index 299adbec3..931717ff1 100644 --- a/Marlin/src/Marlin.cpp +++ b/Marlin/src/Marlin.cpp @@ -736,6 +736,9 @@ void setup() { SERIAL_ECHO_START(); #if HAS_DRIVER(TMC2130) + #if DISABLED(TMC_USE_SW_SPI) + SPI.begin(); + #endif tmc_init_cs_pins(); #endif #if HAS_DRIVER(TMC2208) diff --git a/Marlin/src/core/drivers.h b/Marlin/src/core/drivers.h index e775c58b5..15a449935 100644 --- a/Marlin/src/core/drivers.h +++ b/Marlin/src/core/drivers.h @@ -31,9 +31,9 @@ #define TB6560 0x006 #define TB6600 0x007 #define TMC2100 0x008 -#define TMC2130 0x109 +#define TMC2130 2130 #define TMC2130_STANDALONE 0x009 -#define TMC2208 0x10A +#define TMC2208 2208 #define TMC2208_STANDALONE 0x00A #define TMC26X 0x10B #define TMC26X_STANDALONE 0x00B @@ -45,7 +45,7 @@ #define AXIS_DRIVER_TYPE_X(T) _AXIS_DRIVER_TYPE(X,T) #define AXIS_DRIVER_TYPE_Y(T) _AXIS_DRIVER_TYPE(Y,T) #define AXIS_DRIVER_TYPE_Z(T) _AXIS_DRIVER_TYPE(Z,T) -#define AXIS_DRIVER_TYPE_X2(T) (ENABLED(X_DUAL_STEPPER_DRIVERS) || ENABLED(DUAL_X_CARRIAGE)) && _AXIS_DRIVER_TYPE(X2,T) +#define AXIS_DRIVER_TYPE_X2(T) ((ENABLED(X_DUAL_STEPPER_DRIVERS) || ENABLED(DUAL_X_CARRIAGE)) && _AXIS_DRIVER_TYPE(X2,T)) #define AXIS_DRIVER_TYPE_Y2(T) (ENABLED(Y_DUAL_STEPPER_DRIVERS) && _AXIS_DRIVER_TYPE(Y2,T)) #define AXIS_DRIVER_TYPE_Z2(T) (Z_MULTI_STEPPER_DRIVERS && _AXIS_DRIVER_TYPE(Z2,T)) #define AXIS_DRIVER_TYPE_Z3(T) (ENABLED(Z_TRIPLE_STEPPER_DRIVERS) && _AXIS_DRIVER_TYPE(Z3,T)) diff --git a/Marlin/src/core/language.h b/Marlin/src/core/language.h index 2ed63bdf9..78af20976 100644 --- a/Marlin/src/core/language.h +++ b/Marlin/src/core/language.h @@ -285,6 +285,10 @@ #define MSG_B "Y" #define MSG_C "Z" #endif +#define MSG_X2 "X2" +#define MSG_Y2 "Y2" +#define MSG_Z2 "Z2" +#define MSG_Z3 "Z3" #define MSG_H1 "1" #define MSG_H2 "2" #define MSG_H3 "3" @@ -297,6 +301,7 @@ #define MSG_N4 " 4" #define MSG_N5 " 5" #define MSG_N6 " 6" +#define MSG_E0 "E0" #define MSG_E1 "E1" #define MSG_E2 "E2" #define MSG_E3 "E3" diff --git a/Marlin/src/feature/tmc_util.cpp b/Marlin/src/feature/tmc_util.cpp index 9cc81f9df..27b170a83 100644 --- a/Marlin/src/feature/tmc_util.cpp +++ b/Marlin/src/feature/tmc_util.cpp @@ -36,8 +36,6 @@ #include "../module/planner.h" #endif -bool report_tmc_status = false; - /** * Check for over temperature or short to ground error flags. * Report and log warning of overtemperature condition. @@ -46,6 +44,8 @@ bool report_tmc_status = false; * and so we don't repeatedly report warning before the condition is cleared. */ #if ENABLED(MONITOR_DRIVER_STATUS) + static bool report_tmc_status = false; + struct TMC_driver_data { uint32_t drv_status; bool is_otpw; @@ -95,13 +95,13 @@ bool report_tmc_status = false; #endif template - void monitor_tmc_driver(TMC &st, const TMC_AxisEnum axis, uint8_t &otpw_cnt) { + void monitor_tmc_driver(TMC &st) { TMC_driver_data data = get_driver_data(st); #if ENABLED(STOP_ON_ERROR) if (data.is_error) { SERIAL_EOL(); - _tmc_say_axis(axis); + st.printLabel(); SERIAL_ECHOLNPGM(" driver error detected:"); if (data.is_ot) SERIAL_ECHOLNPGM("overtemperature"); if (st.s2ga()) SERIAL_ECHOLNPGM("short to ground (coil A)"); @@ -114,7 +114,7 @@ bool report_tmc_status = false; #endif // Report if a warning was triggered - if (data.is_otpw && otpw_cnt == 0) { + if (data.is_otpw && st.otpw_count == 0) { char timestamp[10]; duration_t elapsed = print_job_timer.duration(); const bool has_days = (elapsed.value > 60*60*24L); @@ -122,38 +122,38 @@ bool report_tmc_status = false; SERIAL_EOL(); SERIAL_ECHO(timestamp); SERIAL_ECHOPGM(": "); - _tmc_say_axis(axis); + st.printLabel(); SERIAL_ECHOPGM(" driver overtemperature warning! ("); - SERIAL_ECHO(st.getCurrent()); + SERIAL_ECHO(st.getMilliamps()); SERIAL_ECHOLNPGM("mA)"); } #if CURRENT_STEP_DOWN > 0 // Decrease current if is_otpw is true and driver is enabled and there's been more than 4 warnings - if (data.is_otpw && st.isEnabled() && otpw_cnt > 4) { - st.setCurrent(st.getCurrent() - (CURRENT_STEP_DOWN), R_SENSE, HOLD_MULTIPLIER); + if (data.is_otpw && st.isEnabled() && st.otpw_count > 4) { + st.rms_current(st.getMilliamps() - (CURRENT_STEP_DOWN)); #if ENABLED(REPORT_CURRENT_CHANGE) - _tmc_say_axis(axis); - SERIAL_ECHOLNPAIR(" current decreased to ", st.getCurrent()); + st.printLabel(); + SERIAL_ECHOLNPAIR(" current decreased to ", st.getMilliamps()); #endif } #endif if (data.is_otpw) { - otpw_cnt++; + st.otpw_count++; st.flag_otpw = true; } - else if (otpw_cnt > 0) otpw_cnt = 0; + else if (st.otpw_count > 0) st.otpw_count = 0; if (report_tmc_status) { const uint32_t pwm_scale = get_pwm_scale(st); - _tmc_say_axis(axis); + st.printLabel(); SERIAL_ECHOPAIR(":", pwm_scale); SERIAL_ECHOPGM(" |0b"); SERIAL_PRINT(get_status_response(st), BIN); SERIAL_ECHOPGM("| "); if (data.is_error) SERIAL_CHAR('E'); else if (data.is_ot) SERIAL_CHAR('O'); else if (data.is_otpw) SERIAL_CHAR('W'); - else if (otpw_cnt > 0) SERIAL_PRINT(otpw_cnt, DEC); + else if (st.otpw_count > 0) SERIAL_PRINT(st.otpw_count, DEC); else if (st.flag_otpw) SERIAL_CHAR('F'); SERIAL_CHAR('\t'); } @@ -166,56 +166,43 @@ bool report_tmc_status = false; if (ELAPSED(millis(), next_cOT)) { next_cOT = millis() + 500; #if HAS_HW_COMMS(X) - static uint8_t x_otpw_cnt = 0; - monitor_tmc_driver(stepperX, TMC_X, x_otpw_cnt); + monitor_tmc_driver(stepperX); #endif #if HAS_HW_COMMS(Y) - static uint8_t y_otpw_cnt = 0; - monitor_tmc_driver(stepperY, TMC_Y, y_otpw_cnt); + monitor_tmc_driver(stepperY); #endif #if HAS_HW_COMMS(Z) - static uint8_t z_otpw_cnt = 0; - monitor_tmc_driver(stepperZ, TMC_Z, z_otpw_cnt); + monitor_tmc_driver(stepperZ); #endif #if HAS_HW_COMMS(X2) - static uint8_t x2_otpw_cnt = 0; - monitor_tmc_driver(stepperX2, TMC_X, x2_otpw_cnt); + monitor_tmc_driver(stepperX2); #endif #if HAS_HW_COMMS(Y2) - static uint8_t y2_otpw_cnt = 0; - monitor_tmc_driver(stepperY2, TMC_Y, y2_otpw_cnt); + monitor_tmc_driver(stepperY2); #endif #if HAS_HW_COMMS(Z2) - static uint8_t z2_otpw_cnt = 0; - monitor_tmc_driver(stepperZ2, TMC_Z, z2_otpw_cnt); + monitor_tmc_driver(stepperZ2); #endif #if HAS_HW_COMMS(Z3) - static uint8_t z3_otpw_cnt = 0; - monitor_tmc_driver(stepperZ3, TMC_Z, z3_otpw_cnt); + monitor_tmc_driver(stepperZ3); #endif #if HAS_HW_COMMS(E0) - static uint8_t e0_otpw_cnt = 0; - monitor_tmc_driver(stepperE0, TMC_E0, e0_otpw_cnt); + monitor_tmc_driver(stepperE0); #endif #if HAS_HW_COMMS(E1) - static uint8_t e1_otpw_cnt = 0; - monitor_tmc_driver(stepperE1, TMC_E1, e1_otpw_cnt); + monitor_tmc_driver(stepperE1); #endif #if HAS_HW_COMMS(E2) - static uint8_t e2_otpw_cnt = 0; - monitor_tmc_driver(stepperE2, TMC_E2, e2_otpw_cnt); + monitor_tmc_driver(stepperE2); #endif #if HAS_HW_COMMS(E3) - static uint8_t e3_otpw_cnt = 0; - monitor_tmc_driver(stepperE3, TMC_E3, e3_otpw_cnt); + monitor_tmc_driver(stepperE3); #endif #if HAS_HW_COMMS(E4) - static uint8_t e4_otpw_cnt = 0; - monitor_tmc_driver(stepperE4, TMC_E4, e4_otpw_cnt); + monitor_tmc_driver(stepperE4); #endif #if HAS_HW_COMMS(E5) - static uint8_t e5_otpw_cnt = 0; - monitor_tmc_driver(stepperE5, TMC_E5, e5_otpw_cnt); + monitor_tmc_driver(stepperE5); #endif if (report_tmc_status) SERIAL_EOL(); @@ -224,100 +211,6 @@ bool report_tmc_status = false; #endif // MONITOR_DRIVER_STATUS -void _tmc_say_axis(const TMC_AxisEnum axis) { - static const char ext_X[] PROGMEM = "X", ext_Y[] PROGMEM = "Y", ext_Z[] PROGMEM = "Z" - #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(X_DUAL_STEPPER_DRIVERS) - , ext_X2[] PROGMEM = "X2" - #endif - #if ENABLED(Y_DUAL_STEPPER_DRIVERS) - , ext_Y2[] PROGMEM = "Y2" - #endif - #if Z_MULTI_STEPPER_DRIVERS - , ext_Z2[] PROGMEM = "Z2" - #if ENABLED(Z_TRIPLE_STEPPER_DRIVERS) - , ext_Z3[] PROGMEM = "Z3" - #endif - #endif - #if E_STEPPERS - , ext_E0[] PROGMEM = "E0" - #if E_STEPPERS > 1 - , ext_E1[] PROGMEM = "E1" - #if E_STEPPERS > 2 - , ext_E2[] PROGMEM = "E2" - #if E_STEPPERS > 3 - , ext_E3[] PROGMEM = "E3" - #if E_STEPPERS > 4 - , ext_E4[] PROGMEM = "E4" - #if E_STEPPERS > 5 - , ext_E5[] PROGMEM = "E5" - #endif - #endif - #endif - #endif - #endif - #endif - ; - - static PGM_P const tmc_axes[] PROGMEM = { - ext_X, ext_Y, ext_Z - #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(X_DUAL_STEPPER_DRIVERS) - , ext_X2 - #endif - #if ENABLED(Y_DUAL_STEPPER_DRIVERS) - , ext_Y2 - #endif - #if Z_MULTI_STEPPER_DRIVERS - , ext_Z2 - #if ENABLED(Z_TRIPLE_STEPPER_DRIVERS) - , ext_Z3 - #endif - #endif - #if E_STEPPERS - , ext_E0 - #if E_STEPPERS > 1 - , ext_E1 - #if E_STEPPERS > 2 - , ext_E2 - #if E_STEPPERS > 3 - , ext_E3 - #if E_STEPPERS > 4 - , ext_E4 - #if E_STEPPERS > 5 - , ext_E5 - #endif - #endif - #endif - #endif - #endif - #endif - }; - serialprintPGM((char*)pgm_read_ptr(&tmc_axes[axis])); -} - -void _tmc_say_current(const TMC_AxisEnum axis, const uint16_t curr) { - _tmc_say_axis(axis); - SERIAL_ECHOLNPAIR(" driver current: ", curr); -} -void _tmc_say_otpw(const TMC_AxisEnum axis, const bool otpw) { - _tmc_say_axis(axis); - SERIAL_ECHOPGM(" temperature prewarn triggered: "); - serialprintPGM(otpw ? PSTR("true") : PSTR("false")); - SERIAL_EOL(); -} -void _tmc_say_otpw_cleared(const TMC_AxisEnum axis) { - _tmc_say_axis(axis); - SERIAL_ECHOLNPGM(" prewarn flag cleared"); -} -void _tmc_say_pwmthrs(const TMC_AxisEnum axis, const uint32_t thrs) { - _tmc_say_axis(axis); - SERIAL_ECHOLNPAIR(" stealthChop max speed: ", thrs); -} -void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) { - _tmc_say_axis(axis); - SERIAL_ECHOPGM(" homing sensitivity: "); - SERIAL_PRINTLN(sgt, DEC); -} - #if ENABLED(TMC_DEBUG) enum TMC_debug_enum : char { @@ -366,9 +259,7 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) { TMC_S2VSB, TMC_S2VSA }; - static void drv_status_print_hex(const TMC_AxisEnum axis, const uint32_t drv_status) { - _tmc_say_axis(axis); - SERIAL_ECHOPGM(" = 0x"); + static void drv_status_print_hex(const uint32_t drv_status) { for (int B = 24; B >= 8; B -= 8){ SERIAL_PRINT((drv_status >> (B + 4)) & 0xF, HEX); SERIAL_PRINT((drv_status >> B) & 0xF, HEX); @@ -379,17 +270,19 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) { SERIAL_EOL(); } + template + static void print_vsense(TMC &st) { serialprintPGM(st.vsense() ? PSTR("1=.18") : PSTR("0=.325")); } + #if HAS_DRIVER(TMC2130) static void tmc_status(TMC2130Stepper &st, const TMC_debug_enum i) { switch (i) { case TMC_PWM_SCALE: SERIAL_PRINT(st.PWM_SCALE(), DEC); break; - case TMC_TSTEP: SERIAL_ECHO(st.TSTEP()); break; case TMC_SGT: SERIAL_PRINT(st.sgt(), DEC); break; - case TMC_STEALTHCHOP: serialprintPGM(st.stealthChop() ? PSTR("true") : PSTR("false")); break; + case TMC_STEALTHCHOP: serialprintPGM(st.en_pwm_mode() ? PSTR("true") : PSTR("false")); break; default: break; } } - static void tmc_parse_drv_status(TMC2130Stepper &st, const TMC_drv_status_enum i) { + static void _tmc_parse_drv_status(TMC2130Stepper &st, const TMC_drv_status_enum i) { switch (i) { case TMC_STALLGUARD: if (st.stallguard()) SERIAL_CHAR('X'); break; case TMC_SG_RESULT: SERIAL_PRINT(st.sg_result(), DEC); break; @@ -402,7 +295,6 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) { #if HAS_DRIVER(TMC2208) static void tmc_status(TMC2208Stepper &st, const TMC_debug_enum i) { switch (i) { - case TMC_TSTEP: { uint32_t data = 0; st.TSTEP(&data); SERIAL_PROTOCOL(data); break; } case TMC_PWM_SCALE: SERIAL_PRINT(st.pwm_scale_sum(), DEC); break; case TMC_STEALTHCHOP: serialprintPGM(st.stealth() ? PSTR("true") : PSTR("false")); break; case TMC_S2VSA: if (st.s2vsa()) SERIAL_CHAR('X'); break; @@ -410,7 +302,7 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) { default: break; } } - static void tmc_parse_drv_status(TMC2208Stepper &st, const TMC_drv_status_enum i) { + static void _tmc_parse_drv_status(TMC2208Stepper &st, const TMC_drv_status_enum i) { switch (i) { case TMC_T157: if (st.t157()) SERIAL_CHAR('X'); break; case TMC_T150: if (st.t150()) SERIAL_CHAR('X'); break; @@ -422,12 +314,12 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) { #endif template - static void tmc_status(TMC &st, const TMC_AxisEnum axis, const TMC_debug_enum i, const float spmm) { + static void tmc_status(TMC &st, const TMC_debug_enum i, const float spmm) { SERIAL_ECHO('\t'); switch (i) { - case TMC_CODES: _tmc_say_axis(axis); break; + case TMC_CODES: st.printLabel(); break; case TMC_ENABLED: serialprintPGM(st.isEnabled() ? PSTR("true") : PSTR("false")); break; - case TMC_CURRENT: SERIAL_ECHO(st.getCurrent()); break; + case TMC_CURRENT: SERIAL_ECHO(st.getMilliamps()); break; case TMC_RMS_CURRENT: SERIAL_PROTOCOL(st.rms_current()); break; case TMC_MAX_CURRENT: SERIAL_PRINT((float)st.rms_current() * 1.41, 0); break; case TMC_IRUN: @@ -442,10 +334,9 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) { SERIAL_PRINT(st.cs_actual(), DEC); SERIAL_ECHOPGM("/31"); break; - - case TMC_VSENSE: serialprintPGM(st.vsense() ? PSTR("1=.18") : PSTR("0=.325")); break; - + case TMC_VSENSE: print_vsense(st); break; case TMC_MICROSTEPS: SERIAL_ECHO(st.microsteps()); break; + case TMC_TSTEP: SERIAL_ECHO(st.TSTEP()); break; case TMC_TPWMTHRS: { uint32_t tpwmthrs_val = st.TPWMTHRS(); SERIAL_ECHO(tpwmthrs_val); @@ -470,10 +361,10 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) { } template - static void tmc_parse_drv_status(TMC &st, const TMC_AxisEnum axis, const TMC_drv_status_enum i) { + static void tmc_parse_drv_status(TMC &st, const TMC_drv_status_enum i) { SERIAL_CHAR('\t'); switch (i) { - case TMC_DRV_CODES: _tmc_say_axis(axis); break; + case TMC_DRV_CODES: st.printLabel(); break; case TMC_STST: if (st.stst()) SERIAL_CHAR('X'); break; case TMC_OLB: if (st.olb()) SERIAL_CHAR('X'); break; case TMC_OLA: if (st.ola()) SERIAL_CHAR('X'); break; @@ -482,69 +373,73 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) { case TMC_DRV_OTPW: if (st.otpw()) SERIAL_CHAR('X'); break; case TMC_OT: if (st.ot()) SERIAL_CHAR('X'); break; case TMC_DRV_CS_ACTUAL: SERIAL_PRINT(st.cs_actual(), DEC); break; - case TMC_DRV_STATUS_HEX:drv_status_print_hex(axis, st.DRV_STATUS()); break; - default: tmc_parse_drv_status(st, i); break; + case TMC_DRV_STATUS_HEX: + st.printLabel(); + SERIAL_ECHOPGM("\t0x"); + drv_status_print_hex(st.DRV_STATUS()); + break; + default: _tmc_parse_drv_status(st, i); break; } } static void tmc_debug_loop(const TMC_debug_enum i) { #if AXIS_IS_TMC(X) - tmc_status(stepperX, TMC_X, i, planner.axis_steps_per_mm[X_AXIS]); + tmc_status(stepperX, i, planner.axis_steps_per_mm[X_AXIS]); #endif #if AXIS_IS_TMC(X2) - tmc_status(stepperX2, TMC_X2, i, planner.axis_steps_per_mm[X_AXIS]); + tmc_status(stepperX2, i, planner.axis_steps_per_mm[X_AXIS]); #endif #if AXIS_IS_TMC(Y) - tmc_status(stepperY, TMC_Y, i, planner.axis_steps_per_mm[Y_AXIS]); + tmc_status(stepperY, i, planner.axis_steps_per_mm[Y_AXIS]); #endif #if AXIS_IS_TMC(Y2) - tmc_status(stepperY2, TMC_Y2, i, planner.axis_steps_per_mm[Y_AXIS]); + tmc_status(stepperY2, i, planner.axis_steps_per_mm[Y_AXIS]); #endif #if AXIS_IS_TMC(Z) - tmc_status(stepperZ, TMC_Z, i, planner.axis_steps_per_mm[Z_AXIS]); + tmc_status(stepperZ, i, planner.axis_steps_per_mm[Z_AXIS]); #endif #if AXIS_IS_TMC(Z2) - tmc_status(stepperZ2, TMC_Z2, i, planner.axis_steps_per_mm[Z_AXIS]); + tmc_status(stepperZ2, i, planner.axis_steps_per_mm[Z_AXIS]); #endif #if AXIS_IS_TMC(Z3) - tmc_status(stepperZ3, TMC_Z3, i, planner.axis_steps_per_mm[Z_AXIS]); + tmc_status(stepperZ3, i, planner.axis_steps_per_mm[Z_AXIS]); #endif #if AXIS_IS_TMC(E0) - tmc_status(stepperE0, TMC_E0, i, planner.axis_steps_per_mm[E_AXIS]); + tmc_status(stepperE0, i, planner.axis_steps_per_mm[E_AXIS]); #endif #if AXIS_IS_TMC(E1) - tmc_status(stepperE1, TMC_E1, i, planner.axis_steps_per_mm[E_AXIS + tmc_status(stepperE1, i, planner.axis_steps_per_mm[E_AXIS #if ENABLED(DISTINCT_E_FACTORS) + 1 #endif ]); #endif #if AXIS_IS_TMC(E2) - tmc_status(stepperE2, TMC_E2, i, planner.axis_steps_per_mm[E_AXIS + tmc_status(stepperE2, i, planner.axis_steps_per_mm[E_AXIS #if ENABLED(DISTINCT_E_FACTORS) + 2 #endif ]); #endif #if AXIS_IS_TMC(E3) - tmc_status(stepperE3, TMC_E3, i, planner.axis_steps_per_mm[E_AXIS + tmc_status(stepperE3, i, planner.axis_steps_per_mm[E_AXIS #if ENABLED(DISTINCT_E_FACTORS) + 3 #endif ]); #endif #if AXIS_IS_TMC(E4) - tmc_status(stepperE4, TMC_E4, i, planner.axis_steps_per_mm[E_AXIS + tmc_status(stepperE4, i, planner.axis_steps_per_mm[E_AXIS #if ENABLED(DISTINCT_E_FACTORS) + 4 #endif ]); #endif #if AXIS_IS_TMC(E5) - tmc_status(stepperE5, TMC_E5, i, planner.axis_steps_per_mm[E_AXIS + tmc_status(stepperE5, i, planner.axis_steps_per_mm[E_AXIS #if ENABLED(DISTINCT_E_FACTORS) + 5 #endif @@ -556,46 +451,46 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) { static void drv_status_loop(const TMC_drv_status_enum i) { #if AXIS_IS_TMC(X) - tmc_parse_drv_status(stepperX, TMC_X, i); + tmc_parse_drv_status(stepperX, i); #endif #if AXIS_IS_TMC(X2) - tmc_parse_drv_status(stepperX2, TMC_X2, i); + tmc_parse_drv_status(stepperX2, i); #endif #if AXIS_IS_TMC(Y) - tmc_parse_drv_status(stepperY, TMC_Y, i); + tmc_parse_drv_status(stepperY, i); #endif #if AXIS_IS_TMC(Y2) - tmc_parse_drv_status(stepperY2, TMC_Y2, i); + tmc_parse_drv_status(stepperY2, i); #endif #if AXIS_IS_TMC(Z) - tmc_parse_drv_status(stepperZ, TMC_Z, i); + tmc_parse_drv_status(stepperZ, i); #endif #if AXIS_IS_TMC(Z2) - tmc_parse_drv_status(stepperZ2, TMC_Z2, i); + tmc_parse_drv_status(stepperZ2, i); #endif #if AXIS_IS_TMC(Z3) - tmc_parse_drv_status(stepperZ3, TMC_Z3, i); + tmc_parse_drv_status(stepperZ3, i); #endif #if AXIS_IS_TMC(E0) - tmc_parse_drv_status(stepperE0, TMC_E0, i); + tmc_parse_drv_status(stepperE0, i); #endif #if AXIS_IS_TMC(E1) - tmc_parse_drv_status(stepperE1, TMC_E1, i); + tmc_parse_drv_status(stepperE1, i); #endif #if AXIS_IS_TMC(E2) - tmc_parse_drv_status(stepperE2, TMC_E2, i); + tmc_parse_drv_status(stepperE2, i); #endif #if AXIS_IS_TMC(E3) - tmc_parse_drv_status(stepperE3, TMC_E3, i); + tmc_parse_drv_status(stepperE3, i); #endif #if AXIS_IS_TMC(E4) - tmc_parse_drv_status(stepperE4, TMC_E4, i); + tmc_parse_drv_status(stepperE4, i); #endif #if AXIS_IS_TMC(E5) - tmc_parse_drv_status(stepperE5, TMC_E5, i); + tmc_parse_drv_status(stepperE5, i); #endif SERIAL_EOL(); @@ -620,7 +515,7 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) { TMC_REPORT("Run current", TMC_IRUN); TMC_REPORT("Hold current", TMC_IHOLD); TMC_REPORT("CS actual\t", TMC_CS_ACTUAL); - TMC_REPORT("PWM scale\t", TMC_PWM_SCALE); + TMC_REPORT("PWM scale", TMC_PWM_SCALE); TMC_REPORT("vsense\t", TMC_VSENSE); TMC_REPORT("stealthChop", TMC_STEALTHCHOP); TMC_REPORT("msteps\t", TMC_MICROSTEPS); @@ -657,7 +552,7 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) { DRV_REPORT("s2vsa\t", TMC_S2VSA); DRV_REPORT("s2vsb\t", TMC_S2VSB); #endif - DRV_REPORT("Driver registers:", TMC_DRV_STATUS_HEX); + DRV_REPORT("Driver registers:\n",TMC_DRV_STATUS_HEX); SERIAL_EOL(); } @@ -666,9 +561,9 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) { #if USE_SENSORLESS void tmc_stallguard(TMC2130Stepper &st, const bool enable/*=true*/) { - st.coolstep_min_speed(enable ? 1024UL * 1024UL - 1UL : 0); + st.TCOOLTHRS(enable ? 0xFFFFF : 0); #if ENABLED(STEALTHCHOP) - st.stealthChop(!enable); + st.en_pwm_mode(!enable); #endif st.diag1_stall(enable ? 1 : 0); } @@ -676,45 +571,46 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) { #endif // USE_SENSORLESS #if HAS_DRIVER(TMC2130) + #define IS_TMC_SPI(ST) AXIS_DRIVER_TYPE(ST, TMC2130) #define SET_CS_PIN(st) OUT_WRITE(st##_CS_PIN, HIGH) void tmc_init_cs_pins() { - #if AXIS_DRIVER_TYPE(X, TMC2130) + #if IS_TMC_SPI(X) SET_CS_PIN(X); #endif - #if AXIS_DRIVER_TYPE(Y, TMC2130) + #if IS_TMC_SPI(Y) SET_CS_PIN(Y); #endif - #if AXIS_DRIVER_TYPE(Z, TMC2130) + #if IS_TMC_SPI(Z) SET_CS_PIN(Z); #endif - #if AXIS_DRIVER_TYPE(X2, TMC2130) + #if IS_TMC_SPI(X2) SET_CS_PIN(X2); #endif - #if AXIS_DRIVER_TYPE(Y2, TMC2130) + #if IS_TMC_SPI(Y2) SET_CS_PIN(Y2); #endif - #if AXIS_DRIVER_TYPE(Z2, TMC2130) + #if IS_TMC_SPI(Z2) SET_CS_PIN(Z2); #endif - #if AXIS_DRIVER_TYPE(Z3, TMC2130) + #if IS_TMC_SPI(Z3) SET_CS_PIN(Z3); #endif - #if AXIS_DRIVER_TYPE(E0, TMC2130) + #if IS_TMC_SPI(E0) SET_CS_PIN(E0); #endif - #if AXIS_DRIVER_TYPE(E1, TMC2130) + #if IS_TMC_SPI(E1) SET_CS_PIN(E1); #endif - #if AXIS_DRIVER_TYPE(E2, TMC2130) + #if IS_TMC_SPI(E2) SET_CS_PIN(E2); #endif - #if AXIS_DRIVER_TYPE(E3, TMC2130) + #if IS_TMC_SPI(E3) SET_CS_PIN(E3); #endif - #if AXIS_DRIVER_TYPE(E4, TMC2130) + #if IS_TMC_SPI(E4) SET_CS_PIN(E4); #endif - #if AXIS_DRIVER_TYPE(E5, TMC2130) + #if IS_TMC_SPI(E5) SET_CS_PIN(E5); #endif } diff --git a/Marlin/src/feature/tmc_util.h b/Marlin/src/feature/tmc_util.h index b32da5aa3..19050569e 100644 --- a/Marlin/src/feature/tmc_util.h +++ b/Marlin/src/feature/tmc_util.h @@ -23,91 +23,132 @@ #ifndef _TMC_UTIL_H_ #define _TMC_UTIL_H_ -#include "../inc/MarlinConfigPre.h" - -#if HAS_DRIVER(TMC2130) - #include +#include "../inc/MarlinConfig.h" +#if HAS_TRINAMIC + #include #endif -#if HAS_DRIVER(TMC2208) - #include -#endif +#define TMC_X_LABEL 'X', '0' +#define TMC_Y_LABEL 'Y', '0' +#define TMC_Z_LABEL 'Z', '0' + +#define TMC_X2_LABEL 'X', '2' +#define TMC_Y2_LABEL 'Y', '2' +#define TMC_Z2_LABEL 'Z', '2' +#define TMC_Z3_LABEL 'Z', '3' + +#define TMC_E0_LABEL 'E', '0' +#define TMC_E1_LABEL 'E', '1' +#define TMC_E2_LABEL 'E', '2' +#define TMC_E3_LABEL 'E', '3' +#define TMC_E4_LABEL 'E', '4' +#define TMC_E5_LABEL 'E', '5' + +template +class TMCStorage { + protected: + // Only a child class has access to constructor => Don't create on its own! "Poor man's abstract class" + TMCStorage() {} + + uint16_t val_mA = 0; + + public: + #if ENABLED(MONITOR_DRIVER_STATUS) + uint8_t otpw_count = 0; + bool flag_otpw = false; + bool getOTPW() { return flag_otpw; } + void clear_otpw() { flag_otpw = 0; } + #endif + + uint16_t getMilliamps() { return val_mA; } -extern bool report_tmc_status; - -enum TMC_AxisEnum : char { - TMC_X, TMC_Y, TMC_Z - #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(X_DUAL_STEPPER_DRIVERS) - , TMC_X2 - #endif - #if ENABLED(Y_DUAL_STEPPER_DRIVERS) - , TMC_Y2 - #endif - #if ENABLED(Z_DUAL_STEPPER_DRIVERS) - , TMC_Z2 - #endif - #if ENABLED(Z_TRIPLE_STEPPER_DRIVERS) - , TMC_Z3 - #endif - #if E_STEPPERS - , TMC_E0 - #if E_STEPPERS > 1 - , TMC_E1 - #if E_STEPPERS > 2 - , TMC_E2 - #if E_STEPPERS > 3 - , TMC_E3 - #if E_STEPPERS > 4 - , TMC_E4 - #if E_STEPPERS > 5 - , TMC_E5 - #endif // E_STEPPERS > 5 - #endif // E_STEPPERS > 4 - #endif // E_STEPPERS > 3 - #endif // E_STEPPERS > 2 - #endif // E_STEPPERS > 1 - #endif // E_STEPPERS + void printLabel() { + SERIAL_CHAR(AXIS_LETTER); + if (DRIVER_ID > '0') SERIAL_CHAR(DRIVER_ID); + } +}; + +template +class TMCMarlin : public TMC, public TMCStorage { + public: + TMCMarlin(uint16_t cs_pin, float RS) : + TMC(cs_pin, RS) + {} + TMCMarlin(uint16_t CS, float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK) : + TMC(CS, RS, pinMOSI, pinMISO, pinSCK) + {} + uint16_t rms_current() { return TMC::rms_current(); } + void rms_current(uint16_t mA) { + this->val_mA = mA; + TMC::rms_current(mA); + } + void rms_current(uint16_t mA, float mult) { + this->val_mA = mA; + TMC::rms_current(mA, mult); + } +}; +template +class TMCMarlin : public TMC2208Stepper, public TMCStorage { + public: + TMCMarlin(Stream * SerialPort, float RS, bool has_rx=true) : + TMC2208Stepper(SerialPort, RS, has_rx=true) + {} + TMCMarlin(uint16_t RX, uint16_t TX, float RS, bool has_rx=true) : + TMC2208Stepper(RX, TX, RS, has_rx=true) + {} + uint16_t rms_current() { return TMC2208Stepper::rms_current(); } + void rms_current(uint16_t mA) { + this->val_mA = mA; + TMC2208Stepper::rms_current(mA); + } + void rms_current(uint16_t mA, float mult) { + this->val_mA = mA; + TMC2208Stepper::rms_current(mA, mult); + } }; constexpr uint32_t _tmc_thrs(const uint16_t msteps, const int32_t thrs, const uint32_t spmm) { return 12650000UL * msteps / (256 * thrs * spmm); } -void _tmc_say_axis(const TMC_AxisEnum axis); -void _tmc_say_current(const TMC_AxisEnum axis, const uint16_t curr); -void _tmc_say_otpw(const TMC_AxisEnum axis, const bool otpw); -void _tmc_say_otpw_cleared(const TMC_AxisEnum axis); -void _tmc_say_pwmthrs(const TMC_AxisEnum axis, const uint32_t thrs); -void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt); - template -void tmc_get_current(TMC &st, const TMC_AxisEnum axis) { - _tmc_say_current(axis, st.getCurrent()); +void tmc_get_current(TMC &st) { + st.printLabel(); + SERIAL_ECHOLNPAIR(" driver current: ", st.getMilliamps()); } template void tmc_set_current(TMC &st, const int mA) { - st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER); -} -template -void tmc_report_otpw(TMC &st, const TMC_AxisEnum axis) { - _tmc_say_otpw(axis, st.getOTPW()); -} -template -void tmc_clear_otpw(TMC &st, const TMC_AxisEnum axis) { - st.clear_otpw(); - _tmc_say_otpw_cleared(axis); + st.rms_current(mA); } +#if ENABLED(MONITOR_DRIVER_STATUS) + template + void tmc_report_otpw(TMC &st) { + st.printLabel(); + SERIAL_ECHOPGM(" temperature prewarn triggered: "); + serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false")); + SERIAL_EOL(); + } + template + void tmc_clear_otpw(TMC &st) { + st.clear_otpw(); + st.printLabel(); + SERIAL_ECHOLNPGM(" prewarn flag cleared"); + } +#endif template -void tmc_get_pwmthrs(TMC &st, const TMC_AxisEnum axis, const uint16_t spmm) { - _tmc_say_pwmthrs(axis, _tmc_thrs(st.microsteps(), st.TPWMTHRS(), spmm)); +void tmc_get_pwmthrs(TMC &st, const uint16_t spmm) { + st.printLabel(); + SERIAL_ECHOLNPAIR(" stealthChop max speed: ", _tmc_thrs(st.microsteps(), st.TPWMTHRS(), spmm)); } template void tmc_set_pwmthrs(TMC &st, const int32_t thrs, const uint32_t spmm) { st.TPWMTHRS(_tmc_thrs(st.microsteps(), thrs, spmm)); } template -void tmc_get_sgt(TMC &st, const TMC_AxisEnum axis) { - _tmc_say_sgt(axis, st.sgt()); +void tmc_get_sgt(TMC &st) { + st.printLabel(); + SERIAL_ECHOPGM(" homing sensitivity: "); + SERIAL_PRINTLN(st.sgt(), DEC); } template void tmc_set_sgt(TMC &st, const int8_t sgt_val) { diff --git a/Marlin/src/gcode/feature/trinamic/M906.cpp b/Marlin/src/gcode/feature/trinamic/M906.cpp index e727d3e30..853f09838 100644 --- a/Marlin/src/gcode/feature/trinamic/M906.cpp +++ b/Marlin/src/gcode/feature/trinamic/M906.cpp @@ -33,7 +33,7 @@ * Report driver currents when no axis specified */ void GcodeSuite::M906() { - #define TMC_SAY_CURRENT(Q) tmc_get_current(stepper##Q, TMC_##Q) + #define TMC_SAY_CURRENT(Q) tmc_get_current(stepper##Q) #define TMC_SET_CURRENT(Q) tmc_set_current(stepper##Q, value) bool report = true; diff --git a/Marlin/src/gcode/feature/trinamic/M911-M915.cpp b/Marlin/src/gcode/feature/trinamic/M911-M915.cpp index 1ab20ea52..4bb0a5959 100644 --- a/Marlin/src/gcode/feature/trinamic/M911-M915.cpp +++ b/Marlin/src/gcode/feature/trinamic/M911-M915.cpp @@ -33,135 +33,137 @@ #define M91x_USE(ST) (AXIS_DRIVER_TYPE(ST, TMC2130) || (AXIS_DRIVER_TYPE(ST, TMC2208) && PIN_EXISTS(ST##_SERIAL_RX))) #define M91x_USE_E(N) (E_STEPPERS > N && M91x_USE(E##N)) -/** - * M911: Report TMC stepper driver overtemperature pre-warn flag - * This flag is held by the library, persisting until cleared by M912 - */ -void GcodeSuite::M911() { - #if M91x_USE(X) - tmc_report_otpw(stepperX, TMC_X); - #endif - #if M91x_USE(X2) - tmc_report_otpw(stepperX2, TMC_X2); - #endif - #if M91x_USE(Y) - tmc_report_otpw(stepperY, TMC_Y); - #endif - #if M91x_USE(Y2) - tmc_report_otpw(stepperY2, TMC_Y2); - #endif - #if M91x_USE(Z) - tmc_report_otpw(stepperZ, TMC_Z); - #endif - #if M91x_USE(Z2) - tmc_report_otpw(stepperZ2, TMC_Z2); - #endif - #if M91x_USE(Z3) - tmc_report_otpw(stepperZ3, TMC_Z3); - #endif - #if M91x_USE_E(0) - tmc_report_otpw(stepperE0, TMC_E0); - #endif - #if M91x_USE_E(1) - tmc_report_otpw(stepperE1, TMC_E1); - #endif - #if M91x_USE_E(2) - tmc_report_otpw(stepperE2, TMC_E2); - #endif - #if M91x_USE_E(3) - tmc_report_otpw(stepperE3, TMC_E3); - #endif - #if M91x_USE_E(4) - tmc_report_otpw(stepperE4, TMC_E4); - #endif - #if M91x_USE_E(5) - tmc_report_otpw(stepperE5, TMC_E5); - #endif -} +#if ENABLED(MONITOR_DRIVER_STATUS) + /** + * M911: Report TMC stepper driver overtemperature pre-warn flag + * This flag is held by the library, persisting until cleared by M912 + */ + void GcodeSuite::M911() { + #if M91x_USE(X) + tmc_report_otpw(stepperX); + #endif + #if M91x_USE(X2) + tmc_report_otpw(stepperX2); + #endif + #if M91x_USE(Y) + tmc_report_otpw(stepperY); + #endif + #if M91x_USE(Y2) + tmc_report_otpw(stepperY2); + #endif + #if M91x_USE(Z) + tmc_report_otpw(stepperZ); + #endif + #if M91x_USE(Z2) + tmc_report_otpw(stepperZ2); + #endif + #if M91x_USE(Z3) + tmc_report_otpw(stepperZ3); + #endif + #if M91x_USE_E(0) + tmc_report_otpw(stepperE0); + #endif + #if M91x_USE_E(1) + tmc_report_otpw(stepperE1); + #endif + #if M91x_USE_E(2) + tmc_report_otpw(stepperE2); + #endif + #if M91x_USE_E(3) + tmc_report_otpw(stepperE3); + #endif + #if M91x_USE_E(4) + tmc_report_otpw(stepperE4); + #endif + #if M91x_USE_E(5) + tmc_report_otpw(stepperE5); + #endif + } -/** - * M912: Clear TMC stepper driver overtemperature pre-warn flag held by the library - * Specify one or more axes with X, Y, Z, X1, Y1, Z1, X2, Y2, Z2, Z3 and E[index]. - * If no axes are given, clear all. - * - * Examples: - * M912 X ; clear X and X2 - * M912 X1 ; clear X1 only - * M912 X2 ; clear X2 only - * M912 X E ; clear X, X2, and all E - * M912 E1 ; clear E1 only - */ -void GcodeSuite::M912() { - const bool hasX = parser.seen(axis_codes[X_AXIS]), - hasY = parser.seen(axis_codes[Y_AXIS]), - hasZ = parser.seen(axis_codes[Z_AXIS]), - hasE = parser.seen(axis_codes[E_AXIS]), - hasNone = !hasX && !hasY && !hasZ && !hasE; + /** + * M912: Clear TMC stepper driver overtemperature pre-warn flag held by the library + * Specify one or more axes with X, Y, Z, X1, Y1, Z1, X2, Y2, Z2, Z3 and E[index]. + * If no axes are given, clear all. + * + * Examples: + * M912 X ; clear X and X2 + * M912 X1 ; clear X1 only + * M912 X2 ; clear X2 only + * M912 X E ; clear X, X2, and all E + * M912 E1 ; clear E1 only + */ + void GcodeSuite::M912() { + const bool hasX = parser.seen(axis_codes[X_AXIS]), + hasY = parser.seen(axis_codes[Y_AXIS]), + hasZ = parser.seen(axis_codes[Z_AXIS]), + hasE = parser.seen(axis_codes[E_AXIS]), + hasNone = !hasX && !hasY && !hasZ && !hasE; - #if M91x_USE(X) || M91x_USE(X2) - const int8_t xval = int8_t(parser.byteval(axis_codes[X_AXIS], 0xFF)); - #if M91x_USE(X) - if (hasNone || xval == 1 || (hasX && xval < 0)) tmc_clear_otpw(stepperX, TMC_X); - #endif - #if M91x_USE(X2) - if (hasNone || xval == 2 || (hasX && xval < 0)) tmc_clear_otpw(stepperX2, TMC_X2); + #if M91x_USE(X) || M91x_USE(X2) + const int8_t xval = int8_t(parser.byteval(axis_codes[X_AXIS], 0xFF)); + #if M91x_USE(X) + if (hasNone || xval == 1 || (hasX && xval < 0)) tmc_clear_otpw(stepperX); + #endif + #if M91x_USE(X2) + if (hasNone || xval == 2 || (hasX && xval < 0)) tmc_clear_otpw(stepperX2); + #endif #endif - #endif - #if M91x_USE(Y) || M91x_USE(Y2) - const int8_t yval = int8_t(parser.byteval(axis_codes[Y_AXIS], 0xFF)); - #if M91x_USE(Y) - if (hasNone || yval == 1 || (hasY && yval < 0)) tmc_clear_otpw(stepperY, TMC_Y); - #endif - #if M91x_USE(Y2) - if (hasNone || yval == 2 || (hasY && yval < 0)) tmc_clear_otpw(stepperY2, TMC_Y2); + #if M91x_USE(Y) || M91x_USE(Y2) + const int8_t yval = int8_t(parser.byteval(axis_codes[Y_AXIS], 0xFF)); + #if M91x_USE(Y) + if (hasNone || yval == 1 || (hasY && yval < 0)) tmc_clear_otpw(stepperY); + #endif + #if M91x_USE(Y2) + if (hasNone || yval == 2 || (hasY && yval < 0)) tmc_clear_otpw(stepperY2); + #endif #endif - #endif - #if M91x_USE(Z) || M91x_USE(Z2) || M91x_USE(Z3) - const int8_t zval = int8_t(parser.byteval(axis_codes[Z_AXIS], 0xFF)); - #if M91x_USE(Z) - if (hasNone || zval == 1 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ, TMC_Z); - #endif - #if M91x_USE(Z2) - if (hasNone || zval == 2 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ2, TMC_Z2); - #endif - #if M91x_USE(Z3) - if (hasNone || zval == 3 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ3, TMC_Z3); + #if M91x_USE(Z) || M91x_USE(Z2) || M91x_USE(Z3) + const int8_t zval = int8_t(parser.byteval(axis_codes[Z_AXIS], 0xFF)); + #if M91x_USE(Z) + if (hasNone || zval == 1 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ); + #endif + #if M91x_USE(Z2) + if (hasNone || zval == 2 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ2); + #endif + #if M91x_USE(Z3) + if (hasNone || zval == 3 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ3); + #endif #endif - #endif - #if M91x_USE_E(0) || M91x_USE_E(1) || M91x_USE_E(2) || M91x_USE_E(3) || M91x_USE_E(4) || M91x_USE_E(5) - const uint8_t eval = int8_t(parser.byteval(axis_codes[E_AXIS], 0xFF)); - #if M91x_USE_E(0) - if (hasNone || eval == 0 || (hasE && eval < 0)) tmc_clear_otpw(stepperE0, TMC_E0); - #endif - #if M91x_USE_E(1) - if (hasNone || eval == 1 || (hasE && eval < 0)) tmc_clear_otpw(stepperE1, TMC_E1); - #endif - #if M91x_USE_E(2) - if (hasNone || eval == 2 || (hasE && eval < 0)) tmc_clear_otpw(stepperE2, TMC_E2); - #endif - #if M91x_USE_E(3) - if (hasNone || eval == 3 || (hasE && eval < 0)) tmc_clear_otpw(stepperE3, TMC_E3); - #endif - #if M91x_USE_E(4) - if (hasNone || eval == 4 || (hasE && eval < 0)) tmc_clear_otpw(stepperE4, TMC_E4); - #endif - #if M91x_USE_E(5) - if (hasNone || eval == 5 || (hasE && eval < 0)) tmc_clear_otpw(stepperE5, TMC_E5); + #if M91x_USE_E(0) || M91x_USE_E(1) || M91x_USE_E(2) || M91x_USE_E(3) || M91x_USE_E(4) || M91x_USE_E(5) + const int8_t eval = int8_t(parser.byteval(axis_codes[E_AXIS], 0xFF)); + #if M91x_USE_E(0) + if (hasNone || eval == 0 || (hasE && eval < 0)) tmc_clear_otpw(stepperE0); + #endif + #if M91x_USE_E(1) + if (hasNone || eval == 1 || (hasE && eval < 0)) tmc_clear_otpw(stepperE1); + #endif + #if M91x_USE_E(2) + if (hasNone || eval == 2 || (hasE && eval < 0)) tmc_clear_otpw(stepperE2); + #endif + #if M91x_USE_E(3) + if (hasNone || eval == 3 || (hasE && eval < 0)) tmc_clear_otpw(stepperE3); + #endif + #if M91x_USE_E(4) + if (hasNone || eval == 4 || (hasE && eval < 0)) tmc_clear_otpw(stepperE4); + #endif + #if M91x_USE_E(5) + if (hasNone || eval == 5 || (hasE && eval < 0)) tmc_clear_otpw(stepperE5); + #endif #endif - #endif -} + } +#endif /** * M913: Set HYBRID_THRESHOLD speed. */ #if ENABLED(HYBRID_THRESHOLD) void GcodeSuite::M913() { - #define TMC_SAY_PWMTHRS(A,Q) tmc_get_pwmthrs(stepper##Q, TMC_##Q, planner.axis_steps_per_mm[_AXIS(A)]) + #define TMC_SAY_PWMTHRS(A,Q) tmc_get_pwmthrs(stepper##Q, planner.axis_steps_per_mm[_AXIS(A)]) #define TMC_SET_PWMTHRS(A,Q) tmc_set_pwmthrs(stepper##Q, value, planner.axis_steps_per_mm[_AXIS(A)]) - #define TMC_SAY_PWMTHRS_E(E) do{ constexpr uint8_t extruder = E; tmc_get_pwmthrs(stepperE##E, TMC_E##E, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); }while(0) + #define TMC_SAY_PWMTHRS_E(E) do{ constexpr uint8_t extruder = E; tmc_get_pwmthrs(stepperE##E, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); }while(0) #define TMC_SET_PWMTHRS_E(E) do{ constexpr uint8_t extruder = E; tmc_set_pwmthrs(stepperE##E, value, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); }while(0) bool report = true; @@ -271,7 +273,7 @@ void GcodeSuite::M912() { */ #if USE_SENSORLESS void GcodeSuite::M914() { - #define TMC_SAY_SGT(Q) tmc_get_sgt(stepper##Q, TMC_##Q) + #define TMC_SAY_SGT(Q) tmc_get_sgt(stepper##Q) #define TMC_SET_SGT(Q) tmc_set_sgt(stepper##Q, value) bool report = true; @@ -362,16 +364,16 @@ void GcodeSuite::M912() { } #if AXIS_IS_TMC(Z) - const uint16_t Z_current_1 = stepperZ.getCurrent(); - stepperZ.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER); + const uint16_t Z_current_1 = stepperZ.getMilliamps(); + stepperZ.rms_current(_rms); #endif #if AXIS_IS_TMC(Z2) - const uint16_t Z2_current_1 = stepperZ2.getCurrent(); - stepperZ2.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER); + const uint16_t Z2_current_1 = stepperZ2.getMilliamps(); + stepperZ2.rms_current(_rms); #endif - #if Z3_IS_TRINAMIC - const uint16_t Z3_current_1 = stepperZ3.getCurrent(); - stepperZ3.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER); + #if AXIS_IS_TMC(Z3) + const uint16_t Z3_current_1 = stepperZ3.getMilliamps(); + stepperZ3.rms_current(_rms); #endif SERIAL_ECHOPAIR("\nCalibration current: Z", _rms); @@ -381,13 +383,13 @@ void GcodeSuite::M912() { do_blocking_move_to_z(Z_MAX_POS+_z); #if AXIS_IS_TMC(Z) - stepperZ.setCurrent(Z_current_1, R_SENSE, HOLD_MULTIPLIER); + stepperZ.rms_current(Z_current_1); #endif #if AXIS_IS_TMC(Z2) - stepperZ2.setCurrent(Z2_current_1, R_SENSE, HOLD_MULTIPLIER); + stepperZ2.rms_current(Z2_current_1); #endif #if AXIS_IS_TMC(Z3) - stepperZ3.setCurrent(Z3_current_1, R_SENSE, HOLD_MULTIPLIER); + stepperZ3.rms_current(Z3_current_1); #endif do_blocking_move_to_z(Z_MAX_POS); diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 7f1b63d4e..f71b5ab3c 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -632,8 +632,10 @@ void GcodeSuite::process_parsed_command( case 122: M122(); break; #endif case 906: M906(); break; // M906: Set motor current in milliamps using axis codes X, Y, Z, E - case 911: M911(); break; // M911: Report TMC2130 prewarn triggered flags - case 912: M912(); break; // M912: Clear TMC2130 prewarn triggered flags + #if ENABLED(MONITOR_DRIVER_STATUS) + case 911: M911(); break; // M911: Report TMC2130 prewarn triggered flags + case 912: M912(); break; // M912: Clear TMC2130 prewarn triggered flags + #endif #if ENABLED(HYBRID_THRESHOLD) case 913: M913(); break; // M913: Set HYBRID_THRESHOLD speed. #endif diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index d7ca10d9a..4298365e1 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -775,8 +775,10 @@ private: static void M122(); #endif static void M906(); - static void M911(); - static void M912(); + #if ENABLED(MONITOR_DRIVER_STATUS) + static void M911(); + static void M912(); + #endif #if ENABLED(HYBRID_THRESHOLD) static void M913(); #endif diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 0f828451b..16e5f006c 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -460,6 +460,9 @@ * NOTE: Driver timing order is longest-to-shortest duration. * Preserve this ordering when adding new drivers. */ + +#define TRINAMICS (HAS_TRINAMIC || HAS_DRIVER(TMC2660) || HAS_DRIVER(TMC2130_STANDALONE) || HAS_DRIVER(TMC2208_STANDALONE) || HAS_DRIVER(TMC26X_STANDALONE) || HAS_DRIVER(TMC2660_STANDALONE)) + #ifndef MINIMUM_STEPPER_DIR_DELAY #if HAS_DRIVER(TB6560) #define MINIMUM_STEPPER_DIR_DELAY 15000 @@ -473,7 +476,7 @@ #define MINIMUM_STEPPER_DIR_DELAY 400 #elif HAS_DRIVER(A4988) #define MINIMUM_STEPPER_DIR_DELAY 200 - #elif HAS_TRINAMIC || HAS_DRIVER(TMC2660) || HAS_DRIVER(TMC2130_STANDALONE) || HAS_DRIVER(TMC2208_STANDALONE) || HAS_DRIVER(TMC26X_STANDALONE) || HAS_DRIVER(TMC2660_STANDALONE) + #elif TRINAMICS #define MINIMUM_STEPPER_DIR_DELAY 20 #else #define MINIMUM_STEPPER_DIR_DELAY 0 // Expect at least 10µS since one Stepper ISR must transpire @@ -489,7 +492,7 @@ #define MINIMUM_STEPPER_PULSE 2 #elif HAS_DRIVER(A4988) || HAS_DRIVER(LV8729) || HAS_DRIVER(A5984) #define MINIMUM_STEPPER_PULSE 1 - #elif HAS_TRINAMIC || HAS_DRIVER(TMC2660) || HAS_DRIVER(TMC2130_STANDALONE) || HAS_DRIVER(TMC2208_STANDALONE) || HAS_DRIVER(TMC26X_STANDALONE) || HAS_DRIVER(TMC2660_STANDALONE) + #elif TRINAMICS #define MINIMUM_STEPPER_PULSE 0 #else #define MINIMUM_STEPPER_PULSE 2 @@ -505,7 +508,7 @@ #define MAXIMUM_STEPPER_RATE 150000 #elif HAS_DRIVER(DRV8825) #define MAXIMUM_STEPPER_RATE 250000 - #elif HAS_TRINAMIC || HAS_DRIVER(TMC2660) || HAS_DRIVER(TMC2130_STANDALONE) || HAS_DRIVER(TMC2208_STANDALONE) || HAS_DRIVER(TMC26X_STANDALONE) || HAS_DRIVER(TMC2660_STANDALONE) + #elif TRINAMICS #define MAXIMUM_STEPPER_RATE 400000 #elif HAS_DRIVER(A4988) #define MAXIMUM_STEPPER_RATE 500000 diff --git a/Marlin/src/module/configuration_store.cpp b/Marlin/src/module/configuration_store.cpp index eee30aba8..9a92e47d5 100644 --- a/Marlin/src/module/configuration_store.cpp +++ b/Marlin/src/module/configuration_store.cpp @@ -83,6 +83,9 @@ #include "../feature/tmc_util.h" #define TMC_GET_PWMTHRS(A,Q) _tmc_thrs(stepper##Q.microsteps(), stepper##Q.TPWMTHRS(), planner.axis_steps_per_mm[_AXIS(A)]) #endif +typedef struct { uint16_t X, Y, Z, X2, Y2, Z2, Z3, E0, E1, E2, E3, E4, E5; } tmc_stepper_current_t; +typedef struct { uint32_t X, Y, Z, X2, Y2, Z2, Z3, E0, E1, E2, E3, E4, E5; } tmc_hybrid_threshold_t; +typedef struct { int16_t X, Y, Z; } tmc_sgt_t; #if ENABLED(FWRETRACT) #include "../feature/fwretract.h" @@ -98,7 +101,7 @@ #pragma pack(push, 1) // No padding between variables -typedef struct PID { float Kp, Ki, Kd; } PID; +typedef struct PID { float Kp, Ki, Kd; } PID; typedef struct PIDC { float Kp, Ki, Kd, Kc; } PIDC; /** @@ -251,9 +254,9 @@ typedef struct SettingsDataStruct { // HAS_TRINAMIC // #define TMC_AXES (MAX_EXTRUDERS + 7) - uint16_t tmc_stepper_current[TMC_AXES]; // M906 X Y Z X2 Y2 Z2 Z3 E0 E1 E2 E3 E4 E5 - uint32_t tmc_hybrid_threshold[TMC_AXES]; // M913 X Y Z X2 Y2 Z2 Z3 E0 E1 E2 E3 E4 E5 - int16_t tmc_sgt[XYZ]; // M914 X Y Z + tmc_stepper_current_t tmc_stepper_current; // M906 X Y Z X2 Y2 Z2 Z3 E0 E1 E2 E3 E4 E5 + tmc_hybrid_threshold_t tmc_hybrid_threshold; // M913 X Y Z X2 Y2 Z2 Z3 E0 E1 E2 E3 E4 E5 + tmc_sgt_t tmc_sgt; // M914 X Y Z // // LIN_ADVANCE @@ -300,7 +303,7 @@ uint16_t MarlinSettings::datasize() { return sizeof(SettingsData); } #endif void MarlinSettings::postprocess() { - const float oldpos[] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] }; + const float oldpos[XYZE] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS] }; // steps per s2 needs to be updated to agree with units per s2 planner.reset_acceleration_rates(); @@ -436,7 +439,7 @@ void MarlinSettings::postprocess() { EEPROM_WRITE(dummy); #endif #else - const float planner_max_jerk[] = { float(DEFAULT_XJERK), float(DEFAULT_YJERK), float(DEFAULT_ZJERK), float(DEFAULT_EJERK) }; + const float planner_max_jerk[XYZE] = { float(DEFAULT_XJERK), float(DEFAULT_YJERK), float(DEFAULT_ZJERK), float(DEFAULT_EJERK) }; EEPROM_WRITE(planner_max_jerk); #endif @@ -464,11 +467,13 @@ void MarlinSettings::postprocess() { // Global Leveling // - #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) - const float zfh = planner.z_fade_height; - #else - const float zfh = 10.0; - #endif + const float zfh = ( + #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) + planner.z_fade_height + #else + 10.0 + #endif + ); EEPROM_WRITE(zfh); // @@ -478,7 +483,7 @@ void MarlinSettings::postprocess() { #if ENABLED(MESH_BED_LEVELING) // Compile time test that sizeof(mbl.z_values) is as expected static_assert( - sizeof(mbl.z_values) == GRID_MAX_POINTS * sizeof(mbl.z_values[0][0]), + sizeof(mbl.z_values) == (GRID_MAX_POINTS) * sizeof(mbl.z_values[0][0]), "MBL Z array is the wrong size." ); const uint8_t mesh_num_x = GRID_MAX_POINTS_X, mesh_num_y = GRID_MAX_POINTS_Y; @@ -520,7 +525,7 @@ void MarlinSettings::postprocess() { #if ENABLED(AUTO_BED_LEVELING_BILINEAR) // Compile time test that sizeof(z_values) is as expected static_assert( - sizeof(z_values) == GRID_MAX_POINTS * sizeof(z_values[0][0]), + sizeof(z_values) == (GRID_MAX_POINTS) * sizeof(z_values[0][0]), "Bilinear Z array is the wrong size." ); const uint8_t grid_max_x = GRID_MAX_POINTS_X, grid_max_y = GRID_MAX_POINTS_Y; @@ -719,230 +724,154 @@ void MarlinSettings::postprocess() { #endif // - // Save TMC2130 or TMC2208 Configuration, and placeholder values + // Save TMC Configuration, and placeholder values // _FIELD_TEST(tmc_stepper_current); - uint16_t tmc_stepper_current[TMC_AXES] = { - #if HAS_TRINAMIC - #if AXIS_IS_TMC(X) - stepperX.getCurrent(), - #else - 0, - #endif - #if AXIS_IS_TMC(Y) - stepperY.getCurrent(), - #else - 0, - #endif - #if AXIS_IS_TMC(Z) - stepperZ.getCurrent(), - #else - 0, - #endif - #if AXIS_IS_TMC(X2) - stepperX2.getCurrent(), - #else - 0, - #endif - #if AXIS_IS_TMC(Y2) - stepperY2.getCurrent(), - #else - 0, - #endif - #if AXIS_IS_TMC(Z2) - stepperZ2.getCurrent(), - #else - 0, - #endif - #if AXIS_IS_TMC(Z3) - stepperZ3.getCurrent(), - #else - 0, + tmc_stepper_current_t tmc_stepper_current = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + #if HAS_TRINAMIC + #if AXIS_IS_TMC(X) + tmc_stepper_current.X = stepperX.getMilliamps(); + #endif + #if AXIS_IS_TMC(Y) + tmc_stepper_current.Y = stepperY.getMilliamps(); + #endif + #if AXIS_IS_TMC(Z) + tmc_stepper_current.Z = stepperZ.getMilliamps(); + #endif + #if AXIS_IS_TMC(X2) + tmc_stepper_current.X2 = stepperX2.getMilliamps(); + #endif + #if AXIS_IS_TMC(Y2) + tmc_stepper_current.Y2 = stepperY2.getMilliamps(); + #endif + #if AXIS_IS_TMC(Z2) + tmc_stepper_current.Z2 = stepperZ2.getMilliamps(); + #endif + #if AXIS_IS_TMC(Z3) + tmc_stepper_current.Z3 = stepperZ3.getMilliamps(); + #endif + #if MAX_EXTRUDERS + #if AXIS_IS_TMC(E0) + tmc_stepper_current.E0 = stepperE0.getMilliamps(); #endif - #if MAX_EXTRUDERS - #if AXIS_IS_TMC(E0) - stepperE0.getCurrent(), - #else - 0, + #if MAX_EXTRUDERS > 1 + #if AXIS_IS_TMC(E1) + tmc_stepper_current.E1 = stepperE1.getMilliamps(); #endif - #if MAX_EXTRUDERS > 1 - #if AXIS_IS_TMC(E1) - stepperE1.getCurrent(), - #else - 0, + #if MAX_EXTRUDERS > 2 + #if AXIS_IS_TMC(E2) + tmc_stepper_current.E2 = stepperE2.getMilliamps(); #endif - #if MAX_EXTRUDERS > 2 - #if AXIS_IS_TMC(E2) - stepperE2.getCurrent(), - #else - 0, + #if MAX_EXTRUDERS > 3 + #if AXIS_IS_TMC(E3) + tmc_stepper_current.E3 = stepperE3.getMilliamps(); #endif - #if MAX_EXTRUDERS > 3 - #if AXIS_IS_TMC(E3) - stepperE3.getCurrent(), - #else - 0, + #if MAX_EXTRUDERS > 4 + #if AXIS_IS_TMC(E4) + tmc_stepper_current.E4 = stepperE4.getMilliamps(); #endif - #if MAX_EXTRUDERS > 4 - #if AXIS_IS_TMC(E4) - stepperE4.getCurrent() - #else - 0 + #if MAX_EXTRUDERS > 5 + #if AXIS_IS_TMC(E5) + tmc_stepper_current.E5 = stepperE5.getMilliamps(); #endif - #if MAX_EXTRUDERS > 5 - #if AXIS_IS_TMC(E5) - stepperE5.getCurrent() - #else - 0 - #endif - #endif // MAX_EXTRUDERS > 5 - #endif // MAX_EXTRUDERS > 4 - #endif // MAX_EXTRUDERS > 3 - #endif // MAX_EXTRUDERS > 2 - #endif // MAX_EXTRUDERS > 1 - #endif // MAX_EXTRUDERS - #else - 0 - #endif - }; + #endif // MAX_EXTRUDERS > 5 + #endif // MAX_EXTRUDERS > 4 + #endif // MAX_EXTRUDERS > 3 + #endif // MAX_EXTRUDERS > 2 + #endif // MAX_EXTRUDERS > 1 + #endif // MAX_EXTRUDERS + #endif EEPROM_WRITE(tmc_stepper_current); // - // Save TMC2130 or TMC2208 Hybrid Threshold, and placeholder values + // Save TMC Hybrid Threshold, and placeholder values // _FIELD_TEST(tmc_hybrid_threshold); - uint32_t tmc_hybrid_threshold[TMC_AXES] = { - #if ENABLED(HYBRID_THRESHOLD) - #if AXIS_HAS_STEALTHCHOP(X) - TMC_GET_PWMTHRS(X, X), - #else - X_HYBRID_THRESHOLD, - #endif - #if AXIS_HAS_STEALTHCHOP(Y) - TMC_GET_PWMTHRS(Y, Y), - #else - Y_HYBRID_THRESHOLD, - #endif - #if AXIS_HAS_STEALTHCHOP(Z) - TMC_GET_PWMTHRS(Z, Z), - #else - Z_HYBRID_THRESHOLD, - #endif - #if AXIS_HAS_STEALTHCHOP(X2) - TMC_GET_PWMTHRS(X, X2), - #else - X2_HYBRID_THRESHOLD, - #endif - #if AXIS_HAS_STEALTHCHOP(Y2) - TMC_GET_PWMTHRS(Y, Y2), - #else - Y2_HYBRID_THRESHOLD, - #endif - #if AXIS_HAS_STEALTHCHOP(Z2) - TMC_GET_PWMTHRS(Z, Z2), - #else - Z2_HYBRID_THRESHOLD, - #endif - #if AXIS_HAS_STEALTHCHOP(Z3) - TMC_GET_PWMTHRS(Z, Z3), - #else - Z3_HYBRID_THRESHOLD, + #if ENABLED(HYBRID_THRESHOLD) + tmc_hybrid_threshold_t tmc_hybrid_threshold = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + #if AXIS_HAS_STEALTHCHOP(X) + tmc_hybrid_threshold.X = TMC_GET_PWMTHRS(X, X); + #endif + #if AXIS_HAS_STEALTHCHOP(Y) + tmc_hybrid_threshold.Y = TMC_GET_PWMTHRS(Y, Y); + #endif + #if AXIS_HAS_STEALTHCHOP(Z) + tmc_hybrid_threshold.Z = TMC_GET_PWMTHRS(Z, Z); + #endif + #if AXIS_HAS_STEALTHCHOP(X2) + tmc_hybrid_threshold.X2 = TMC_GET_PWMTHRS(X, X2); + #endif + #if AXIS_HAS_STEALTHCHOP(Y2) + tmc_hybrid_threshold.Y2 = TMC_GET_PWMTHRS(Y, Y2); + #endif + #if AXIS_HAS_STEALTHCHOP(Z2) + tmc_hybrid_threshold.Z2 = TMC_GET_PWMTHRS(Z, Z2); + #endif + #if AXIS_HAS_STEALTHCHOP(Z3) + tmc_hybrid_threshold.Z3 = TMC_GET_PWMTHRS(Z, Z3); + #endif + #if MAX_EXTRUDERS + #if AXIS_HAS_STEALTHCHOP(E0) + tmc_hybrid_threshold.E0 = TMC_GET_PWMTHRS(E, E0); #endif - #if MAX_EXTRUDERS - #if AXIS_HAS_STEALTHCHOP(E0) - TMC_GET_PWMTHRS(E, E0), - #else - E0_HYBRID_THRESHOLD, + #if MAX_EXTRUDERS > 1 + #if AXIS_HAS_STEALTHCHOP(E1) + tmc_hybrid_threshold.E1 = TMC_GET_PWMTHRS(E, E1); #endif - #if MAX_EXTRUDERS > 1 - #if AXIS_HAS_STEALTHCHOP(E1) - TMC_GET_PWMTHRS(E, E1), - #else - E1_HYBRID_THRESHOLD, + #if MAX_EXTRUDERS > 2 + #if AXIS_HAS_STEALTHCHOP(E2) + tmc_hybrid_threshold.E2 = TMC_GET_PWMTHRS(E, E2); #endif - #if MAX_EXTRUDERS > 2 - #if AXIS_HAS_STEALTHCHOP(E2) - TMC_GET_PWMTHRS(E, E2), - #else - E2_HYBRID_THRESHOLD, + #if MAX_EXTRUDERS > 3 + #if AXIS_HAS_STEALTHCHOP(E3) + tmc_hybrid_threshold.E3 = TMC_GET_PWMTHRS(E, E3); #endif - #if MAX_EXTRUDERS > 3 - #if AXIS_HAS_STEALTHCHOP(E3) - TMC_GET_PWMTHRS(E, E3), - #else - E3_HYBRID_THRESHOLD, + #if MAX_EXTRUDERS > 4 + #if AXIS_HAS_STEALTHCHOP(E4) + tmc_hybrid_threshold.E4 = TMC_GET_PWMTHRS(E, E4); #endif - #if MAX_EXTRUDERS > 4 - #if AXIS_HAS_STEALTHCHOP(E4) - TMC_GET_PWMTHRS(E, E4) - #else - E4_HYBRID_THRESHOLD - #endif - #if MAX_EXTRUDERS > 5 - #if AXIS_HAS_STEALTHCHOP(E5) - TMC_GET_PWMTHRS(E, E5) - #else - E5_HYBRID_THRESHOLD - #endif - #endif // MAX_EXTRUDERS > 5 - #endif // MAX_EXTRUDERS > 4 - #endif // MAX_EXTRUDERS > 3 - #endif // MAX_EXTRUDERS > 2 - #endif // MAX_EXTRUDERS > 1 - #endif // MAX_EXTRUDERS - #else - 100, 100, 3, // X, Y, Z - 100, 100, 3, 3 // X2, Y2, Z2, Z3 - #if MAX_EXTRUDERS - , 30 // E0 - #if MAX_EXTRUDERS > 1 - , 30 // E1 - #if MAX_EXTRUDERS > 2 - , 30 // E2 - #if MAX_EXTRUDERS > 3 - , 30 // E3 - #if MAX_EXTRUDERS > 4 - , 30 // E4 - #if MAX_EXTRUDERS > 5 - , 30 // E5 + #if MAX_EXTRUDERS > 5 + #if AXIS_HAS_STEALTHCHOP(E5) + tmc_hybrid_threshold.E5 = TMC_GET_PWMTHRS(E, E5); #endif - #endif - #endif - #endif - #endif - #endif - #endif - }; + #endif // MAX_EXTRUDERS > 5 + #endif // MAX_EXTRUDERS > 4 + #endif // MAX_EXTRUDERS > 3 + #endif // MAX_EXTRUDERS > 2 + #endif // MAX_EXTRUDERS > 1 + #endif // MAX_EXTRUDERS + #else + const tmc_hybrid_threshold_t tmc_hybrid_threshold = { + .X = 100, .Y = 100, .Z = 3, + .X2 = 100, .Y2 = 100, .Z2 = 3, .Z3 = 3, + .E0 = 30, .E1 = 30, .E2 = 30, + .E3 = 30, .E4 = 30, .E5 = 30 + }; + #endif EEPROM_WRITE(tmc_hybrid_threshold); // - // TMC2130 StallGuard threshold + // TMC StallGuard threshold // - int16_t tmc_sgt[XYZ] = { - #if USE_SENSORLESS - #if X_SENSORLESS - stepperX.sgt(), - #else - 0, - #endif - #if Y_SENSORLESS - stepperY.sgt(), - #else - 0, - #endif - #if Z_SENSORLESS - stepperZ.sgt() - #else - 0 - #endif - #else - 0 + + tmc_sgt_t tmc_sgt = { 0, 0, 0 }; + + #if USE_SENSORLESS + #if X_SENSORLESS + tmc_sgt.X = stepperX.sgt(); #endif - }; + #if Y_SENSORLESS + tmc_sgt.Y = stepperY.sgt(); + #endif + #if Z_SENSORLESS + tmc_sgt.Z = stepperZ.sgt(); + #endif + #endif EEPROM_WRITE(tmc_sgt); // @@ -1423,15 +1352,15 @@ void MarlinSettings::postprocess() { if (!validating) reset_stepper_drivers(); // - // TMC2130 Stepper Settings + // TMC Stepper Settings // _FIELD_TEST(tmc_stepper_current); #if HAS_TRINAMIC - #define SET_CURR(Q) stepper##Q.setCurrent(currents[TMC_##Q] ? currents[TMC_##Q] : Q##_CURRENT, R_SENSE, HOLD_MULTIPLIER) - uint16_t currents[TMC_AXES]; + #define SET_CURR(Q) stepper##Q.rms_current(currents.Q ? currents.Q : Q##_CURRENT) + tmc_stepper_current_t currents; EEPROM_READ(currents); if (!validating) { #if AXIS_IS_TMC(X) @@ -1480,8 +1409,8 @@ void MarlinSettings::postprocess() { #endif #if ENABLED(HYBRID_THRESHOLD) - #define TMC_SET_PWMTHRS(A,Q) tmc_set_pwmthrs(stepper##Q, tmc_hybrid_threshold[TMC_##Q], planner.axis_steps_per_mm[_AXIS(A)]) - uint32_t tmc_hybrid_threshold[TMC_AXES]; + #define TMC_SET_PWMTHRS(A,Q) tmc_set_pwmthrs(stepper##Q, tmc_hybrid_threshold.Q, planner.axis_steps_per_mm[_AXIS(A)]) + tmc_hybrid_threshold_t tmc_hybrid_threshold; EEPROM_READ(tmc_hybrid_threshold); if (!validating) { #if AXIS_HAS_STEALTHCHOP(X) @@ -1530,40 +1459,40 @@ void MarlinSettings::postprocess() { #endif /* - * TMC2130 StallGuard threshold. + * TMC StallGuard threshold. * X and X2 use the same value * Y and Y2 use the same value * Z, Z2 and Z3 use the same value */ - int16_t tmc_sgt[XYZ]; + tmc_sgt_t tmc_sgt; EEPROM_READ(tmc_sgt); #if USE_SENSORLESS if (!validating) { #ifdef X_STALL_SENSITIVITY #if AXIS_HAS_STALLGUARD(X) - stepperX.sgt(tmc_sgt[0]); + stepperX.sgt(tmc_sgt.X); #endif #if AXIS_HAS_STALLGUARD(X2) - stepperX2.sgt(tmc_sgt[0]); + stepperX2.sgt(tmc_sgt.X); #endif #endif #ifdef Y_STALL_SENSITIVITY #if AXIS_HAS_STALLGUARD(Y) - stepperY.sgt(tmc_sgt[1]); + stepperY.sgt(tmc_sgt.Y); #endif #if AXIS_HAS_STALLGUARD(Y2) - stepperY2.sgt(tmc_sgt[1]); + stepperY2.sgt(tmc_sgt.Y); #endif #endif #ifdef Z_STALL_SENSITIVITY #if AXIS_HAS_STALLGUARD(Z) - stepperZ.sgt(tmc_sgt[2]); + stepperZ.sgt(tmc_sgt.Z); #endif #if AXIS_HAS_STALLGUARD(Z2) - stepperZ2.sgt(tmc_sgt[2]); + stepperZ2.sgt(tmc_sgt.Z); #endif #if AXIS_HAS_STALLGUARD(Z3) - stepperZ3.sgt(tmc_sgt[2]); + stepperZ3.sgt(tmc_sgt.Z); #endif #endif } @@ -1957,8 +1886,7 @@ void MarlinSettings::reset(PORTARG_SOLO) { #endif // HAS_SERVOS && EDITABLE_SERVO_ANGLES #if ENABLED(DELTA) - const float adj[ABC] = DELTA_ENDSTOP_ADJ, - dta[ABC] = DELTA_TOWER_ANGLE_TRIM; + const float adj[ABC] = DELTA_ENDSTOP_ADJ, dta[ABC] = DELTA_TOWER_ANGLE_TRIM; delta_height = DELTA_HEIGHT; COPY(delta_endstop_adj, adj); delta_radius = DELTA_RADIUS; @@ -2683,7 +2611,7 @@ void MarlinSettings::reset(PORTARG_SOLO) { #if HAS_TRINAMIC /** - * TMC2130 / TMC2208 stepper driver current + * TMC stepper driver current */ if (!forReplay) { CONFIG_ECHO_START; @@ -2694,65 +2622,68 @@ void MarlinSettings::reset(PORTARG_SOLO) { say_M906(PORTVAR_SOLO); #endif #if AXIS_IS_TMC(X) - SERIAL_ECHOPAIR_P(port, " X", stepperX.getCurrent()); + SERIAL_ECHOPAIR_P(port, " X", stepperX.getMilliamps()); #endif #if AXIS_IS_TMC(Y) - SERIAL_ECHOPAIR_P(port, " Y", stepperY.getCurrent()); + SERIAL_ECHOPAIR_P(port, " Y", stepperY.getMilliamps()); #endif #if AXIS_IS_TMC(Z) - SERIAL_ECHOPAIR_P(port, " Z", stepperZ.getCurrent()); + SERIAL_ECHOPAIR_P(port, " Z", stepperZ.getMilliamps()); #endif #if AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z) SERIAL_EOL_P(port); #endif + #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2) say_M906(PORTVAR_SOLO); SERIAL_ECHOPGM_P(port, " I1"); #endif #if AXIS_IS_TMC(X2) - SERIAL_ECHOPAIR_P(port, " X", stepperX2.getCurrent()); + SERIAL_ECHOPAIR_P(port, " X", stepperX2.getMilliamps()); #endif #if AXIS_IS_TMC(Y2) - SERIAL_ECHOPAIR_P(port, " Y", stepperY2.getCurrent()); + SERIAL_ECHOPAIR_P(port, " Y", stepperY2.getMilliamps()); #endif #if AXIS_IS_TMC(Z2) - SERIAL_ECHOPAIR_P(port, " Z", stepperZ2.getCurrent()); + SERIAL_ECHOPAIR_P(port, " Z", stepperZ2.getMilliamps()); #endif #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2) SERIAL_EOL_P(port); #endif + #if AXIS_IS_TMC(Z3) say_M906(PORTVAR_SOLO); - SERIAL_ECHOLNPAIR_P(port, " I2 Z", stepperZ3.getCurrent()); + SERIAL_ECHOLNPAIR_P(port, " I2 Z", stepperZ3.getMilliamps()); #endif + #if AXIS_IS_TMC(E0) say_M906(PORTVAR_SOLO); - SERIAL_ECHOLNPAIR_P(port, " T0 E", stepperE0.getCurrent()); + SERIAL_ECHOLNPAIR_P(port, " T0 E", stepperE0.getMilliamps()); #endif #if AXIS_IS_TMC(E1) say_M906(PORTVAR_SOLO); - SERIAL_ECHOLNPAIR_P(port, " T1 E", stepperE1.getCurrent()); + SERIAL_ECHOLNPAIR_P(port, " T1 E", stepperE1.getMilliamps()); #endif #if AXIS_IS_TMC(E2) say_M906(PORTVAR_SOLO); - SERIAL_ECHOLNPAIR_P(port, " T2 E", stepperE2.getCurrent()); + SERIAL_ECHOLNPAIR_P(port, " T2 E", stepperE2.getMilliamps()); #endif #if AXIS_IS_TMC(E3) say_M906(PORTVAR_SOLO); - SERIAL_ECHOLNPAIR_P(port, " T3 E", stepperE3.getCurrent()); + SERIAL_ECHOLNPAIR_P(port, " T3 E", stepperE3.getMilliamps()); #endif #if AXIS_IS_TMC(E4) say_M906(PORTVAR_SOLO); - SERIAL_ECHOLNPAIR_P(port, " T4 E", stepperE4.getCurrent()); + SERIAL_ECHOLNPAIR_P(port, " T4 E", stepperE4.getMilliamps()); #endif #if AXIS_IS_TMC(E5) say_M906(PORTVAR_SOLO); - SERIAL_ECHOLNPAIR_P(port, " T5 E", stepperE5.getCurrent()); + SERIAL_ECHOLNPAIR_P(port, " T5 E", stepperE5.getMilliamps()); #endif SERIAL_EOL_P(port); /** - * TMC2130 / TMC2208 / TRAMS Hybrid Threshold + * TMC Hybrid Threshold */ #if ENABLED(HYBRID_THRESHOLD) if (!forReplay) { @@ -2760,63 +2691,66 @@ void MarlinSettings::reset(PORTARG_SOLO) { SERIAL_ECHOLNPGM_P(port, "Hybrid Threshold:"); } CONFIG_ECHO_START; - #if AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z) + #if AXIS_HAS_STEALTHCHOP(X) || AXIS_HAS_STEALTHCHOP(Y) || AXIS_HAS_STEALTHCHOP(Z) say_M913(PORTVAR_SOLO); #endif - #if AXIS_IS_TMC(X) + #if AXIS_HAS_STEALTHCHOP(X) SERIAL_ECHOPAIR_P(port, " X", TMC_GET_PWMTHRS(X, X)); #endif - #if AXIS_IS_TMC(Y) + #if AXIS_HAS_STEALTHCHOP(Y) SERIAL_ECHOPAIR_P(port, " Y", TMC_GET_PWMTHRS(Y, Y)); #endif - #if AXIS_IS_TMC(Z) + #if AXIS_HAS_STEALTHCHOP(Z) SERIAL_ECHOPAIR_P(port, " Z", TMC_GET_PWMTHRS(Z, Z)); #endif - #if AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z) + #if AXIS_HAS_STEALTHCHOP(X) || AXIS_HAS_STEALTHCHOP(Y) || AXIS_HAS_STEALTHCHOP(Z) SERIAL_EOL_P(port); #endif - #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2) + + #if AXIS_HAS_STEALTHCHOP(X2) || AXIS_HAS_STEALTHCHOP(Y2) || AXIS_HAS_STEALTHCHOP(Z2) say_M913(PORTVAR_SOLO); SERIAL_ECHOPGM_P(port, " I1"); #endif - #if AXIS_IS_TMC(X2) + #if AXIS_HAS_STEALTHCHOP(X2) SERIAL_ECHOPAIR_P(port, " X", TMC_GET_PWMTHRS(X, X2)); #endif - #if AXIS_IS_TMC(Y2) + #if AXIS_HAS_STEALTHCHOP(Y2) SERIAL_ECHOPAIR_P(port, " Y", TMC_GET_PWMTHRS(Y, Y2)); #endif - #if AXIS_IS_TMC(Z2) + #if AXIS_HAS_STEALTHCHOP(Z2) SERIAL_ECHOPAIR_P(port, " Z", TMC_GET_PWMTHRS(Z, Z2)); #endif - #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2) + #if AXIS_HAS_STEALTHCHOP(X2) || AXIS_HAS_STEALTHCHOP(Y2) || AXIS_HAS_STEALTHCHOP(Z2) SERIAL_EOL_P(port); #endif - #if AXIS_IS_TMC(Z3) + + #if AXIS_HAS_STEALTHCHOP(Z3) say_M913(PORTVAR_SOLO); SERIAL_ECHOPGM_P(port, " I2"); SERIAL_ECHOLNPAIR_P(port, " Z", TMC_GET_PWMTHRS(Z, Z3)); #endif - #if AXIS_IS_TMC(E0) + + #if AXIS_HAS_STEALTHCHOP(E0) say_M913(PORTVAR_SOLO); SERIAL_ECHOLNPAIR_P(port, " T0 E", TMC_GET_PWMTHRS(E, E0)); #endif - #if AXIS_IS_TMC(E1) + #if AXIS_HAS_STEALTHCHOP(E1) say_M913(PORTVAR_SOLO); SERIAL_ECHOLNPAIR_P(port, " T1 E", TMC_GET_PWMTHRS(E, E1)); #endif - #if AXIS_IS_TMC(E2) + #if AXIS_HAS_STEALTHCHOP(E2) say_M913(PORTVAR_SOLO); SERIAL_ECHOLNPAIR_P(port, " T2 E", TMC_GET_PWMTHRS(E, E2)); #endif - #if AXIS_IS_TMC(E3) + #if AXIS_HAS_STEALTHCHOP(E3) say_M913(PORTVAR_SOLO); SERIAL_ECHOLNPAIR_P(port, " T3 E", TMC_GET_PWMTHRS(E, E3)); #endif - #if AXIS_IS_TMC(E4) + #if AXIS_HAS_STEALTHCHOP(E4) say_M913(PORTVAR_SOLO); SERIAL_ECHOLNPAIR_P(port, " T4 E", TMC_GET_PWMTHRS(E, E4)); #endif - #if AXIS_IS_TMC(E5) + #if AXIS_HAS_STEALTHCHOP(E5) say_M913(PORTVAR_SOLO); SERIAL_ECHOLNPAIR_P(port, " T5 E", TMC_GET_PWMTHRS(E, E5)); #endif @@ -2824,7 +2758,7 @@ void MarlinSettings::reset(PORTARG_SOLO) { #endif // HYBRID_THRESHOLD /** - * TMC2130 Sensorless homing thresholds + * TMC Sensorless homing thresholds */ #if USE_SENSORLESS if (!forReplay) { diff --git a/Marlin/src/module/stepper_indirection.cpp b/Marlin/src/module/stepper_indirection.cpp index 86cd7c383..c6b641e93 100644 --- a/Marlin/src/module/stepper_indirection.cpp +++ b/Marlin/src/module/stepper_indirection.cpp @@ -139,170 +139,103 @@ } #endif // TMC26X +#if HAS_TRINAMIC + #define _TMC_INIT(ST, SPMM) tmc_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, SPMM) +#endif + // // TMC2130 Driver objects and inits // #if HAS_DRIVER(TMC2130) #include - #include #include "planner.h" #include "../core/enum.h" - #if TMC2130STEPPER_VERSION < 0x020201 - #error "Update TMC2130Stepper library to 2.2.1 or newer." - #endif - #if ENABLED(TMC_USE_SW_SPI) - #define _TMC2130_DEFINE(ST) TMC2130Stepper stepper##ST(ST##_ENABLE_PIN, ST##_DIR_PIN, ST##_STEP_PIN, ST##_CS_PIN, TMC_SW_MOSI, TMC_SW_MISO, TMC_SW_SCK) + #define _TMC2130_DEFINE(ST, L) TMCMarlin stepper##ST(ST##_CS_PIN, R_SENSE, TMC_SW_MOSI, TMC_SW_MISO, TMC_SW_SCK) + #define TMC2130_DEFINE(ST) _TMC2130_DEFINE(ST, TMC_##ST##_LABEL) #else - #define _TMC2130_DEFINE(ST) TMC2130Stepper stepper##ST(ST##_ENABLE_PIN, ST##_DIR_PIN, ST##_STEP_PIN, ST##_CS_PIN) + #define _TMC2130_DEFINE(ST, L) TMCMarlin stepper##ST(ST##_CS_PIN, R_SENSE) + #define TMC2130_DEFINE(ST) _TMC2130_DEFINE(ST, TMC_##ST##_LABEL) #endif - // Stepper objects of TMC2130 steppers used #if AXIS_DRIVER_TYPE(X, TMC2130) - _TMC2130_DEFINE(X); + TMC2130_DEFINE(X); #endif #if AXIS_DRIVER_TYPE(X2, TMC2130) - _TMC2130_DEFINE(X2); + TMC2130_DEFINE(X2); #endif #if AXIS_DRIVER_TYPE(Y, TMC2130) - _TMC2130_DEFINE(Y); + TMC2130_DEFINE(Y); #endif #if AXIS_DRIVER_TYPE(Y2, TMC2130) - _TMC2130_DEFINE(Y2); + TMC2130_DEFINE(Y2); #endif #if AXIS_DRIVER_TYPE(Z, TMC2130) - _TMC2130_DEFINE(Z); + TMC2130_DEFINE(Z); #endif #if AXIS_DRIVER_TYPE(Z2, TMC2130) - _TMC2130_DEFINE(Z2); + TMC2130_DEFINE(Z2); #endif #if AXIS_DRIVER_TYPE(Z3, TMC2130) - _TMC2130_DEFINE(Z3); + TMC2130_DEFINE(Z3); #endif #if AXIS_DRIVER_TYPE(E0, TMC2130) - _TMC2130_DEFINE(E0); + TMC2130_DEFINE(E0); #endif #if AXIS_DRIVER_TYPE(E1, TMC2130) - _TMC2130_DEFINE(E1); + TMC2130_DEFINE(E1); #endif #if AXIS_DRIVER_TYPE(E2, TMC2130) - _TMC2130_DEFINE(E2); + TMC2130_DEFINE(E2); #endif #if AXIS_DRIVER_TYPE(E3, TMC2130) - _TMC2130_DEFINE(E3); + TMC2130_DEFINE(E3); #endif #if AXIS_DRIVER_TYPE(E4, TMC2130) - _TMC2130_DEFINE(E4); + TMC2130_DEFINE(E4); #endif #if AXIS_DRIVER_TYPE(E5, TMC2130) - _TMC2130_DEFINE(E5); + TMC2130_DEFINE(E5); #endif - // Use internal reference voltage for current calculations. This is the default. - // Following values from Trinamic's spreadsheet with values for a NEMA17 (42BYGHW609) - // https://www.trinamic.com/products/integrated-circuits/details/tmc2130/ - void tmc2130_init(TMC2130Stepper &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) { + template + void tmc_init(TMCMarlin &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) { #if DISABLED(STEALTHCHOP) || DISABLED(HYBRID_THRESHOLD) UNUSED(thrs); UNUSED(spmm); #endif st.begin(); - st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER); + + CHOPCONF_t chopconf{0}; + chopconf.tbl = 1; + chopconf.toff = 3; + chopconf.intpol = INTERPOLATE; + chopconf.hstrt = 2; + chopconf.hend = 5; + st.CHOPCONF(chopconf.sr); + + st.rms_current(mA, HOLD_MULTIPLIER); st.microsteps(microsteps); - st.blank_time(24); - st.off_time(5); // Only enables the driver if used with stealthChop - st.interpolate(INTERPOLATE); - st.power_down_delay(128); // ~2s until driver lowers to hold current - st.hysteresis_start(3); - st.hysteresis_end(2); + st.iholddelay(10); + st.TPOWERDOWN(128); // ~2s until driver lowers to hold current + #if ENABLED(STEALTHCHOP) - st.stealth_freq(1); // f_pwm = 2/683 f_clk - st.stealth_autoscale(1); - st.stealth_gradient(5); - st.stealth_amplitude(255); - st.stealthChop(1); - #if ENABLED(HYBRID_THRESHOLD) - st.stealth_max_speed(12650000UL*microsteps/(256*thrs*spmm)); - #endif - #endif - st.GSTAT(); // Clear GSTAT - } + st.en_pwm_mode(true); - #define _TMC2130_INIT(ST, SPMM) tmc2130_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, SPMM) + PWMCONF_t pwmconf{0}; + pwmconf.pwm_freq = 0b01; // f_pwm = 2/683 f_clk + pwmconf.pwm_autoscale = true; + pwmconf.pwm_grad = 5; + pwmconf.pwm_ampl = 180; + st.PWMCONF(pwmconf.sr); - void tmc2130_init_to_defaults() { - #if AXIS_DRIVER_TYPE(X, TMC2130) - _TMC2130_INIT( X, planner.axis_steps_per_mm[X_AXIS]); - #endif - #if AXIS_DRIVER_TYPE(X2, TMC2130) - _TMC2130_INIT(X2, planner.axis_steps_per_mm[X_AXIS]); - #endif - #if AXIS_DRIVER_TYPE(Y, TMC2130) - _TMC2130_INIT( Y, planner.axis_steps_per_mm[Y_AXIS]); - #endif - #if AXIS_DRIVER_TYPE(Y2, TMC2130) - _TMC2130_INIT(Y2, planner.axis_steps_per_mm[Y_AXIS]); - #endif - #if AXIS_DRIVER_TYPE(Z, TMC2130) - _TMC2130_INIT( Z, planner.axis_steps_per_mm[Z_AXIS]); - #endif - #if AXIS_DRIVER_TYPE(Z2, TMC2130) - _TMC2130_INIT(Z2, planner.axis_steps_per_mm[Z_AXIS]); - #endif - #if AXIS_DRIVER_TYPE(Z3, TMC2130) - _TMC2130_INIT(Z3, planner.axis_steps_per_mm[Z_AXIS]); - #endif - #if AXIS_DRIVER_TYPE(E0, TMC2130) - _TMC2130_INIT(E0, planner.axis_steps_per_mm[E_AXIS]); - #endif - #if AXIS_DRIVER_TYPE(E1, TMC2130) - { constexpr uint8_t extruder = 1; _TMC2130_INIT(E1, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); } - #endif - #if AXIS_DRIVER_TYPE(E2, TMC2130) - { constexpr uint8_t extruder = 2; _TMC2130_INIT(E2, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); } - #endif - #if AXIS_DRIVER_TYPE(E3, TMC2130) - { constexpr uint8_t extruder = 3; _TMC2130_INIT(E3, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); } - #endif - #if AXIS_DRIVER_TYPE(E4, TMC2130) - { constexpr uint8_t extruder = 4; _TMC2130_INIT(E4, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); } - #endif - #if AXIS_DRIVER_TYPE(E5, TMC2130) - { constexpr uint8_t extruder = 5; _TMC2130_INIT(E5, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); } - #endif - - #if USE_SENSORLESS - #define TMC_INIT_SGT(P,Q) stepper##Q.sgt(P##_STALL_SENSITIVITY); - #if X_SENSORLESS - #if AXIS_DRIVER_TYPE(X, TMC2130) - stepperX.sgt(X_STALL_SENSITIVITY); - #endif - #if AXIS_DRIVER_TYPE(X2, TMC2130) - stepperX2.sgt(X_STALL_SENSITIVITY); - #endif - #endif - #if Y_SENSORLESS - #if AXIS_DRIVER_TYPE(Y, TMC2130) - stepperY.sgt(Y_STALL_SENSITIVITY); - #endif - #if AXIS_DRIVER_TYPE(Y2, TMC2130) - stepperY2.sgt(Y_STALL_SENSITIVITY); - #endif - #endif - #if Z_SENSORLESS - #if AXIS_DRIVER_TYPE(Z, TMC2130) - stepperZ.sgt(Z_STALL_SENSITIVITY); - #endif - #if AXIS_DRIVER_TYPE(Z2, TMC2130) - stepperZ2.sgt(Z_STALL_SENSITIVITY); - #endif - #if ENABLED(Z3_IS_TMC2130) - stepperZ3.sgt(Z_STALL_SENSITIVITY); - #endif + #if ENABLED(HYBRID_THRESHOLD) + st.TPWMTHRS(12650000UL*microsteps/(256*thrs*spmm)); #endif #endif + st.GSTAT(); // Clear GSTAT } #endif // TMC2130 @@ -311,106 +244,104 @@ // #if HAS_DRIVER(TMC2208) #include - #include #include "planner.h" - #if TMC2208STEPPER_VERSION < 0x000101 - #error "Update TMC2208Stepper library to 0.1.1 or newer." - #endif + #define _TMC2208_DEFINE_HARDWARE(ST, L) TMCMarlin stepper##ST(&ST##_HARDWARE_SERIAL, R_SENSE) + #define TMC2208_DEFINE_HARDWARE(ST) _TMC2208_DEFINE_HARDWARE(ST, TMC_##ST##_LABEL) - #define _TMC2208_DEFINE_HARDWARE(ST) TMC2208Stepper stepper##ST(&ST##_HARDWARE_SERIAL) - #define _TMC2208_DEFINE_SOFTWARE(ST) TMC2208Stepper stepper##ST(ST##_SERIAL_RX_PIN, ST##_SERIAL_TX_PIN, ST##_SERIAL_RX_PIN > -1) + #define _TMC2208_DEFINE_SOFTWARE(ST, L) TMCMarlin stepper##ST(ST##_SERIAL_RX_PIN, ST##_SERIAL_TX_PIN, R_SENSE, ST##_SERIAL_RX_PIN > -1) + #define TMC2208_DEFINE_SOFTWARE(ST) _TMC2208_DEFINE_SOFTWARE(ST, TMC_##ST##_LABEL) // Stepper objects of TMC2208 steppers used #if AXIS_DRIVER_TYPE(X, TMC2208) #ifdef X_HARDWARE_SERIAL - _TMC2208_DEFINE_HARDWARE(X); + TMC2208_DEFINE_HARDWARE(X); #else - _TMC2208_DEFINE_SOFTWARE(X); + TMC2208_DEFINE_SOFTWARE(X); #endif #endif #if AXIS_DRIVER_TYPE(X2, TMC2208) #ifdef X2_HARDWARE_SERIAL - _TMC2208_DEFINE_HARDWARE(X2); + TMC2208_DEFINE_HARDWARE(X2); #else - _TMC2208_DEFINE_SOFTWARE(X2); + TMC2208_DEFINE_SOFTWARE(X2); #endif #endif #if AXIS_DRIVER_TYPE(Y, TMC2208) #ifdef Y_HARDWARE_SERIAL - _TMC2208_DEFINE_HARDWARE(Y); + TMC2208_DEFINE_HARDWARE(Y); #else - _TMC2208_DEFINE_SOFTWARE(Y); + TMC2208_DEFINE_SOFTWARE(Y); #endif #endif #if AXIS_DRIVER_TYPE(Y2, TMC2208) #ifdef Y2_HARDWARE_SERIAL - _TMC2208_DEFINE_HARDWARE(Y2); + TMC2208_DEFINE_HARDWARE(Y2); #else - _TMC2208_DEFINE_SOFTWARE(Y2); + TMC2208_DEFINE_SOFTWARE(Y2); #endif #endif #if AXIS_DRIVER_TYPE(Z, TMC2208) #ifdef Z_HARDWARE_SERIAL - _TMC2208_DEFINE_HARDWARE(Z); + TMC2208_DEFINE_HARDWARE(Z); #else - _TMC2208_DEFINE_SOFTWARE(Z); + TMC2208_DEFINE_SOFTWARE(Z); #endif #endif #if AXIS_DRIVER_TYPE(Z2, TMC2208) #ifdef Z2_HARDWARE_SERIAL - _TMC2208_DEFINE_HARDWARE(Z2); + TMC2208_DEFINE_HARDWARE(Z2); #else - _TMC2208_DEFINE_SOFTWARE(Z2); + TMC2208_DEFINE_SOFTWARE(Z2); #endif #endif #if AXIS_DRIVER_TYPE(Z3, TMC2208) #ifdef Z3_HARDWARE_SERIAL - _TMC2208_DEFINE_HARDWARE(Z3); + TMC2208_DEFINE_HARDWARE(Z3); #else - _TMC2208_DEFINE_SOFTWARE(Z3); + TMC2208_DEFINE_SOFTWARE(Z3); #endif #endif #if AXIS_DRIVER_TYPE(E0, TMC2208) #ifdef E0_HARDWARE_SERIAL - _TMC2208_DEFINE_HARDWARE(E0); + TMC2208_DEFINE_HARDWARE(E0); #else - _TMC2208_DEFINE_SOFTWARE(E0); + TMC2208_DEFINE_SOFTWARE(E0); #endif #endif #if AXIS_DRIVER_TYPE(E1, TMC2208) #ifdef E1_HARDWARE_SERIAL - _TMC2208_DEFINE_HARDWARE(E1); + TMC2208_DEFINE_HARDWARE(E1); #else - _TMC2208_DEFINE_SOFTWARE(E1); + TMC2208_DEFINE_SOFTWARE(E1); #endif #endif #if AXIS_DRIVER_TYPE(E2, TMC2208) #ifdef E2_HARDWARE_SERIAL - _TMC2208_DEFINE_HARDWARE(E2); + TMC2208_DEFINE_HARDWARE(E2); #else - _TMC2208_DEFINE_SOFTWARE(E2); + TMC2208_DEFINE_SOFTWARE(E2); #endif #endif #if AXIS_DRIVER_TYPE(E3, TMC2208) #ifdef E3_HARDWARE_SERIAL - _TMC2208_DEFINE_HARDWARE(E3); + TMC2208_DEFINE_HARDWARE(E3); #else - _TMC2208_DEFINE_SOFTWARE(E3); + TMC2208_DEFINE_SOFTWARE(E3); #endif #endif #if AXIS_DRIVER_TYPE(E4, TMC2208) #ifdef E4_HARDWARE_SERIAL - _TMC2208_DEFINE_HARDWARE(E4); + TMC2208_DEFINE_HARDWARE(E4); #else - _TMC2208_DEFINE_SOFTWARE(E4); + TMC2208_DEFINE_SOFTWARE(E4); #endif #endif #if AXIS_DRIVER_TYPE(E5, TMC2208) #ifdef E5_HARDWARE_SERIAL - _TMC2208_DEFINE_HARDWARE(E5); + TMC2208_DEFINE_HARDWARE(E5); #else - _TMC2208_DEFINE_SOFTWARE(E5); + TMC2208_DEFINE_SOFTWARE(E5); #endif #endif @@ -508,85 +439,52 @@ #endif } - // Use internal reference voltage for current calculations. This is the default. - // Following values from Trinamic's spreadsheet with values for a NEMA17 (42BYGHW609) - void tmc2208_init(TMC2208Stepper &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) { - st.pdn_disable(true); // Use UART - st.mstep_reg_select(true); // Select microsteps with UART - st.I_scale_analog(false); - st.rms_current(mA, HOLD_MULTIPLIER, R_SENSE); + template + void tmc_init(TMCMarlin &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) { + #if DISABLED(STEALTHCHOP) || DISABLED(HYBRID_THRESHOLD) + UNUSED(thrs); + UNUSED(spmm); + #endif + + TMC2208_n::GCONF_t gconf{0}; + gconf.pdn_disable = true; // Use UART + gconf.mstep_reg_select = true; // Select microsteps with UART + gconf.i_scale_analog = false; + + TMC2208_n::CHOPCONF_t chopconf{0}; + chopconf.tbl = 0b01; // blank_time = 24 + chopconf.toff = 5; + chopconf.intpol = INTERPOLATE; + chopconf.hstrt = 2; + chopconf.hend = 5; + st.CHOPCONF(chopconf.sr); + + st.rms_current(mA, HOLD_MULTIPLIER); st.microsteps(microsteps); - st.blank_time(24); - st.toff(5); - st.intpol(INTERPOLATE); + st.iholddelay(10); st.TPOWERDOWN(128); // ~2s until driver lowers to hold current - st.hysteresis_start(3); - st.hysteresis_end(2); #if ENABLED(STEALTHCHOP) - st.pwm_lim(12); - st.pwm_reg(8); - st.pwm_autograd(1); - st.pwm_autoscale(1); - st.pwm_freq(1); - st.pwm_grad(14); - st.pwm_ofs(36); - st.en_spreadCycle(false); + gconf.en_spreadcycle = false; + + TMC2208_n::PWMCONF_t pwmconf{0}; + pwmconf.pwm_lim = 12; + pwmconf.pwm_reg = 8; + pwmconf.pwm_autograd = true; + pwmconf.pwm_autoscale = true; + pwmconf.pwm_freq = 0b01; + pwmconf.pwm_grad = 14; + pwmconf.pwm_ofs = 36; + st.PWMCONF(pwmconf.sr); #if ENABLED(HYBRID_THRESHOLD) st.TPWMTHRS(12650000UL*microsteps/(256*thrs*spmm)); - #else - UNUSED(thrs); - UNUSED(spmm); #endif #else - st.en_spreadCycle(true); + gconf.en_spreadcycle = true; #endif + st.GCONF(gconf.sr); st.GSTAT(0b111); // Clear delay(200); } - - #define _TMC2208_INIT(ST, SPMM) tmc2208_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, SPMM) - - void tmc2208_init_to_defaults() { - #if AXIS_DRIVER_TYPE(X, TMC2208) - _TMC2208_INIT(X, planner.axis_steps_per_mm[X_AXIS]); - #endif - #if AXIS_DRIVER_TYPE(X2, TMC2208) - _TMC2208_INIT(X2, planner.axis_steps_per_mm[X_AXIS]); - #endif - #if AXIS_DRIVER_TYPE(Y, TMC2208) - _TMC2208_INIT(Y, planner.axis_steps_per_mm[Y_AXIS]); - #endif - #if AXIS_DRIVER_TYPE(Y2, TMC2208) - _TMC2208_INIT(Y2, planner.axis_steps_per_mm[Y_AXIS]); - #endif - #if AXIS_DRIVER_TYPE(Z, TMC2208) - _TMC2208_INIT(Z, planner.axis_steps_per_mm[Z_AXIS]); - #endif - #if AXIS_DRIVER_TYPE(Z2, TMC2208) - _TMC2208_INIT(Z2, planner.axis_steps_per_mm[Z_AXIS]); - #endif - #if AXIS_DRIVER_TYPE(Z3, TMC2208) - _TMC2208_INIT(Z3, planner.axis_steps_per_mm[Z_AXIS]); - #endif - #if AXIS_DRIVER_TYPE(E0, TMC2208) - _TMC2208_INIT(E0, planner.axis_steps_per_mm[E_AXIS]); - #endif - #if AXIS_DRIVER_TYPE(E1, TMC2208) - { constexpr int extruder = 1; _TMC2208_INIT(E1, planner.axis_steps_per_mm[E_AXIS_N]); } - #endif - #if AXIS_DRIVER_TYPE(E2, TMC2208) - { constexpr int extruder = 2; _TMC2208_INIT(E2, planner.axis_steps_per_mm[E_AXIS_N]); } - #endif - #if AXIS_DRIVER_TYPE(E3, TMC2208) - { constexpr int extruder = 3; _TMC2208_INIT(E3, planner.axis_steps_per_mm[E_AXIS_N]); } - #endif - #if AXIS_DRIVER_TYPE(E4, TMC2208) - { constexpr int extruder = 4; _TMC2208_INIT(E4, planner.axis_steps_per_mm[E_AXIS_N]); } - #endif - #if AXIS_DRIVER_TYPE(E5, TMC2208) - { constexpr int extruder = 5; _TMC2208_INIT(E5, planner.axis_steps_per_mm[E_AXIS_N]); } - #endif - } #endif // TMC2208 void restore_stepper_drivers() { @@ -635,20 +533,84 @@ void reset_stepper_drivers() { #if HAS_DRIVER(TMC26X) tmc26x_init_to_defaults(); #endif - #if HAS_DRIVER(TMC2130) - delay(100); - tmc2130_init_to_defaults(); + #if ENABLED(HAVE_L6470DRIVER) + L6470_init_to_defaults(); + #endif + + #if AXIS_IS_TMC(X) + _TMC_INIT(X, planner.axis_steps_per_mm[X_AXIS]); + #endif + #if AXIS_IS_TMC(X2) + _TMC_INIT(X2, planner.axis_steps_per_mm[X_AXIS]); + #endif + #if AXIS_IS_TMC(Y) + _TMC_INIT(Y, planner.axis_steps_per_mm[Y_AXIS]); + #endif + #if AXIS_IS_TMC(Y2) + _TMC_INIT(Y2, planner.axis_steps_per_mm[Y_AXIS]); + #endif + #if AXIS_IS_TMC(Z) + _TMC_INIT(Z, planner.axis_steps_per_mm[Z_AXIS]); + #endif + #if AXIS_IS_TMC(Z2) + _TMC_INIT(Z2, planner.axis_steps_per_mm[Z_AXIS]); + #endif + #if AXIS_IS_TMC(Z3) + _TMC_INIT(Z3, planner.axis_steps_per_mm[Z_AXIS]); + #endif + #if AXIS_IS_TMC(E0) + _TMC_INIT(E0, planner.axis_steps_per_mm[E_AXIS]); + #endif + #if AXIS_IS_TMC(E1) + { constexpr uint8_t extruder = 1; _TMC_INIT(E1, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); } + #endif + #if AXIS_IS_TMC(E2) + { constexpr uint8_t extruder = 2; _TMC_INIT(E2, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); } #endif - #if HAS_DRIVER(TMC2208) - delay(100); - tmc2208_init_to_defaults(); + #if AXIS_IS_TMC(E3) + { constexpr uint8_t extruder = 3; _TMC_INIT(E3, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); } + #endif + #if AXIS_IS_TMC(E4) + { constexpr uint8_t extruder = 4; _TMC_INIT(E4, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); } + #endif + #if AXIS_IS_TMC(E5) + { constexpr uint8_t extruder = 5; _TMC_INIT(E5, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); } + #endif + + #if ENABLED(SENSORLESS_HOMING) + #if X_SENSORLESS + #if AXIS_HAS_STALLGUARD(X) + stepperX.sgt(X_STALL_SENSITIVITY); + #endif + #if AXIS_HAS_STALLGUARD(X2) + stepperX2.sgt(X_STALL_SENSITIVITY); + #endif + #endif + #if Y_SENSORLESS + #if AXIS_HAS_STALLGUARD(Y) + stepperY.sgt(Y_STALL_SENSITIVITY); + #endif + #if AXIS_HAS_STALLGUARD(Y2) + stepperY2.sgt(Y_STALL_SENSITIVITY); + #endif + #endif + #if Z_SENSORLESS + #if AXIS_HAS_STALLGUARD(Z) + stepperZ.sgt(Z_STALL_SENSITIVITY); + #endif + #if AXIS_HAS_STALLGUARD(Z2) + stepperZ2.sgt(Z_STALL_SENSITIVITY); + #endif + #if AXIS_HAS_STALLGUARD(Z3) + stepperZ3.sgt(Z_STALL_SENSITIVITY); + #endif + #endif #endif + #ifdef TMC_ADV TMC_ADV() #endif - #if HAS_DRIVER(L6470) - L6470_init_to_defaults(); - #endif + stepper.set_directions(); } diff --git a/Marlin/src/module/stepper_indirection.h b/Marlin/src/module/stepper_indirection.h index 1a615e395..3f884c25d 100644 --- a/Marlin/src/module/stepper_indirection.h +++ b/Marlin/src/module/stepper_indirection.h @@ -57,15 +57,20 @@ void tmc26x_init_to_defaults(); #endif -#if HAS_DRIVER(TMC2130) - #include - void tmc2130_init_to_defaults(); -#endif +#if HAS_TRINAMIC + #include + #include "../feature/tmc_util.h" + #if TMCSTEPPER_VERSION < 0x000001 + #error "Update TMCStepper library to 0.0.1 or newer." + #endif -#if HAS_DRIVER(TMC2208) - #include - void tmc2208_serial_begin(); - void tmc2208_init_to_defaults(); + #define __TMC_CLASS(MODEL, A, I) TMCMarlin + #define _TMC_CLASS(MODEL, L) __TMC_CLASS(MODEL, L) + #define TMC_CLASS(ST) _TMC_CLASS(ST##_DRIVER_TYPE, TMC_##ST##_LABEL) + + #if HAS_DRIVER(TMC2208) + void tmc2208_serial_begin(); + #endif #endif // L6470 has STEP on normal pins, but DIR/ENABLE via SPI @@ -88,17 +93,15 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #define X_DIR_WRITE(STATE) stepperX.Step_Clock(STATE) #define X_DIR_READ (stepperX.getStatus() & STATUS_DIR) #else + #if AXIS_IS_TMC(X) + extern TMC_CLASS(X) stepperX; + #endif #if AXIS_DRIVER_TYPE(X, TMC26X) extern TMC26XStepper stepperX; #define X_ENABLE_INIT NOOP #define X_ENABLE_WRITE(STATE) stepperX.setEnabled(STATE) #define X_ENABLE_READ stepperX.isEnabled() #else - #if AXIS_DRIVER_TYPE(X, TMC2130) - extern TMC2130Stepper stepperX; - #elif AXIS_DRIVER_TYPE(X, TMC2208) - extern TMC2208Stepper stepperX; - #endif #define X_ENABLE_INIT SET_OUTPUT(X_ENABLE_PIN) #define X_ENABLE_WRITE(STATE) WRITE(X_ENABLE_PIN,STATE) #define X_ENABLE_READ READ(X_ENABLE_PIN) @@ -121,17 +124,15 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #define Y_DIR_WRITE(STATE) stepperY.Step_Clock(STATE) #define Y_DIR_READ (stepperY.getStatus() & STATUS_DIR) #else + #if AXIS_IS_TMC(Y) + extern TMC_CLASS(Y) stepperY; + #endif #if AXIS_DRIVER_TYPE(Y, TMC26X) extern TMC26XStepper stepperY; #define Y_ENABLE_INIT NOOP #define Y_ENABLE_WRITE(STATE) stepperY.setEnabled(STATE) #define Y_ENABLE_READ stepperY.isEnabled() #else - #if AXIS_DRIVER_TYPE(Y, TMC2130) - extern TMC2130Stepper stepperY; - #elif AXIS_DRIVER_TYPE(Y, TMC2208) - extern TMC2208Stepper stepperY; - #endif #define Y_ENABLE_INIT SET_OUTPUT(Y_ENABLE_PIN) #define Y_ENABLE_WRITE(STATE) WRITE(Y_ENABLE_PIN,STATE) #define Y_ENABLE_READ READ(Y_ENABLE_PIN) @@ -154,17 +155,15 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #define Z_DIR_WRITE(STATE) stepperZ.Step_Clock(STATE) #define Z_DIR_READ (stepperZ.getStatus() & STATUS_DIR) #else + #if AXIS_IS_TMC(Z) + extern TMC_CLASS(Z) stepperZ; + #endif #if AXIS_DRIVER_TYPE(Z, TMC26X) extern TMC26XStepper stepperZ; #define Z_ENABLE_INIT NOOP #define Z_ENABLE_WRITE(STATE) stepperZ.setEnabled(STATE) #define Z_ENABLE_READ stepperZ.isEnabled() #else - #if AXIS_DRIVER_TYPE(Z, TMC2130) - extern TMC2130Stepper stepperZ; - #elif AXIS_DRIVER_TYPE(Z, TMC2208) - extern TMC2208Stepper stepperZ; - #endif #define Z_ENABLE_INIT SET_OUTPUT(Z_ENABLE_PIN) #define Z_ENABLE_WRITE(STATE) WRITE(Z_ENABLE_PIN,STATE) #define Z_ENABLE_READ READ(Z_ENABLE_PIN) @@ -188,17 +187,15 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #define X2_DIR_WRITE(STATE) stepperX2.Step_Clock(STATE) #define X2_DIR_READ (stepperX2.getStatus() & STATUS_DIR) #else + #if AXIS_IS_TMC(X2) + extern TMC_CLASS(X2) stepperX2; + #endif #if AXIS_DRIVER_TYPE(X2, TMC26X) extern TMC26XStepper stepperX2; #define X2_ENABLE_INIT NOOP #define X2_ENABLE_WRITE(STATE) stepperX2.setEnabled(STATE) #define X2_ENABLE_READ stepperX2.isEnabled() #else - #if AXIS_DRIVER_TYPE(X2, TMC2130) - extern TMC2130Stepper stepperX2; - #elif AXIS_DRIVER_TYPE(X2, TMC2208) - extern TMC2208Stepper stepperX2; - #endif #define X2_ENABLE_INIT SET_OUTPUT(X2_ENABLE_PIN) #define X2_ENABLE_WRITE(STATE) WRITE(X2_ENABLE_PIN,STATE) #define X2_ENABLE_READ READ(X2_ENABLE_PIN) @@ -223,17 +220,15 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #define Y2_DIR_WRITE(STATE) stepperY2.Step_Clock(STATE) #define Y2_DIR_READ (stepperY2.getStatus() & STATUS_DIR) #else + #if AXIS_IS_TMC(Y2) + extern TMC_CLASS(Y2) stepperY2; + #endif #if AXIS_DRIVER_TYPE(Y2, TMC26X) extern TMC26XStepper stepperY2; #define Y2_ENABLE_INIT NOOP #define Y2_ENABLE_WRITE(STATE) stepperY2.setEnabled(STATE) #define Y2_ENABLE_READ stepperY2.isEnabled() #else - #if AXIS_DRIVER_TYPE(Y2, TMC2130) - extern TMC2130Stepper stepperY2; - #elif AXIS_DRIVER_TYPE(Y2, TMC2208) - extern TMC2208Stepper stepperY2; - #endif #define Y2_ENABLE_INIT SET_OUTPUT(Y2_ENABLE_PIN) #define Y2_ENABLE_WRITE(STATE) WRITE(Y2_ENABLE_PIN,STATE) #define Y2_ENABLE_READ READ(Y2_ENABLE_PIN) @@ -258,17 +253,15 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #define Z2_DIR_WRITE(STATE) stepperZ2.Step_Clock(STATE) #define Z2_DIR_READ (stepperZ2.getStatus() & STATUS_DIR) #else + #if AXIS_IS_TMC(Z2) + extern TMC_CLASS(Z2) stepperZ2; + #endif #if AXIS_DRIVER_TYPE(Z2, TMC26X) extern TMC26XStepper stepperZ2; #define Z2_ENABLE_INIT NOOP #define Z2_ENABLE_WRITE(STATE) stepperZ2.setEnabled(STATE) #define Z2_ENABLE_READ stepperZ2.isEnabled() #else - #if AXIS_DRIVER_TYPE(Z2, TMC2130) - extern TMC2130Stepper stepperZ2; - #elif AXIS_DRIVER_TYPE(Z2, TMC2208) - extern TMC2208Stepper stepperZ2; - #endif #define Z2_ENABLE_INIT SET_OUTPUT(Z2_ENABLE_PIN) #define Z2_ENABLE_WRITE(STATE) WRITE(Z2_ENABLE_PIN,STATE) #define Z2_ENABLE_READ READ(Z2_ENABLE_PIN) @@ -293,17 +286,15 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #define Z3_DIR_WRITE(STATE) stepperZ3.Step_Clock(STATE) #define Z3_DIR_READ (stepperZ3.getStatus() & STATUS_DIR) #else + #if AXIS_IS_TMC(Z3) + extern TMC_CLASS(Z3) stepperZ3; + #endif #if ENABLED(Z3_IS_TMC26X) extern TMC26XStepper stepperZ3; #define Z3_ENABLE_INIT NOOP #define Z3_ENABLE_WRITE(STATE) stepperZ3.setEnabled(STATE) #define Z3_ENABLE_READ stepperZ3.isEnabled() #else - #if ENABLED(Z3_IS_TMC2130) - extern TMC2130Stepper stepperZ3; - #elif ENABLED(Z3_IS_TMC2208) - extern TMC2208Stepper stepperZ3; - #endif #define Z3_ENABLE_INIT SET_OUTPUT(Z3_ENABLE_PIN) #define Z3_ENABLE_WRITE(STATE) WRITE(Z3_ENABLE_PIN,STATE) #define Z3_ENABLE_READ READ(Z3_ENABLE_PIN) @@ -327,17 +318,15 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #define E0_DIR_WRITE(STATE) stepperE0.Step_Clock(STATE) #define E0_DIR_READ (stepperE0.getStatus() & STATUS_DIR) #else + #if AXIS_IS_TMC(E0) + extern TMC_CLASS(E0) stepperE0; + #endif #if AXIS_DRIVER_TYPE(E0, TMC26X) extern TMC26XStepper stepperE0; #define E0_ENABLE_INIT NOOP #define E0_ENABLE_WRITE(STATE) stepperE0.setEnabled(STATE) #define E0_ENABLE_READ stepperE0.isEnabled() #else - #if AXIS_DRIVER_TYPE(E0, TMC2130) - extern TMC2130Stepper stepperE0; - #elif AXIS_DRIVER_TYPE(E0, TMC2208) - extern TMC2208Stepper stepperE0; - #endif #define E0_ENABLE_INIT SET_OUTPUT(E0_ENABLE_PIN) #define E0_ENABLE_WRITE(STATE) WRITE(E0_ENABLE_PIN,STATE) #define E0_ENABLE_READ READ(E0_ENABLE_PIN) @@ -360,17 +349,15 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #define E1_DIR_WRITE(STATE) stepperE1.Step_Clock(STATE) #define E1_DIR_READ (stepperE1.getStatus() & STATUS_DIR) #else + #if AXIS_IS_TMC(E1) + extern TMC_CLASS(E1) stepperE1; + #endif #if AXIS_DRIVER_TYPE(E1, TMC26X) extern TMC26XStepper stepperE1; #define E1_ENABLE_INIT NOOP #define E1_ENABLE_WRITE(STATE) stepperE1.setEnabled(STATE) #define E1_ENABLE_READ stepperE1.isEnabled() #else - #if AXIS_DRIVER_TYPE(E1, TMC2130) - extern TMC2130Stepper stepperE1; - #elif AXIS_DRIVER_TYPE(E1, TMC2208) - extern TMC2208Stepper stepperE1; - #endif #define E1_ENABLE_INIT SET_OUTPUT(E1_ENABLE_PIN) #define E1_ENABLE_WRITE(STATE) WRITE(E1_ENABLE_PIN,STATE) #define E1_ENABLE_READ READ(E1_ENABLE_PIN) @@ -393,17 +380,15 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #define E2_DIR_WRITE(STATE) stepperE2.Step_Clock(STATE) #define E2_DIR_READ (stepperE2.getStatus() & STATUS_DIR) #else + #if AXIS_IS_TMC(E2) + extern TMC_CLASS(E2) stepperE2; + #endif #if AXIS_DRIVER_TYPE(E2, TMC26X) extern TMC26XStepper stepperE2; #define E2_ENABLE_INIT NOOP #define E2_ENABLE_WRITE(STATE) stepperE2.setEnabled(STATE) #define E2_ENABLE_READ stepperE2.isEnabled() #else - #if AXIS_DRIVER_TYPE(E2, TMC2130) - extern TMC2130Stepper stepperE2; - #elif AXIS_DRIVER_TYPE(E2, TMC2208) - extern TMC2208Stepper stepperE2; - #endif #define E2_ENABLE_INIT SET_OUTPUT(E2_ENABLE_PIN) #define E2_ENABLE_WRITE(STATE) WRITE(E2_ENABLE_PIN,STATE) #define E2_ENABLE_READ READ(E2_ENABLE_PIN) @@ -426,17 +411,15 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #define E3_DIR_WRITE(STATE) stepperE3.Step_Clock(STATE) #define E3_DIR_READ (stepperE3.getStatus() & STATUS_DIR) #else + #if AXIS_IS_TMC(E3) + extern TMC_CLASS(E3) stepperE3; + #endif #if AXIS_DRIVER_TYPE(E3, TMC26X) extern TMC26XStepper stepperE3; #define E3_ENABLE_INIT NOOP #define E3_ENABLE_WRITE(STATE) stepperE3.setEnabled(STATE) #define E3_ENABLE_READ stepperE3.isEnabled() #else - #if AXIS_DRIVER_TYPE(E3, TMC2130) - extern TMC2130Stepper stepperE3; - #elif AXIS_DRIVER_TYPE(E3, TMC2208) - extern TMC2208Stepper stepperE3; - #endif #define E3_ENABLE_INIT SET_OUTPUT(E3_ENABLE_PIN) #define E3_ENABLE_WRITE(STATE) WRITE(E3_ENABLE_PIN,STATE) #define E3_ENABLE_READ READ(E3_ENABLE_PIN) @@ -459,17 +442,15 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #define E4_DIR_WRITE(STATE) stepperE4.Step_Clock(STATE) #define E4_DIR_READ (stepperE4.getStatus() & STATUS_DIR) #else + #if AXIS_IS_TMC(E4) + extern TMC_CLASS(E4) stepperE4; + #endif #if AXIS_DRIVER_TYPE(E4, TMC26X) extern TMC26XStepper stepperE4; #define E4_ENABLE_INIT NOOP #define E4_ENABLE_WRITE(STATE) stepperE4.setEnabled(STATE) #define E4_ENABLE_READ stepperE4.isEnabled() #else - #if AXIS_DRIVER_TYPE(E4, TMC2130) - extern TMC2130Stepper stepperE4; - #elif AXIS_DRIVER_TYPE(E4, TMC2208) - extern TMC2208Stepper stepperE4; - #endif #define E4_ENABLE_INIT SET_OUTPUT(E4_ENABLE_PIN) #define E4_ENABLE_WRITE(STATE) WRITE(E4_ENABLE_PIN,STATE) #define E4_ENABLE_READ READ(E4_ENABLE_PIN) @@ -492,17 +473,15 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #define E5_DIR_WRITE(STATE) stepperE5.Step_Clock(STATE) #define E5_DIR_READ (stepperE5.getStatus() & STATUS_DIR) #else + #if AXIS_IS_TMC(E5) + extern TMC_CLASS(E5) stepperE5; + #endif #if AXIS_DRIVER_TYPE(E5, TMC26X) extern TMC26XStepper stepperE5; #define E5_ENABLE_INIT NOOP #define E5_ENABLE_WRITE(STATE) stepperE5.setEnabled(STATE) #define E5_ENABLE_READ stepperE5.isEnabled() #else - #if AXIS_DRIVER_TYPE(E5, TMC2130) - extern TMC2130Stepper stepperE5; - #elif AXIS_DRIVER_TYPE(E5, TMC2208) - extern TMC2208Stepper stepperE5; - #endif #define E5_ENABLE_INIT SET_OUTPUT(E5_ENABLE_PIN) #define E5_ENABLE_WRITE(STATE) WRITE(E5_ENABLE_PIN,STATE) #define E5_ENABLE_READ READ(E5_ENABLE_PIN) diff --git a/platformio.ini b/platformio.ini index 77756c664..cf438d4f5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -31,8 +31,7 @@ build_flags = -fmax-errors=5 lib_deps = https://github.com/MarlinFirmware/U8glib-HAL/archive/dev.zip LiquidCrystal@1.3.4 - TMC2130Stepper - https://github.com/teemuatlut/TMC2208Stepper/archive/v0.2.5.zip + https://github.com/teemuatlut/TMCStepper.git Adafruit NeoPixel@1.1.3 https://github.com/lincomatic/LiquidTWI2/archive/30aa480.zip https://github.com/ameyer/Arduino-L6470/archive/master.zip @@ -162,7 +161,7 @@ lib_ldf_mode = off lib_extra_dirs = frameworks lib_deps = CMSIS-LPC1768 https://github.com/MarlinFirmware/U8glib-HAL/archive/dev.zip - TMC2130Stepper@>=2.2.1 + https://github.com/teemuatlut/TMCStepper.git extra_scripts = Marlin/src/HAL/HAL_LPC1768/debug_extra_script.py, Marlin/src/HAL/HAL_LPC1768/lpc1768_flag_script.py, Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py src_filter = ${common.default_src_filter} + monitor_speed = 250000 @@ -270,7 +269,7 @@ framework = arduino board = disco_f407vg build_flags = ${common.build_flags} -DUSE_STM32GENERIC -DSTM32GENERIC -DMENU_USB_SERIAL -DMENU_SERIAL=SerialUSB lib_deps = ${common.lib_deps} -lib_ignore = Adafruit NeoPixel, c1921b4, TMC2130Stepper +lib_ignore = Adafruit NeoPixel, c1921b4, TMCStepper src_filter = ${common.default_src_filter} + monitor_speed = 250000 @@ -301,11 +300,10 @@ lib_ignore = NewliquidCrystal LiquidTWI2 Adafruit NeoPixel - TMC2130Stepper + TMCStepper Servo(STM32F1) TMC26XStepper U8glib-HAL - TMC2208Stepper c1921b4 #