Migrate to a new TMC library (#11943)

This commit is contained in:
teemuatlut 2018-10-03 10:48:49 +03:00 committed by Scott Lahteine
parent 2abf3d258d
commit c3229e1b34
14 changed files with 795 additions and 968 deletions

View file

@ -736,6 +736,9 @@ void setup() {
SERIAL_ECHO_START(); SERIAL_ECHO_START();
#if HAS_DRIVER(TMC2130) #if HAS_DRIVER(TMC2130)
#if DISABLED(TMC_USE_SW_SPI)
SPI.begin();
#endif
tmc_init_cs_pins(); tmc_init_cs_pins();
#endif #endif
#if HAS_DRIVER(TMC2208) #if HAS_DRIVER(TMC2208)

View file

@ -31,9 +31,9 @@
#define TB6560 0x006 #define TB6560 0x006
#define TB6600 0x007 #define TB6600 0x007
#define TMC2100 0x008 #define TMC2100 0x008
#define TMC2130 0x109 #define TMC2130 2130
#define TMC2130_STANDALONE 0x009 #define TMC2130_STANDALONE 0x009
#define TMC2208 0x10A #define TMC2208 2208
#define TMC2208_STANDALONE 0x00A #define TMC2208_STANDALONE 0x00A
#define TMC26X 0x10B #define TMC26X 0x10B
#define TMC26X_STANDALONE 0x00B #define TMC26X_STANDALONE 0x00B
@ -45,7 +45,7 @@
#define AXIS_DRIVER_TYPE_X(T) _AXIS_DRIVER_TYPE(X,T) #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_Y(T) _AXIS_DRIVER_TYPE(Y,T)
#define AXIS_DRIVER_TYPE_Z(T) _AXIS_DRIVER_TYPE(Z,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_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_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)) #define AXIS_DRIVER_TYPE_Z3(T) (ENABLED(Z_TRIPLE_STEPPER_DRIVERS) && _AXIS_DRIVER_TYPE(Z3,T))

View file

@ -285,6 +285,10 @@
#define MSG_B "Y" #define MSG_B "Y"
#define MSG_C "Z" #define MSG_C "Z"
#endif #endif
#define MSG_X2 "X2"
#define MSG_Y2 "Y2"
#define MSG_Z2 "Z2"
#define MSG_Z3 "Z3"
#define MSG_H1 "1" #define MSG_H1 "1"
#define MSG_H2 "2" #define MSG_H2 "2"
#define MSG_H3 "3" #define MSG_H3 "3"
@ -297,6 +301,7 @@
#define MSG_N4 " 4" #define MSG_N4 " 4"
#define MSG_N5 " 5" #define MSG_N5 " 5"
#define MSG_N6 " 6" #define MSG_N6 " 6"
#define MSG_E0 "E0"
#define MSG_E1 "E1" #define MSG_E1 "E1"
#define MSG_E2 "E2" #define MSG_E2 "E2"
#define MSG_E3 "E3" #define MSG_E3 "E3"

View file

@ -36,8 +36,6 @@
#include "../module/planner.h" #include "../module/planner.h"
#endif #endif
bool report_tmc_status = false;
/** /**
* Check for over temperature or short to ground error flags. * Check for over temperature or short to ground error flags.
* Report and log warning of overtemperature condition. * 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. * and so we don't repeatedly report warning before the condition is cleared.
*/ */
#if ENABLED(MONITOR_DRIVER_STATUS) #if ENABLED(MONITOR_DRIVER_STATUS)
static bool report_tmc_status = false;
struct TMC_driver_data { struct TMC_driver_data {
uint32_t drv_status; uint32_t drv_status;
bool is_otpw; bool is_otpw;
@ -95,13 +95,13 @@ bool report_tmc_status = false;
#endif #endif
template<typename TMC> template<typename TMC>
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); TMC_driver_data data = get_driver_data(st);
#if ENABLED(STOP_ON_ERROR) #if ENABLED(STOP_ON_ERROR)
if (data.is_error) { if (data.is_error) {
SERIAL_EOL(); SERIAL_EOL();
_tmc_say_axis(axis); st.printLabel();
SERIAL_ECHOLNPGM(" driver error detected:"); SERIAL_ECHOLNPGM(" driver error detected:");
if (data.is_ot) SERIAL_ECHOLNPGM("overtemperature"); if (data.is_ot) SERIAL_ECHOLNPGM("overtemperature");
if (st.s2ga()) SERIAL_ECHOLNPGM("short to ground (coil A)"); if (st.s2ga()) SERIAL_ECHOLNPGM("short to ground (coil A)");
@ -114,7 +114,7 @@ bool report_tmc_status = false;
#endif #endif
// Report if a warning was triggered // Report if a warning was triggered
if (data.is_otpw && otpw_cnt == 0) { if (data.is_otpw && st.otpw_count == 0) {
char timestamp[10]; char timestamp[10];
duration_t elapsed = print_job_timer.duration(); duration_t elapsed = print_job_timer.duration();
const bool has_days = (elapsed.value > 60*60*24L); const bool has_days = (elapsed.value > 60*60*24L);
@ -122,38 +122,38 @@ bool report_tmc_status = false;
SERIAL_EOL(); SERIAL_EOL();
SERIAL_ECHO(timestamp); SERIAL_ECHO(timestamp);
SERIAL_ECHOPGM(": "); SERIAL_ECHOPGM(": ");
_tmc_say_axis(axis); st.printLabel();
SERIAL_ECHOPGM(" driver overtemperature warning! ("); SERIAL_ECHOPGM(" driver overtemperature warning! (");
SERIAL_ECHO(st.getCurrent()); SERIAL_ECHO(st.getMilliamps());
SERIAL_ECHOLNPGM("mA)"); SERIAL_ECHOLNPGM("mA)");
} }
#if CURRENT_STEP_DOWN > 0 #if CURRENT_STEP_DOWN > 0
// Decrease current if is_otpw is true and driver is enabled and there's been more than 4 warnings // 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) { if (data.is_otpw && st.isEnabled() && st.otpw_count > 4) {
st.setCurrent(st.getCurrent() - (CURRENT_STEP_DOWN), R_SENSE, HOLD_MULTIPLIER); st.rms_current(st.getMilliamps() - (CURRENT_STEP_DOWN));
#if ENABLED(REPORT_CURRENT_CHANGE) #if ENABLED(REPORT_CURRENT_CHANGE)
_tmc_say_axis(axis); st.printLabel();
SERIAL_ECHOLNPAIR(" current decreased to ", st.getCurrent()); SERIAL_ECHOLNPAIR(" current decreased to ", st.getMilliamps());
#endif #endif
} }
#endif #endif
if (data.is_otpw) { if (data.is_otpw) {
otpw_cnt++; st.otpw_count++;
st.flag_otpw = true; 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) { if (report_tmc_status) {
const uint32_t pwm_scale = get_pwm_scale(st); const uint32_t pwm_scale = get_pwm_scale(st);
_tmc_say_axis(axis); st.printLabel();
SERIAL_ECHOPAIR(":", pwm_scale); SERIAL_ECHOPAIR(":", pwm_scale);
SERIAL_ECHOPGM(" |0b"); SERIAL_PRINT(get_status_response(st), BIN); SERIAL_ECHOPGM(" |0b"); SERIAL_PRINT(get_status_response(st), BIN);
SERIAL_ECHOPGM("| "); SERIAL_ECHOPGM("| ");
if (data.is_error) SERIAL_CHAR('E'); if (data.is_error) SERIAL_CHAR('E');
else if (data.is_ot) SERIAL_CHAR('O'); else if (data.is_ot) SERIAL_CHAR('O');
else if (data.is_otpw) SERIAL_CHAR('W'); 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'); else if (st.flag_otpw) SERIAL_CHAR('F');
SERIAL_CHAR('\t'); SERIAL_CHAR('\t');
} }
@ -166,56 +166,43 @@ bool report_tmc_status = false;
if (ELAPSED(millis(), next_cOT)) { if (ELAPSED(millis(), next_cOT)) {
next_cOT = millis() + 500; next_cOT = millis() + 500;
#if HAS_HW_COMMS(X) #if HAS_HW_COMMS(X)
static uint8_t x_otpw_cnt = 0; monitor_tmc_driver(stepperX);
monitor_tmc_driver(stepperX, TMC_X, x_otpw_cnt);
#endif #endif
#if HAS_HW_COMMS(Y) #if HAS_HW_COMMS(Y)
static uint8_t y_otpw_cnt = 0; monitor_tmc_driver(stepperY);
monitor_tmc_driver(stepperY, TMC_Y, y_otpw_cnt);
#endif #endif
#if HAS_HW_COMMS(Z) #if HAS_HW_COMMS(Z)
static uint8_t z_otpw_cnt = 0; monitor_tmc_driver(stepperZ);
monitor_tmc_driver(stepperZ, TMC_Z, z_otpw_cnt);
#endif #endif
#if HAS_HW_COMMS(X2) #if HAS_HW_COMMS(X2)
static uint8_t x2_otpw_cnt = 0; monitor_tmc_driver(stepperX2);
monitor_tmc_driver(stepperX2, TMC_X, x2_otpw_cnt);
#endif #endif
#if HAS_HW_COMMS(Y2) #if HAS_HW_COMMS(Y2)
static uint8_t y2_otpw_cnt = 0; monitor_tmc_driver(stepperY2);
monitor_tmc_driver(stepperY2, TMC_Y, y2_otpw_cnt);
#endif #endif
#if HAS_HW_COMMS(Z2) #if HAS_HW_COMMS(Z2)
static uint8_t z2_otpw_cnt = 0; monitor_tmc_driver(stepperZ2);
monitor_tmc_driver(stepperZ2, TMC_Z, z2_otpw_cnt);
#endif #endif
#if HAS_HW_COMMS(Z3) #if HAS_HW_COMMS(Z3)
static uint8_t z3_otpw_cnt = 0; monitor_tmc_driver(stepperZ3);
monitor_tmc_driver(stepperZ3, TMC_Z, z3_otpw_cnt);
#endif #endif
#if HAS_HW_COMMS(E0) #if HAS_HW_COMMS(E0)
static uint8_t e0_otpw_cnt = 0; monitor_tmc_driver(stepperE0);
monitor_tmc_driver(stepperE0, TMC_E0, e0_otpw_cnt);
#endif #endif
#if HAS_HW_COMMS(E1) #if HAS_HW_COMMS(E1)
static uint8_t e1_otpw_cnt = 0; monitor_tmc_driver(stepperE1);
monitor_tmc_driver(stepperE1, TMC_E1, e1_otpw_cnt);
#endif #endif
#if HAS_HW_COMMS(E2) #if HAS_HW_COMMS(E2)
static uint8_t e2_otpw_cnt = 0; monitor_tmc_driver(stepperE2);
monitor_tmc_driver(stepperE2, TMC_E2, e2_otpw_cnt);
#endif #endif
#if HAS_HW_COMMS(E3) #if HAS_HW_COMMS(E3)
static uint8_t e3_otpw_cnt = 0; monitor_tmc_driver(stepperE3);
monitor_tmc_driver(stepperE3, TMC_E3, e3_otpw_cnt);
#endif #endif
#if HAS_HW_COMMS(E4) #if HAS_HW_COMMS(E4)
static uint8_t e4_otpw_cnt = 0; monitor_tmc_driver(stepperE4);
monitor_tmc_driver(stepperE4, TMC_E4, e4_otpw_cnt);
#endif #endif
#if HAS_HW_COMMS(E5) #if HAS_HW_COMMS(E5)
static uint8_t e5_otpw_cnt = 0; monitor_tmc_driver(stepperE5);
monitor_tmc_driver(stepperE5, TMC_E5, e5_otpw_cnt);
#endif #endif
if (report_tmc_status) SERIAL_EOL(); if (report_tmc_status) SERIAL_EOL();
@ -224,100 +211,6 @@ bool report_tmc_status = false;
#endif // MONITOR_DRIVER_STATUS #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) #if ENABLED(TMC_DEBUG)
enum TMC_debug_enum : char { enum TMC_debug_enum : char {
@ -366,9 +259,7 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) {
TMC_S2VSB, TMC_S2VSB,
TMC_S2VSA TMC_S2VSA
}; };
static void drv_status_print_hex(const TMC_AxisEnum axis, const uint32_t drv_status) { static void drv_status_print_hex(const uint32_t drv_status) {
_tmc_say_axis(axis);
SERIAL_ECHOPGM(" = 0x");
for (int B = 24; B >= 8; B -= 8){ for (int B = 24; B >= 8; B -= 8){
SERIAL_PRINT((drv_status >> (B + 4)) & 0xF, HEX); SERIAL_PRINT((drv_status >> (B + 4)) & 0xF, HEX);
SERIAL_PRINT((drv_status >> B) & 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(); SERIAL_EOL();
} }
template<class TMC>
static void print_vsense(TMC &st) { serialprintPGM(st.vsense() ? PSTR("1=.18") : PSTR("0=.325")); }
#if HAS_DRIVER(TMC2130) #if HAS_DRIVER(TMC2130)
static void tmc_status(TMC2130Stepper &st, const TMC_debug_enum i) { static void tmc_status(TMC2130Stepper &st, const TMC_debug_enum i) {
switch (i) { switch (i) {
case TMC_PWM_SCALE: SERIAL_PRINT(st.PWM_SCALE(), DEC); break; 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_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; 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) { switch (i) {
case TMC_STALLGUARD: if (st.stallguard()) SERIAL_CHAR('X'); break; case TMC_STALLGUARD: if (st.stallguard()) SERIAL_CHAR('X'); break;
case TMC_SG_RESULT: SERIAL_PRINT(st.sg_result(), DEC); 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) #if HAS_DRIVER(TMC2208)
static void tmc_status(TMC2208Stepper &st, const TMC_debug_enum i) { static void tmc_status(TMC2208Stepper &st, const TMC_debug_enum i) {
switch (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_PWM_SCALE: SERIAL_PRINT(st.pwm_scale_sum(), DEC); break;
case TMC_STEALTHCHOP: serialprintPGM(st.stealth() ? PSTR("true") : PSTR("false")); break; case TMC_STEALTHCHOP: serialprintPGM(st.stealth() ? PSTR("true") : PSTR("false")); break;
case TMC_S2VSA: if (st.s2vsa()) SERIAL_CHAR('X'); 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; 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) { switch (i) {
case TMC_T157: if (st.t157()) SERIAL_CHAR('X'); break; case TMC_T157: if (st.t157()) SERIAL_CHAR('X'); break;
case TMC_T150: if (st.t150()) 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 #endif
template <typename TMC> template <typename TMC>
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'); SERIAL_ECHO('\t');
switch (i) { 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_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_RMS_CURRENT: SERIAL_PROTOCOL(st.rms_current()); break;
case TMC_MAX_CURRENT: SERIAL_PRINT((float)st.rms_current() * 1.41, 0); break; case TMC_MAX_CURRENT: SERIAL_PRINT((float)st.rms_current() * 1.41, 0); break;
case TMC_IRUN: 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_PRINT(st.cs_actual(), DEC);
SERIAL_ECHOPGM("/31"); SERIAL_ECHOPGM("/31");
break; break;
case TMC_VSENSE: print_vsense(st); break;
case TMC_VSENSE: serialprintPGM(st.vsense() ? PSTR("1=.18") : PSTR("0=.325")); break;
case TMC_MICROSTEPS: SERIAL_ECHO(st.microsteps()); break; case TMC_MICROSTEPS: SERIAL_ECHO(st.microsteps()); break;
case TMC_TSTEP: SERIAL_ECHO(st.TSTEP()); break;
case TMC_TPWMTHRS: { case TMC_TPWMTHRS: {
uint32_t tpwmthrs_val = st.TPWMTHRS(); uint32_t tpwmthrs_val = st.TPWMTHRS();
SERIAL_ECHO(tpwmthrs_val); SERIAL_ECHO(tpwmthrs_val);
@ -470,10 +361,10 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) {
} }
template <typename TMC> template <typename TMC>
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'); SERIAL_CHAR('\t');
switch (i) { 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_STST: if (st.stst()) SERIAL_CHAR('X'); break;
case TMC_OLB: if (st.olb()) SERIAL_CHAR('X'); break; case TMC_OLB: if (st.olb()) SERIAL_CHAR('X'); break;
case TMC_OLA: if (st.ola()) 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_DRV_OTPW: if (st.otpw()) SERIAL_CHAR('X'); break;
case TMC_OT: if (st.ot()) 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_CS_ACTUAL: SERIAL_PRINT(st.cs_actual(), DEC); break;
case TMC_DRV_STATUS_HEX:drv_status_print_hex(axis, st.DRV_STATUS()); break; case TMC_DRV_STATUS_HEX:
default: tmc_parse_drv_status(st, i); break; 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) { static void tmc_debug_loop(const TMC_debug_enum i) {
#if AXIS_IS_TMC(X) #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 #endif
#if AXIS_IS_TMC(X2) #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 #endif
#if AXIS_IS_TMC(Y) #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 #endif
#if AXIS_IS_TMC(Y2) #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 #endif
#if AXIS_IS_TMC(Z) #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 #endif
#if AXIS_IS_TMC(Z2) #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 #endif
#if AXIS_IS_TMC(Z3) #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 #endif
#if AXIS_IS_TMC(E0) #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 #endif
#if AXIS_IS_TMC(E1) #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) #if ENABLED(DISTINCT_E_FACTORS)
+ 1 + 1
#endif #endif
]); ]);
#endif #endif
#if AXIS_IS_TMC(E2) #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) #if ENABLED(DISTINCT_E_FACTORS)
+ 2 + 2
#endif #endif
]); ]);
#endif #endif
#if AXIS_IS_TMC(E3) #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) #if ENABLED(DISTINCT_E_FACTORS)
+ 3 + 3
#endif #endif
]); ]);
#endif #endif
#if AXIS_IS_TMC(E4) #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) #if ENABLED(DISTINCT_E_FACTORS)
+ 4 + 4
#endif #endif
]); ]);
#endif #endif
#if AXIS_IS_TMC(E5) #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) #if ENABLED(DISTINCT_E_FACTORS)
+ 5 + 5
#endif #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) { static void drv_status_loop(const TMC_drv_status_enum i) {
#if AXIS_IS_TMC(X) #if AXIS_IS_TMC(X)
tmc_parse_drv_status(stepperX, TMC_X, i); tmc_parse_drv_status(stepperX, i);
#endif #endif
#if AXIS_IS_TMC(X2) #if AXIS_IS_TMC(X2)
tmc_parse_drv_status(stepperX2, TMC_X2, i); tmc_parse_drv_status(stepperX2, i);
#endif #endif
#if AXIS_IS_TMC(Y) #if AXIS_IS_TMC(Y)
tmc_parse_drv_status(stepperY, TMC_Y, i); tmc_parse_drv_status(stepperY, i);
#endif #endif
#if AXIS_IS_TMC(Y2) #if AXIS_IS_TMC(Y2)
tmc_parse_drv_status(stepperY2, TMC_Y2, i); tmc_parse_drv_status(stepperY2, i);
#endif #endif
#if AXIS_IS_TMC(Z) #if AXIS_IS_TMC(Z)
tmc_parse_drv_status(stepperZ, TMC_Z, i); tmc_parse_drv_status(stepperZ, i);
#endif #endif
#if AXIS_IS_TMC(Z2) #if AXIS_IS_TMC(Z2)
tmc_parse_drv_status(stepperZ2, TMC_Z2, i); tmc_parse_drv_status(stepperZ2, i);
#endif #endif
#if AXIS_IS_TMC(Z3) #if AXIS_IS_TMC(Z3)
tmc_parse_drv_status(stepperZ3, TMC_Z3, i); tmc_parse_drv_status(stepperZ3, i);
#endif #endif
#if AXIS_IS_TMC(E0) #if AXIS_IS_TMC(E0)
tmc_parse_drv_status(stepperE0, TMC_E0, i); tmc_parse_drv_status(stepperE0, i);
#endif #endif
#if AXIS_IS_TMC(E1) #if AXIS_IS_TMC(E1)
tmc_parse_drv_status(stepperE1, TMC_E1, i); tmc_parse_drv_status(stepperE1, i);
#endif #endif
#if AXIS_IS_TMC(E2) #if AXIS_IS_TMC(E2)
tmc_parse_drv_status(stepperE2, TMC_E2, i); tmc_parse_drv_status(stepperE2, i);
#endif #endif
#if AXIS_IS_TMC(E3) #if AXIS_IS_TMC(E3)
tmc_parse_drv_status(stepperE3, TMC_E3, i); tmc_parse_drv_status(stepperE3, i);
#endif #endif
#if AXIS_IS_TMC(E4) #if AXIS_IS_TMC(E4)
tmc_parse_drv_status(stepperE4, TMC_E4, i); tmc_parse_drv_status(stepperE4, i);
#endif #endif
#if AXIS_IS_TMC(E5) #if AXIS_IS_TMC(E5)
tmc_parse_drv_status(stepperE5, TMC_E5, i); tmc_parse_drv_status(stepperE5, i);
#endif #endif
SERIAL_EOL(); 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("Run current", TMC_IRUN);
TMC_REPORT("Hold current", TMC_IHOLD); TMC_REPORT("Hold current", TMC_IHOLD);
TMC_REPORT("CS actual\t", TMC_CS_ACTUAL); 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("vsense\t", TMC_VSENSE);
TMC_REPORT("stealthChop", TMC_STEALTHCHOP); TMC_REPORT("stealthChop", TMC_STEALTHCHOP);
TMC_REPORT("msteps\t", TMC_MICROSTEPS); 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("s2vsa\t", TMC_S2VSA);
DRV_REPORT("s2vsb\t", TMC_S2VSB); DRV_REPORT("s2vsb\t", TMC_S2VSB);
#endif #endif
DRV_REPORT("Driver registers:", TMC_DRV_STATUS_HEX); DRV_REPORT("Driver registers:\n",TMC_DRV_STATUS_HEX);
SERIAL_EOL(); SERIAL_EOL();
} }
@ -666,9 +561,9 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) {
#if USE_SENSORLESS #if USE_SENSORLESS
void tmc_stallguard(TMC2130Stepper &st, const bool enable/*=true*/) { 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) #if ENABLED(STEALTHCHOP)
st.stealthChop(!enable); st.en_pwm_mode(!enable);
#endif #endif
st.diag1_stall(enable ? 1 : 0); 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 #endif // USE_SENSORLESS
#if HAS_DRIVER(TMC2130) #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) #define SET_CS_PIN(st) OUT_WRITE(st##_CS_PIN, HIGH)
void tmc_init_cs_pins() { void tmc_init_cs_pins() {
#if AXIS_DRIVER_TYPE(X, TMC2130) #if IS_TMC_SPI(X)
SET_CS_PIN(X); SET_CS_PIN(X);
#endif #endif
#if AXIS_DRIVER_TYPE(Y, TMC2130) #if IS_TMC_SPI(Y)
SET_CS_PIN(Y); SET_CS_PIN(Y);
#endif #endif
#if AXIS_DRIVER_TYPE(Z, TMC2130) #if IS_TMC_SPI(Z)
SET_CS_PIN(Z); SET_CS_PIN(Z);
#endif #endif
#if AXIS_DRIVER_TYPE(X2, TMC2130) #if IS_TMC_SPI(X2)
SET_CS_PIN(X2); SET_CS_PIN(X2);
#endif #endif
#if AXIS_DRIVER_TYPE(Y2, TMC2130) #if IS_TMC_SPI(Y2)
SET_CS_PIN(Y2); SET_CS_PIN(Y2);
#endif #endif
#if AXIS_DRIVER_TYPE(Z2, TMC2130) #if IS_TMC_SPI(Z2)
SET_CS_PIN(Z2); SET_CS_PIN(Z2);
#endif #endif
#if AXIS_DRIVER_TYPE(Z3, TMC2130) #if IS_TMC_SPI(Z3)
SET_CS_PIN(Z3); SET_CS_PIN(Z3);
#endif #endif
#if AXIS_DRIVER_TYPE(E0, TMC2130) #if IS_TMC_SPI(E0)
SET_CS_PIN(E0); SET_CS_PIN(E0);
#endif #endif
#if AXIS_DRIVER_TYPE(E1, TMC2130) #if IS_TMC_SPI(E1)
SET_CS_PIN(E1); SET_CS_PIN(E1);
#endif #endif
#if AXIS_DRIVER_TYPE(E2, TMC2130) #if IS_TMC_SPI(E2)
SET_CS_PIN(E2); SET_CS_PIN(E2);
#endif #endif
#if AXIS_DRIVER_TYPE(E3, TMC2130) #if IS_TMC_SPI(E3)
SET_CS_PIN(E3); SET_CS_PIN(E3);
#endif #endif
#if AXIS_DRIVER_TYPE(E4, TMC2130) #if IS_TMC_SPI(E4)
SET_CS_PIN(E4); SET_CS_PIN(E4);
#endif #endif
#if AXIS_DRIVER_TYPE(E5, TMC2130) #if IS_TMC_SPI(E5)
SET_CS_PIN(E5); SET_CS_PIN(E5);
#endif #endif
} }

View file

@ -23,91 +23,132 @@
#ifndef _TMC_UTIL_H_ #ifndef _TMC_UTIL_H_
#define _TMC_UTIL_H_ #define _TMC_UTIL_H_
#include "../inc/MarlinConfigPre.h" #include "../inc/MarlinConfig.h"
#if HAS_TRINAMIC
#if HAS_DRIVER(TMC2130) #include <TMCStepper.h>
#include <TMC2130Stepper.h>
#endif #endif
#if HAS_DRIVER(TMC2208) #define TMC_X_LABEL 'X', '0'
#include <TMC2208Stepper.h> #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<char AXIS_LETTER, char DRIVER_ID>
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 #endif
extern bool report_tmc_status; uint16_t getMilliamps() { return val_mA; }
enum TMC_AxisEnum : char { void printLabel() {
TMC_X, TMC_Y, TMC_Z SERIAL_CHAR(AXIS_LETTER);
#if ENABLED(DUAL_X_CARRIAGE) || ENABLED(X_DUAL_STEPPER_DRIVERS) if (DRIVER_ID > '0') SERIAL_CHAR(DRIVER_ID);
, TMC_X2 }
#endif };
#if ENABLED(Y_DUAL_STEPPER_DRIVERS)
, TMC_Y2 template<class TMC, char AXIS_LETTER, char DRIVER_ID>
#endif class TMCMarlin : public TMC, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
#if ENABLED(Z_DUAL_STEPPER_DRIVERS) public:
, TMC_Z2 TMCMarlin(uint16_t cs_pin, float RS) :
#endif TMC(cs_pin, RS)
#if ENABLED(Z_TRIPLE_STEPPER_DRIVERS) {}
, TMC_Z3 TMCMarlin(uint16_t CS, float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK) :
#endif TMC(CS, RS, pinMOSI, pinMISO, pinSCK)
#if E_STEPPERS {}
, TMC_E0 uint16_t rms_current() { return TMC::rms_current(); }
#if E_STEPPERS > 1 void rms_current(uint16_t mA) {
, TMC_E1 this->val_mA = mA;
#if E_STEPPERS > 2 TMC::rms_current(mA);
, TMC_E2 }
#if E_STEPPERS > 3 void rms_current(uint16_t mA, float mult) {
, TMC_E3 this->val_mA = mA;
#if E_STEPPERS > 4 TMC::rms_current(mA, mult);
, TMC_E4 }
#if E_STEPPERS > 5 };
, TMC_E5 template<char AXIS_LETTER, char DRIVER_ID>
#endif // E_STEPPERS > 5 class TMCMarlin<TMC2208Stepper, AXIS_LETTER, DRIVER_ID> : public TMC2208Stepper, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
#endif // E_STEPPERS > 4 public:
#endif // E_STEPPERS > 3 TMCMarlin(Stream * SerialPort, float RS, bool has_rx=true) :
#endif // E_STEPPERS > 2 TMC2208Stepper(SerialPort, RS, has_rx=true)
#endif // E_STEPPERS > 1 {}
#endif // E_STEPPERS 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) { constexpr uint32_t _tmc_thrs(const uint16_t msteps, const int32_t thrs, const uint32_t spmm) {
return 12650000UL * msteps / (256 * thrs * 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<typename TMC> template<typename TMC>
void tmc_get_current(TMC &st, const TMC_AxisEnum axis) { void tmc_get_current(TMC &st) {
_tmc_say_current(axis, st.getCurrent()); st.printLabel();
SERIAL_ECHOLNPAIR(" driver current: ", st.getMilliamps());
} }
template<typename TMC> template<typename TMC>
void tmc_set_current(TMC &st, const int mA) { void tmc_set_current(TMC &st, const int mA) {
st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER); st.rms_current(mA);
}
#if ENABLED(MONITOR_DRIVER_STATUS)
template<typename TMC>
void tmc_report_otpw(TMC &st) {
st.printLabel();
SERIAL_ECHOPGM(" temperature prewarn triggered: ");
serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false"));
SERIAL_EOL();
} }
template<typename TMC> template<typename TMC>
void tmc_report_otpw(TMC &st, const TMC_AxisEnum axis) { void tmc_clear_otpw(TMC &st) {
_tmc_say_otpw(axis, st.getOTPW());
}
template<typename TMC>
void tmc_clear_otpw(TMC &st, const TMC_AxisEnum axis) {
st.clear_otpw(); st.clear_otpw();
_tmc_say_otpw_cleared(axis); st.printLabel();
SERIAL_ECHOLNPGM(" prewarn flag cleared");
} }
#endif
template<typename TMC> template<typename TMC>
void tmc_get_pwmthrs(TMC &st, const TMC_AxisEnum axis, const uint16_t spmm) { void tmc_get_pwmthrs(TMC &st, const uint16_t spmm) {
_tmc_say_pwmthrs(axis, _tmc_thrs(st.microsteps(), st.TPWMTHRS(), spmm)); st.printLabel();
SERIAL_ECHOLNPAIR(" stealthChop max speed: ", _tmc_thrs(st.microsteps(), st.TPWMTHRS(), spmm));
} }
template<typename TMC> template<typename TMC>
void tmc_set_pwmthrs(TMC &st, const int32_t thrs, const uint32_t spmm) { void tmc_set_pwmthrs(TMC &st, const int32_t thrs, const uint32_t spmm) {
st.TPWMTHRS(_tmc_thrs(st.microsteps(), thrs, spmm)); st.TPWMTHRS(_tmc_thrs(st.microsteps(), thrs, spmm));
} }
template<typename TMC> template<typename TMC>
void tmc_get_sgt(TMC &st, const TMC_AxisEnum axis) { void tmc_get_sgt(TMC &st) {
_tmc_say_sgt(axis, st.sgt()); st.printLabel();
SERIAL_ECHOPGM(" homing sensitivity: ");
SERIAL_PRINTLN(st.sgt(), DEC);
} }
template<typename TMC> template<typename TMC>
void tmc_set_sgt(TMC &st, const int8_t sgt_val) { void tmc_set_sgt(TMC &st, const int8_t sgt_val) {

View file

@ -33,7 +33,7 @@
* Report driver currents when no axis specified * Report driver currents when no axis specified
*/ */
void GcodeSuite::M906() { 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) #define TMC_SET_CURRENT(Q) tmc_set_current(stepper##Q, value)
bool report = true; bool report = true;

View file

@ -33,49 +33,50 @@
#define M91x_USE(ST) (AXIS_DRIVER_TYPE(ST, TMC2130) || (AXIS_DRIVER_TYPE(ST, TMC2208) && PIN_EXISTS(ST##_SERIAL_RX))) #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)) #define M91x_USE_E(N) (E_STEPPERS > N && M91x_USE(E##N))
#if ENABLED(MONITOR_DRIVER_STATUS)
/** /**
* M911: Report TMC stepper driver overtemperature pre-warn flag * M911: Report TMC stepper driver overtemperature pre-warn flag
* This flag is held by the library, persisting until cleared by M912 * This flag is held by the library, persisting until cleared by M912
*/ */
void GcodeSuite::M911() { void GcodeSuite::M911() {
#if M91x_USE(X) #if M91x_USE(X)
tmc_report_otpw(stepperX, TMC_X); tmc_report_otpw(stepperX);
#endif #endif
#if M91x_USE(X2) #if M91x_USE(X2)
tmc_report_otpw(stepperX2, TMC_X2); tmc_report_otpw(stepperX2);
#endif #endif
#if M91x_USE(Y) #if M91x_USE(Y)
tmc_report_otpw(stepperY, TMC_Y); tmc_report_otpw(stepperY);
#endif #endif
#if M91x_USE(Y2) #if M91x_USE(Y2)
tmc_report_otpw(stepperY2, TMC_Y2); tmc_report_otpw(stepperY2);
#endif #endif
#if M91x_USE(Z) #if M91x_USE(Z)
tmc_report_otpw(stepperZ, TMC_Z); tmc_report_otpw(stepperZ);
#endif #endif
#if M91x_USE(Z2) #if M91x_USE(Z2)
tmc_report_otpw(stepperZ2, TMC_Z2); tmc_report_otpw(stepperZ2);
#endif #endif
#if M91x_USE(Z3) #if M91x_USE(Z3)
tmc_report_otpw(stepperZ3, TMC_Z3); tmc_report_otpw(stepperZ3);
#endif #endif
#if M91x_USE_E(0) #if M91x_USE_E(0)
tmc_report_otpw(stepperE0, TMC_E0); tmc_report_otpw(stepperE0);
#endif #endif
#if M91x_USE_E(1) #if M91x_USE_E(1)
tmc_report_otpw(stepperE1, TMC_E1); tmc_report_otpw(stepperE1);
#endif #endif
#if M91x_USE_E(2) #if M91x_USE_E(2)
tmc_report_otpw(stepperE2, TMC_E2); tmc_report_otpw(stepperE2);
#endif #endif
#if M91x_USE_E(3) #if M91x_USE_E(3)
tmc_report_otpw(stepperE3, TMC_E3); tmc_report_otpw(stepperE3);
#endif #endif
#if M91x_USE_E(4) #if M91x_USE_E(4)
tmc_report_otpw(stepperE4, TMC_E4); tmc_report_otpw(stepperE4);
#endif #endif
#if M91x_USE_E(5) #if M91x_USE_E(5)
tmc_report_otpw(stepperE5, TMC_E5); tmc_report_otpw(stepperE5);
#endif #endif
} }
@ -101,67 +102,68 @@ void GcodeSuite::M912() {
#if M91x_USE(X) || M91x_USE(X2) #if M91x_USE(X) || M91x_USE(X2)
const int8_t xval = int8_t(parser.byteval(axis_codes[X_AXIS], 0xFF)); const int8_t xval = int8_t(parser.byteval(axis_codes[X_AXIS], 0xFF));
#if M91x_USE(X) #if M91x_USE(X)
if (hasNone || xval == 1 || (hasX && xval < 0)) tmc_clear_otpw(stepperX, TMC_X); if (hasNone || xval == 1 || (hasX && xval < 0)) tmc_clear_otpw(stepperX);
#endif #endif
#if M91x_USE(X2) #if M91x_USE(X2)
if (hasNone || xval == 2 || (hasX && xval < 0)) tmc_clear_otpw(stepperX2, TMC_X2); if (hasNone || xval == 2 || (hasX && xval < 0)) tmc_clear_otpw(stepperX2);
#endif #endif
#endif #endif
#if M91x_USE(Y) || M91x_USE(Y2) #if M91x_USE(Y) || M91x_USE(Y2)
const int8_t yval = int8_t(parser.byteval(axis_codes[Y_AXIS], 0xFF)); const int8_t yval = int8_t(parser.byteval(axis_codes[Y_AXIS], 0xFF));
#if M91x_USE(Y) #if M91x_USE(Y)
if (hasNone || yval == 1 || (hasY && yval < 0)) tmc_clear_otpw(stepperY, TMC_Y); if (hasNone || yval == 1 || (hasY && yval < 0)) tmc_clear_otpw(stepperY);
#endif #endif
#if M91x_USE(Y2) #if M91x_USE(Y2)
if (hasNone || yval == 2 || (hasY && yval < 0)) tmc_clear_otpw(stepperY2, TMC_Y2); if (hasNone || yval == 2 || (hasY && yval < 0)) tmc_clear_otpw(stepperY2);
#endif #endif
#endif #endif
#if M91x_USE(Z) || M91x_USE(Z2) || M91x_USE(Z3) #if M91x_USE(Z) || M91x_USE(Z2) || M91x_USE(Z3)
const int8_t zval = int8_t(parser.byteval(axis_codes[Z_AXIS], 0xFF)); const int8_t zval = int8_t(parser.byteval(axis_codes[Z_AXIS], 0xFF));
#if M91x_USE(Z) #if M91x_USE(Z)
if (hasNone || zval == 1 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ, TMC_Z); if (hasNone || zval == 1 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ);
#endif #endif
#if M91x_USE(Z2) #if M91x_USE(Z2)
if (hasNone || zval == 2 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ2, TMC_Z2); if (hasNone || zval == 2 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ2);
#endif #endif
#if M91x_USE(Z3) #if M91x_USE(Z3)
if (hasNone || zval == 3 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ3, TMC_Z3); if (hasNone || zval == 3 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ3);
#endif #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) #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)); const int8_t eval = int8_t(parser.byteval(axis_codes[E_AXIS], 0xFF));
#if M91x_USE_E(0) #if M91x_USE_E(0)
if (hasNone || eval == 0 || (hasE && eval < 0)) tmc_clear_otpw(stepperE0, TMC_E0); if (hasNone || eval == 0 || (hasE && eval < 0)) tmc_clear_otpw(stepperE0);
#endif #endif
#if M91x_USE_E(1) #if M91x_USE_E(1)
if (hasNone || eval == 1 || (hasE && eval < 0)) tmc_clear_otpw(stepperE1, TMC_E1); if (hasNone || eval == 1 || (hasE && eval < 0)) tmc_clear_otpw(stepperE1);
#endif #endif
#if M91x_USE_E(2) #if M91x_USE_E(2)
if (hasNone || eval == 2 || (hasE && eval < 0)) tmc_clear_otpw(stepperE2, TMC_E2); if (hasNone || eval == 2 || (hasE && eval < 0)) tmc_clear_otpw(stepperE2);
#endif #endif
#if M91x_USE_E(3) #if M91x_USE_E(3)
if (hasNone || eval == 3 || (hasE && eval < 0)) tmc_clear_otpw(stepperE3, TMC_E3); if (hasNone || eval == 3 || (hasE && eval < 0)) tmc_clear_otpw(stepperE3);
#endif #endif
#if M91x_USE_E(4) #if M91x_USE_E(4)
if (hasNone || eval == 4 || (hasE && eval < 0)) tmc_clear_otpw(stepperE4, TMC_E4); if (hasNone || eval == 4 || (hasE && eval < 0)) tmc_clear_otpw(stepperE4);
#endif #endif
#if M91x_USE_E(5) #if M91x_USE_E(5)
if (hasNone || eval == 5 || (hasE && eval < 0)) tmc_clear_otpw(stepperE5, TMC_E5); if (hasNone || eval == 5 || (hasE && eval < 0)) tmc_clear_otpw(stepperE5);
#endif #endif
#endif #endif
} }
#endif
/** /**
* M913: Set HYBRID_THRESHOLD speed. * M913: Set HYBRID_THRESHOLD speed.
*/ */
#if ENABLED(HYBRID_THRESHOLD) #if ENABLED(HYBRID_THRESHOLD)
void GcodeSuite::M913() { 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_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) #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; bool report = true;
@ -271,7 +273,7 @@ void GcodeSuite::M912() {
*/ */
#if USE_SENSORLESS #if USE_SENSORLESS
void GcodeSuite::M914() { 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) #define TMC_SET_SGT(Q) tmc_set_sgt(stepper##Q, value)
bool report = true; bool report = true;
@ -362,16 +364,16 @@ void GcodeSuite::M912() {
} }
#if AXIS_IS_TMC(Z) #if AXIS_IS_TMC(Z)
const uint16_t Z_current_1 = stepperZ.getCurrent(); const uint16_t Z_current_1 = stepperZ.getMilliamps();
stepperZ.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER); stepperZ.rms_current(_rms);
#endif #endif
#if AXIS_IS_TMC(Z2) #if AXIS_IS_TMC(Z2)
const uint16_t Z2_current_1 = stepperZ2.getCurrent(); const uint16_t Z2_current_1 = stepperZ2.getMilliamps();
stepperZ2.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER); stepperZ2.rms_current(_rms);
#endif #endif
#if Z3_IS_TRINAMIC #if AXIS_IS_TMC(Z3)
const uint16_t Z3_current_1 = stepperZ3.getCurrent(); const uint16_t Z3_current_1 = stepperZ3.getMilliamps();
stepperZ3.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER); stepperZ3.rms_current(_rms);
#endif #endif
SERIAL_ECHOPAIR("\nCalibration current: Z", _rms); SERIAL_ECHOPAIR("\nCalibration current: Z", _rms);
@ -381,13 +383,13 @@ void GcodeSuite::M912() {
do_blocking_move_to_z(Z_MAX_POS+_z); do_blocking_move_to_z(Z_MAX_POS+_z);
#if AXIS_IS_TMC(Z) #if AXIS_IS_TMC(Z)
stepperZ.setCurrent(Z_current_1, R_SENSE, HOLD_MULTIPLIER); stepperZ.rms_current(Z_current_1);
#endif #endif
#if AXIS_IS_TMC(Z2) #if AXIS_IS_TMC(Z2)
stepperZ2.setCurrent(Z2_current_1, R_SENSE, HOLD_MULTIPLIER); stepperZ2.rms_current(Z2_current_1);
#endif #endif
#if AXIS_IS_TMC(Z3) #if AXIS_IS_TMC(Z3)
stepperZ3.setCurrent(Z3_current_1, R_SENSE, HOLD_MULTIPLIER); stepperZ3.rms_current(Z3_current_1);
#endif #endif
do_blocking_move_to_z(Z_MAX_POS); do_blocking_move_to_z(Z_MAX_POS);

View file

@ -632,8 +632,10 @@ void GcodeSuite::process_parsed_command(
case 122: M122(); break; case 122: M122(); break;
#endif #endif
case 906: M906(); break; // M906: Set motor current in milliamps using axis codes X, Y, Z, E case 906: M906(); break; // M906: Set motor current in milliamps using axis codes X, Y, Z, E
#if ENABLED(MONITOR_DRIVER_STATUS)
case 911: M911(); break; // M911: Report TMC2130 prewarn triggered flags case 911: M911(); break; // M911: Report TMC2130 prewarn triggered flags
case 912: M912(); break; // M912: Clear TMC2130 prewarn triggered flags case 912: M912(); break; // M912: Clear TMC2130 prewarn triggered flags
#endif
#if ENABLED(HYBRID_THRESHOLD) #if ENABLED(HYBRID_THRESHOLD)
case 913: M913(); break; // M913: Set HYBRID_THRESHOLD speed. case 913: M913(); break; // M913: Set HYBRID_THRESHOLD speed.
#endif #endif

View file

@ -775,8 +775,10 @@ private:
static void M122(); static void M122();
#endif #endif
static void M906(); static void M906();
#if ENABLED(MONITOR_DRIVER_STATUS)
static void M911(); static void M911();
static void M912(); static void M912();
#endif
#if ENABLED(HYBRID_THRESHOLD) #if ENABLED(HYBRID_THRESHOLD)
static void M913(); static void M913();
#endif #endif

View file

@ -460,6 +460,9 @@
* NOTE: Driver timing order is longest-to-shortest duration. * NOTE: Driver timing order is longest-to-shortest duration.
* Preserve this ordering when adding new drivers. * 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 #ifndef MINIMUM_STEPPER_DIR_DELAY
#if HAS_DRIVER(TB6560) #if HAS_DRIVER(TB6560)
#define MINIMUM_STEPPER_DIR_DELAY 15000 #define MINIMUM_STEPPER_DIR_DELAY 15000
@ -473,7 +476,7 @@
#define MINIMUM_STEPPER_DIR_DELAY 400 #define MINIMUM_STEPPER_DIR_DELAY 400
#elif HAS_DRIVER(A4988) #elif HAS_DRIVER(A4988)
#define MINIMUM_STEPPER_DIR_DELAY 200 #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 #define MINIMUM_STEPPER_DIR_DELAY 20
#else #else
#define MINIMUM_STEPPER_DIR_DELAY 0 // Expect at least 10µS since one Stepper ISR must transpire #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 #define MINIMUM_STEPPER_PULSE 2
#elif HAS_DRIVER(A4988) || HAS_DRIVER(LV8729) || HAS_DRIVER(A5984) #elif HAS_DRIVER(A4988) || HAS_DRIVER(LV8729) || HAS_DRIVER(A5984)
#define MINIMUM_STEPPER_PULSE 1 #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 #define MINIMUM_STEPPER_PULSE 0
#else #else
#define MINIMUM_STEPPER_PULSE 2 #define MINIMUM_STEPPER_PULSE 2
@ -505,7 +508,7 @@
#define MAXIMUM_STEPPER_RATE 150000 #define MAXIMUM_STEPPER_RATE 150000
#elif HAS_DRIVER(DRV8825) #elif HAS_DRIVER(DRV8825)
#define MAXIMUM_STEPPER_RATE 250000 #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 #define MAXIMUM_STEPPER_RATE 400000
#elif HAS_DRIVER(A4988) #elif HAS_DRIVER(A4988)
#define MAXIMUM_STEPPER_RATE 500000 #define MAXIMUM_STEPPER_RATE 500000

View file

@ -83,6 +83,9 @@
#include "../feature/tmc_util.h" #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)]) #define TMC_GET_PWMTHRS(A,Q) _tmc_thrs(stepper##Q.microsteps(), stepper##Q.TPWMTHRS(), planner.axis_steps_per_mm[_AXIS(A)])
#endif #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) #if ENABLED(FWRETRACT)
#include "../feature/fwretract.h" #include "../feature/fwretract.h"
@ -251,9 +254,9 @@ typedef struct SettingsDataStruct {
// HAS_TRINAMIC // HAS_TRINAMIC
// //
#define TMC_AXES (MAX_EXTRUDERS + 7) #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 tmc_stepper_current_t tmc_stepper_current; // 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 tmc_hybrid_threshold_t tmc_hybrid_threshold; // M913 X Y Z X2 Y2 Z2 Z3 E0 E1 E2 E3 E4 E5
int16_t tmc_sgt[XYZ]; // M914 X Y Z tmc_sgt_t tmc_sgt; // M914 X Y Z
// //
// LIN_ADVANCE // LIN_ADVANCE
@ -300,7 +303,7 @@ uint16_t MarlinSettings::datasize() { return sizeof(SettingsData); }
#endif #endif
void MarlinSettings::postprocess() { 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 // steps per s2 needs to be updated to agree with units per s2
planner.reset_acceleration_rates(); planner.reset_acceleration_rates();
@ -436,7 +439,7 @@ void MarlinSettings::postprocess() {
EEPROM_WRITE(dummy); EEPROM_WRITE(dummy);
#endif #endif
#else #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); EEPROM_WRITE(planner_max_jerk);
#endif #endif
@ -464,11 +467,13 @@ void MarlinSettings::postprocess() {
// Global Leveling // Global Leveling
// //
const float zfh = (
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
const float zfh = planner.z_fade_height; planner.z_fade_height
#else #else
const float zfh = 10.0; 10.0
#endif #endif
);
EEPROM_WRITE(zfh); EEPROM_WRITE(zfh);
// //
@ -478,7 +483,7 @@ void MarlinSettings::postprocess() {
#if ENABLED(MESH_BED_LEVELING) #if ENABLED(MESH_BED_LEVELING)
// Compile time test that sizeof(mbl.z_values) is as expected // Compile time test that sizeof(mbl.z_values) is as expected
static_assert( 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." "MBL Z array is the wrong size."
); );
const uint8_t mesh_num_x = GRID_MAX_POINTS_X, mesh_num_y = GRID_MAX_POINTS_Y; 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) #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
// Compile time test that sizeof(z_values) is as expected // Compile time test that sizeof(z_values) is as expected
static_assert( 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." "Bilinear Z array is the wrong size."
); );
const uint8_t grid_max_x = GRID_MAX_POINTS_X, grid_max_y = GRID_MAX_POINTS_Y; const uint8_t grid_max_x = GRID_MAX_POINTS_X, grid_max_y = GRID_MAX_POINTS_Y;
@ -719,83 +724,58 @@ void MarlinSettings::postprocess() {
#endif #endif
// //
// Save TMC2130 or TMC2208 Configuration, and placeholder values // Save TMC Configuration, and placeholder values
// //
_FIELD_TEST(tmc_stepper_current); _FIELD_TEST(tmc_stepper_current);
uint16_t tmc_stepper_current[TMC_AXES] = { tmc_stepper_current_t tmc_stepper_current = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
#if HAS_TRINAMIC #if HAS_TRINAMIC
#if AXIS_IS_TMC(X) #if AXIS_IS_TMC(X)
stepperX.getCurrent(), tmc_stepper_current.X = stepperX.getMilliamps();
#else
0,
#endif #endif
#if AXIS_IS_TMC(Y) #if AXIS_IS_TMC(Y)
stepperY.getCurrent(), tmc_stepper_current.Y = stepperY.getMilliamps();
#else
0,
#endif #endif
#if AXIS_IS_TMC(Z) #if AXIS_IS_TMC(Z)
stepperZ.getCurrent(), tmc_stepper_current.Z = stepperZ.getMilliamps();
#else
0,
#endif #endif
#if AXIS_IS_TMC(X2) #if AXIS_IS_TMC(X2)
stepperX2.getCurrent(), tmc_stepper_current.X2 = stepperX2.getMilliamps();
#else
0,
#endif #endif
#if AXIS_IS_TMC(Y2) #if AXIS_IS_TMC(Y2)
stepperY2.getCurrent(), tmc_stepper_current.Y2 = stepperY2.getMilliamps();
#else
0,
#endif #endif
#if AXIS_IS_TMC(Z2) #if AXIS_IS_TMC(Z2)
stepperZ2.getCurrent(), tmc_stepper_current.Z2 = stepperZ2.getMilliamps();
#else
0,
#endif #endif
#if AXIS_IS_TMC(Z3) #if AXIS_IS_TMC(Z3)
stepperZ3.getCurrent(), tmc_stepper_current.Z3 = stepperZ3.getMilliamps();
#else
0,
#endif #endif
#if MAX_EXTRUDERS #if MAX_EXTRUDERS
#if AXIS_IS_TMC(E0) #if AXIS_IS_TMC(E0)
stepperE0.getCurrent(), tmc_stepper_current.E0 = stepperE0.getMilliamps();
#else
0,
#endif #endif
#if MAX_EXTRUDERS > 1 #if MAX_EXTRUDERS > 1
#if AXIS_IS_TMC(E1) #if AXIS_IS_TMC(E1)
stepperE1.getCurrent(), tmc_stepper_current.E1 = stepperE1.getMilliamps();
#else
0,
#endif #endif
#if MAX_EXTRUDERS > 2 #if MAX_EXTRUDERS > 2
#if AXIS_IS_TMC(E2) #if AXIS_IS_TMC(E2)
stepperE2.getCurrent(), tmc_stepper_current.E2 = stepperE2.getMilliamps();
#else
0,
#endif #endif
#if MAX_EXTRUDERS > 3 #if MAX_EXTRUDERS > 3
#if AXIS_IS_TMC(E3) #if AXIS_IS_TMC(E3)
stepperE3.getCurrent(), tmc_stepper_current.E3 = stepperE3.getMilliamps();
#else
0,
#endif #endif
#if MAX_EXTRUDERS > 4 #if MAX_EXTRUDERS > 4
#if AXIS_IS_TMC(E4) #if AXIS_IS_TMC(E4)
stepperE4.getCurrent() tmc_stepper_current.E4 = stepperE4.getMilliamps();
#else
0
#endif #endif
#if MAX_EXTRUDERS > 5 #if MAX_EXTRUDERS > 5
#if AXIS_IS_TMC(E5) #if AXIS_IS_TMC(E5)
stepperE5.getCurrent() tmc_stepper_current.E5 = stepperE5.getMilliamps();
#else
0
#endif #endif
#endif // MAX_EXTRUDERS > 5 #endif // MAX_EXTRUDERS > 5
#endif // MAX_EXTRUDERS > 4 #endif // MAX_EXTRUDERS > 4
@ -803,90 +783,61 @@ void MarlinSettings::postprocess() {
#endif // MAX_EXTRUDERS > 2 #endif // MAX_EXTRUDERS > 2
#endif // MAX_EXTRUDERS > 1 #endif // MAX_EXTRUDERS > 1
#endif // MAX_EXTRUDERS #endif // MAX_EXTRUDERS
#else
0
#endif #endif
};
EEPROM_WRITE(tmc_stepper_current); 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); _FIELD_TEST(tmc_hybrid_threshold);
uint32_t tmc_hybrid_threshold[TMC_AXES] = {
#if ENABLED(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) #if AXIS_HAS_STEALTHCHOP(X)
TMC_GET_PWMTHRS(X, X), tmc_hybrid_threshold.X = TMC_GET_PWMTHRS(X, X);
#else
X_HYBRID_THRESHOLD,
#endif #endif
#if AXIS_HAS_STEALTHCHOP(Y) #if AXIS_HAS_STEALTHCHOP(Y)
TMC_GET_PWMTHRS(Y, Y), tmc_hybrid_threshold.Y = TMC_GET_PWMTHRS(Y, Y);
#else
Y_HYBRID_THRESHOLD,
#endif #endif
#if AXIS_HAS_STEALTHCHOP(Z) #if AXIS_HAS_STEALTHCHOP(Z)
TMC_GET_PWMTHRS(Z, Z), tmc_hybrid_threshold.Z = TMC_GET_PWMTHRS(Z, Z);
#else
Z_HYBRID_THRESHOLD,
#endif #endif
#if AXIS_HAS_STEALTHCHOP(X2) #if AXIS_HAS_STEALTHCHOP(X2)
TMC_GET_PWMTHRS(X, X2), tmc_hybrid_threshold.X2 = TMC_GET_PWMTHRS(X, X2);
#else
X2_HYBRID_THRESHOLD,
#endif #endif
#if AXIS_HAS_STEALTHCHOP(Y2) #if AXIS_HAS_STEALTHCHOP(Y2)
TMC_GET_PWMTHRS(Y, Y2), tmc_hybrid_threshold.Y2 = TMC_GET_PWMTHRS(Y, Y2);
#else
Y2_HYBRID_THRESHOLD,
#endif #endif
#if AXIS_HAS_STEALTHCHOP(Z2) #if AXIS_HAS_STEALTHCHOP(Z2)
TMC_GET_PWMTHRS(Z, Z2), tmc_hybrid_threshold.Z2 = TMC_GET_PWMTHRS(Z, Z2);
#else
Z2_HYBRID_THRESHOLD,
#endif #endif
#if AXIS_HAS_STEALTHCHOP(Z3) #if AXIS_HAS_STEALTHCHOP(Z3)
TMC_GET_PWMTHRS(Z, Z3), tmc_hybrid_threshold.Z3 = TMC_GET_PWMTHRS(Z, Z3);
#else
Z3_HYBRID_THRESHOLD,
#endif #endif
#if MAX_EXTRUDERS #if MAX_EXTRUDERS
#if AXIS_HAS_STEALTHCHOP(E0) #if AXIS_HAS_STEALTHCHOP(E0)
TMC_GET_PWMTHRS(E, E0), tmc_hybrid_threshold.E0 = TMC_GET_PWMTHRS(E, E0);
#else
E0_HYBRID_THRESHOLD,
#endif #endif
#if MAX_EXTRUDERS > 1 #if MAX_EXTRUDERS > 1
#if AXIS_HAS_STEALTHCHOP(E1) #if AXIS_HAS_STEALTHCHOP(E1)
TMC_GET_PWMTHRS(E, E1), tmc_hybrid_threshold.E1 = TMC_GET_PWMTHRS(E, E1);
#else
E1_HYBRID_THRESHOLD,
#endif #endif
#if MAX_EXTRUDERS > 2 #if MAX_EXTRUDERS > 2
#if AXIS_HAS_STEALTHCHOP(E2) #if AXIS_HAS_STEALTHCHOP(E2)
TMC_GET_PWMTHRS(E, E2), tmc_hybrid_threshold.E2 = TMC_GET_PWMTHRS(E, E2);
#else
E2_HYBRID_THRESHOLD,
#endif #endif
#if MAX_EXTRUDERS > 3 #if MAX_EXTRUDERS > 3
#if AXIS_HAS_STEALTHCHOP(E3) #if AXIS_HAS_STEALTHCHOP(E3)
TMC_GET_PWMTHRS(E, E3), tmc_hybrid_threshold.E3 = TMC_GET_PWMTHRS(E, E3);
#else
E3_HYBRID_THRESHOLD,
#endif #endif
#if MAX_EXTRUDERS > 4 #if MAX_EXTRUDERS > 4
#if AXIS_HAS_STEALTHCHOP(E4) #if AXIS_HAS_STEALTHCHOP(E4)
TMC_GET_PWMTHRS(E, E4) tmc_hybrid_threshold.E4 = TMC_GET_PWMTHRS(E, E4);
#else
E4_HYBRID_THRESHOLD
#endif #endif
#if MAX_EXTRUDERS > 5 #if MAX_EXTRUDERS > 5
#if AXIS_HAS_STEALTHCHOP(E5) #if AXIS_HAS_STEALTHCHOP(E5)
TMC_GET_PWMTHRS(E, E5) tmc_hybrid_threshold.E5 = TMC_GET_PWMTHRS(E, E5);
#else
E5_HYBRID_THRESHOLD
#endif #endif
#endif // MAX_EXTRUDERS > 5 #endif // MAX_EXTRUDERS > 5
#endif // MAX_EXTRUDERS > 4 #endif // MAX_EXTRUDERS > 4
@ -895,54 +846,32 @@ void MarlinSettings::postprocess() {
#endif // MAX_EXTRUDERS > 1 #endif // MAX_EXTRUDERS > 1
#endif // MAX_EXTRUDERS #endif // MAX_EXTRUDERS
#else #else
100, 100, 3, // X, Y, Z const tmc_hybrid_threshold_t tmc_hybrid_threshold = {
100, 100, 3, 3 // X2, Y2, Z2, Z3 .X = 100, .Y = 100, .Z = 3,
#if MAX_EXTRUDERS .X2 = 100, .Y2 = 100, .Z2 = 3, .Z3 = 3,
, 30 // E0 .E0 = 30, .E1 = 30, .E2 = 30,
#if MAX_EXTRUDERS > 1 .E3 = 30, .E4 = 30, .E5 = 30
, 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
#endif
#endif
#endif
#endif
#endif
#endif
#endif
}; };
#endif
EEPROM_WRITE(tmc_hybrid_threshold); EEPROM_WRITE(tmc_hybrid_threshold);
// //
// TMC2130 StallGuard threshold // TMC StallGuard threshold
// //
int16_t tmc_sgt[XYZ] = {
tmc_sgt_t tmc_sgt = { 0, 0, 0 };
#if USE_SENSORLESS #if USE_SENSORLESS
#if X_SENSORLESS #if X_SENSORLESS
stepperX.sgt(), tmc_sgt.X = stepperX.sgt();
#else
0,
#endif #endif
#if Y_SENSORLESS #if Y_SENSORLESS
stepperY.sgt(), tmc_sgt.Y = stepperY.sgt();
#else
0,
#endif #endif
#if Z_SENSORLESS #if Z_SENSORLESS
stepperZ.sgt() tmc_sgt.Z = stepperZ.sgt();
#else
0
#endif #endif
#else
0
#endif #endif
};
EEPROM_WRITE(tmc_sgt); EEPROM_WRITE(tmc_sgt);
// //
@ -1423,15 +1352,15 @@ void MarlinSettings::postprocess() {
if (!validating) reset_stepper_drivers(); if (!validating) reset_stepper_drivers();
// //
// TMC2130 Stepper Settings // TMC Stepper Settings
// //
_FIELD_TEST(tmc_stepper_current); _FIELD_TEST(tmc_stepper_current);
#if HAS_TRINAMIC #if HAS_TRINAMIC
#define SET_CURR(Q) stepper##Q.setCurrent(currents[TMC_##Q] ? currents[TMC_##Q] : Q##_CURRENT, R_SENSE, HOLD_MULTIPLIER) #define SET_CURR(Q) stepper##Q.rms_current(currents.Q ? currents.Q : Q##_CURRENT)
uint16_t currents[TMC_AXES]; tmc_stepper_current_t currents;
EEPROM_READ(currents); EEPROM_READ(currents);
if (!validating) { if (!validating) {
#if AXIS_IS_TMC(X) #if AXIS_IS_TMC(X)
@ -1480,8 +1409,8 @@ void MarlinSettings::postprocess() {
#endif #endif
#if ENABLED(HYBRID_THRESHOLD) #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)]) #define TMC_SET_PWMTHRS(A,Q) tmc_set_pwmthrs(stepper##Q, tmc_hybrid_threshold.Q, planner.axis_steps_per_mm[_AXIS(A)])
uint32_t tmc_hybrid_threshold[TMC_AXES]; tmc_hybrid_threshold_t tmc_hybrid_threshold;
EEPROM_READ(tmc_hybrid_threshold); EEPROM_READ(tmc_hybrid_threshold);
if (!validating) { if (!validating) {
#if AXIS_HAS_STEALTHCHOP(X) #if AXIS_HAS_STEALTHCHOP(X)
@ -1530,40 +1459,40 @@ void MarlinSettings::postprocess() {
#endif #endif
/* /*
* TMC2130 StallGuard threshold. * TMC StallGuard threshold.
* X and X2 use the same value * X and X2 use the same value
* Y and Y2 use the same value * Y and Y2 use the same value
* Z, Z2 and Z3 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); EEPROM_READ(tmc_sgt);
#if USE_SENSORLESS #if USE_SENSORLESS
if (!validating) { if (!validating) {
#ifdef X_STALL_SENSITIVITY #ifdef X_STALL_SENSITIVITY
#if AXIS_HAS_STALLGUARD(X) #if AXIS_HAS_STALLGUARD(X)
stepperX.sgt(tmc_sgt[0]); stepperX.sgt(tmc_sgt.X);
#endif #endif
#if AXIS_HAS_STALLGUARD(X2) #if AXIS_HAS_STALLGUARD(X2)
stepperX2.sgt(tmc_sgt[0]); stepperX2.sgt(tmc_sgt.X);
#endif #endif
#endif #endif
#ifdef Y_STALL_SENSITIVITY #ifdef Y_STALL_SENSITIVITY
#if AXIS_HAS_STALLGUARD(Y) #if AXIS_HAS_STALLGUARD(Y)
stepperY.sgt(tmc_sgt[1]); stepperY.sgt(tmc_sgt.Y);
#endif #endif
#if AXIS_HAS_STALLGUARD(Y2) #if AXIS_HAS_STALLGUARD(Y2)
stepperY2.sgt(tmc_sgt[1]); stepperY2.sgt(tmc_sgt.Y);
#endif #endif
#endif #endif
#ifdef Z_STALL_SENSITIVITY #ifdef Z_STALL_SENSITIVITY
#if AXIS_HAS_STALLGUARD(Z) #if AXIS_HAS_STALLGUARD(Z)
stepperZ.sgt(tmc_sgt[2]); stepperZ.sgt(tmc_sgt.Z);
#endif #endif
#if AXIS_HAS_STALLGUARD(Z2) #if AXIS_HAS_STALLGUARD(Z2)
stepperZ2.sgt(tmc_sgt[2]); stepperZ2.sgt(tmc_sgt.Z);
#endif #endif
#if AXIS_HAS_STALLGUARD(Z3) #if AXIS_HAS_STALLGUARD(Z3)
stepperZ3.sgt(tmc_sgt[2]); stepperZ3.sgt(tmc_sgt.Z);
#endif #endif
#endif #endif
} }
@ -1957,8 +1886,7 @@ void MarlinSettings::reset(PORTARG_SOLO) {
#endif // HAS_SERVOS && EDITABLE_SERVO_ANGLES #endif // HAS_SERVOS && EDITABLE_SERVO_ANGLES
#if ENABLED(DELTA) #if ENABLED(DELTA)
const float adj[ABC] = DELTA_ENDSTOP_ADJ, const float adj[ABC] = DELTA_ENDSTOP_ADJ, dta[ABC] = DELTA_TOWER_ANGLE_TRIM;
dta[ABC] = DELTA_TOWER_ANGLE_TRIM;
delta_height = DELTA_HEIGHT; delta_height = DELTA_HEIGHT;
COPY(delta_endstop_adj, adj); COPY(delta_endstop_adj, adj);
delta_radius = DELTA_RADIUS; delta_radius = DELTA_RADIUS;
@ -2683,7 +2611,7 @@ void MarlinSettings::reset(PORTARG_SOLO) {
#if HAS_TRINAMIC #if HAS_TRINAMIC
/** /**
* TMC2130 / TMC2208 stepper driver current * TMC stepper driver current
*/ */
if (!forReplay) { if (!forReplay) {
CONFIG_ECHO_START; CONFIG_ECHO_START;
@ -2694,65 +2622,68 @@ void MarlinSettings::reset(PORTARG_SOLO) {
say_M906(PORTVAR_SOLO); say_M906(PORTVAR_SOLO);
#endif #endif
#if AXIS_IS_TMC(X) #if AXIS_IS_TMC(X)
SERIAL_ECHOPAIR_P(port, " X", stepperX.getCurrent()); SERIAL_ECHOPAIR_P(port, " X", stepperX.getMilliamps());
#endif #endif
#if AXIS_IS_TMC(Y) #if AXIS_IS_TMC(Y)
SERIAL_ECHOPAIR_P(port, " Y", stepperY.getCurrent()); SERIAL_ECHOPAIR_P(port, " Y", stepperY.getMilliamps());
#endif #endif
#if AXIS_IS_TMC(Z) #if AXIS_IS_TMC(Z)
SERIAL_ECHOPAIR_P(port, " Z", stepperZ.getCurrent()); SERIAL_ECHOPAIR_P(port, " Z", stepperZ.getMilliamps());
#endif #endif
#if AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z) #if AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z)
SERIAL_EOL_P(port); SERIAL_EOL_P(port);
#endif #endif
#if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2) #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2)
say_M906(PORTVAR_SOLO); say_M906(PORTVAR_SOLO);
SERIAL_ECHOPGM_P(port, " I1"); SERIAL_ECHOPGM_P(port, " I1");
#endif #endif
#if AXIS_IS_TMC(X2) #if AXIS_IS_TMC(X2)
SERIAL_ECHOPAIR_P(port, " X", stepperX2.getCurrent()); SERIAL_ECHOPAIR_P(port, " X", stepperX2.getMilliamps());
#endif #endif
#if AXIS_IS_TMC(Y2) #if AXIS_IS_TMC(Y2)
SERIAL_ECHOPAIR_P(port, " Y", stepperY2.getCurrent()); SERIAL_ECHOPAIR_P(port, " Y", stepperY2.getMilliamps());
#endif #endif
#if AXIS_IS_TMC(Z2) #if AXIS_IS_TMC(Z2)
SERIAL_ECHOPAIR_P(port, " Z", stepperZ2.getCurrent()); SERIAL_ECHOPAIR_P(port, " Z", stepperZ2.getMilliamps());
#endif #endif
#if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2) #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2)
SERIAL_EOL_P(port); SERIAL_EOL_P(port);
#endif #endif
#if AXIS_IS_TMC(Z3) #if AXIS_IS_TMC(Z3)
say_M906(PORTVAR_SOLO); say_M906(PORTVAR_SOLO);
SERIAL_ECHOLNPAIR_P(port, " I2 Z", stepperZ3.getCurrent()); SERIAL_ECHOLNPAIR_P(port, " I2 Z", stepperZ3.getMilliamps());
#endif #endif
#if AXIS_IS_TMC(E0) #if AXIS_IS_TMC(E0)
say_M906(PORTVAR_SOLO); say_M906(PORTVAR_SOLO);
SERIAL_ECHOLNPAIR_P(port, " T0 E", stepperE0.getCurrent()); SERIAL_ECHOLNPAIR_P(port, " T0 E", stepperE0.getMilliamps());
#endif #endif
#if AXIS_IS_TMC(E1) #if AXIS_IS_TMC(E1)
say_M906(PORTVAR_SOLO); say_M906(PORTVAR_SOLO);
SERIAL_ECHOLNPAIR_P(port, " T1 E", stepperE1.getCurrent()); SERIAL_ECHOLNPAIR_P(port, " T1 E", stepperE1.getMilliamps());
#endif #endif
#if AXIS_IS_TMC(E2) #if AXIS_IS_TMC(E2)
say_M906(PORTVAR_SOLO); say_M906(PORTVAR_SOLO);
SERIAL_ECHOLNPAIR_P(port, " T2 E", stepperE2.getCurrent()); SERIAL_ECHOLNPAIR_P(port, " T2 E", stepperE2.getMilliamps());
#endif #endif
#if AXIS_IS_TMC(E3) #if AXIS_IS_TMC(E3)
say_M906(PORTVAR_SOLO); say_M906(PORTVAR_SOLO);
SERIAL_ECHOLNPAIR_P(port, " T3 E", stepperE3.getCurrent()); SERIAL_ECHOLNPAIR_P(port, " T3 E", stepperE3.getMilliamps());
#endif #endif
#if AXIS_IS_TMC(E4) #if AXIS_IS_TMC(E4)
say_M906(PORTVAR_SOLO); say_M906(PORTVAR_SOLO);
SERIAL_ECHOLNPAIR_P(port, " T4 E", stepperE4.getCurrent()); SERIAL_ECHOLNPAIR_P(port, " T4 E", stepperE4.getMilliamps());
#endif #endif
#if AXIS_IS_TMC(E5) #if AXIS_IS_TMC(E5)
say_M906(PORTVAR_SOLO); say_M906(PORTVAR_SOLO);
SERIAL_ECHOLNPAIR_P(port, " T5 E", stepperE5.getCurrent()); SERIAL_ECHOLNPAIR_P(port, " T5 E", stepperE5.getMilliamps());
#endif #endif
SERIAL_EOL_P(port); SERIAL_EOL_P(port);
/** /**
* TMC2130 / TMC2208 / TRAMS Hybrid Threshold * TMC Hybrid Threshold
*/ */
#if ENABLED(HYBRID_THRESHOLD) #if ENABLED(HYBRID_THRESHOLD)
if (!forReplay) { if (!forReplay) {
@ -2760,63 +2691,66 @@ void MarlinSettings::reset(PORTARG_SOLO) {
SERIAL_ECHOLNPGM_P(port, "Hybrid Threshold:"); SERIAL_ECHOLNPGM_P(port, "Hybrid Threshold:");
} }
CONFIG_ECHO_START; 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); say_M913(PORTVAR_SOLO);
#endif #endif
#if AXIS_IS_TMC(X) #if AXIS_HAS_STEALTHCHOP(X)
SERIAL_ECHOPAIR_P(port, " X", TMC_GET_PWMTHRS(X, X)); SERIAL_ECHOPAIR_P(port, " X", TMC_GET_PWMTHRS(X, X));
#endif #endif
#if AXIS_IS_TMC(Y) #if AXIS_HAS_STEALTHCHOP(Y)
SERIAL_ECHOPAIR_P(port, " Y", TMC_GET_PWMTHRS(Y, Y)); SERIAL_ECHOPAIR_P(port, " Y", TMC_GET_PWMTHRS(Y, Y));
#endif #endif
#if AXIS_IS_TMC(Z) #if AXIS_HAS_STEALTHCHOP(Z)
SERIAL_ECHOPAIR_P(port, " Z", TMC_GET_PWMTHRS(Z, Z)); SERIAL_ECHOPAIR_P(port, " Z", TMC_GET_PWMTHRS(Z, Z));
#endif #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); SERIAL_EOL_P(port);
#endif #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); say_M913(PORTVAR_SOLO);
SERIAL_ECHOPGM_P(port, " I1"); SERIAL_ECHOPGM_P(port, " I1");
#endif #endif
#if AXIS_IS_TMC(X2) #if AXIS_HAS_STEALTHCHOP(X2)
SERIAL_ECHOPAIR_P(port, " X", TMC_GET_PWMTHRS(X, X2)); SERIAL_ECHOPAIR_P(port, " X", TMC_GET_PWMTHRS(X, X2));
#endif #endif
#if AXIS_IS_TMC(Y2) #if AXIS_HAS_STEALTHCHOP(Y2)
SERIAL_ECHOPAIR_P(port, " Y", TMC_GET_PWMTHRS(Y, Y2)); SERIAL_ECHOPAIR_P(port, " Y", TMC_GET_PWMTHRS(Y, Y2));
#endif #endif
#if AXIS_IS_TMC(Z2) #if AXIS_HAS_STEALTHCHOP(Z2)
SERIAL_ECHOPAIR_P(port, " Z", TMC_GET_PWMTHRS(Z, Z2)); SERIAL_ECHOPAIR_P(port, " Z", TMC_GET_PWMTHRS(Z, Z2));
#endif #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); SERIAL_EOL_P(port);
#endif #endif
#if AXIS_IS_TMC(Z3)
#if AXIS_HAS_STEALTHCHOP(Z3)
say_M913(PORTVAR_SOLO); say_M913(PORTVAR_SOLO);
SERIAL_ECHOPGM_P(port, " I2"); SERIAL_ECHOPGM_P(port, " I2");
SERIAL_ECHOLNPAIR_P(port, " Z", TMC_GET_PWMTHRS(Z, Z3)); SERIAL_ECHOLNPAIR_P(port, " Z", TMC_GET_PWMTHRS(Z, Z3));
#endif #endif
#if AXIS_IS_TMC(E0)
#if AXIS_HAS_STEALTHCHOP(E0)
say_M913(PORTVAR_SOLO); say_M913(PORTVAR_SOLO);
SERIAL_ECHOLNPAIR_P(port, " T0 E", TMC_GET_PWMTHRS(E, E0)); SERIAL_ECHOLNPAIR_P(port, " T0 E", TMC_GET_PWMTHRS(E, E0));
#endif #endif
#if AXIS_IS_TMC(E1) #if AXIS_HAS_STEALTHCHOP(E1)
say_M913(PORTVAR_SOLO); say_M913(PORTVAR_SOLO);
SERIAL_ECHOLNPAIR_P(port, " T1 E", TMC_GET_PWMTHRS(E, E1)); SERIAL_ECHOLNPAIR_P(port, " T1 E", TMC_GET_PWMTHRS(E, E1));
#endif #endif
#if AXIS_IS_TMC(E2) #if AXIS_HAS_STEALTHCHOP(E2)
say_M913(PORTVAR_SOLO); say_M913(PORTVAR_SOLO);
SERIAL_ECHOLNPAIR_P(port, " T2 E", TMC_GET_PWMTHRS(E, E2)); SERIAL_ECHOLNPAIR_P(port, " T2 E", TMC_GET_PWMTHRS(E, E2));
#endif #endif
#if AXIS_IS_TMC(E3) #if AXIS_HAS_STEALTHCHOP(E3)
say_M913(PORTVAR_SOLO); say_M913(PORTVAR_SOLO);
SERIAL_ECHOLNPAIR_P(port, " T3 E", TMC_GET_PWMTHRS(E, E3)); SERIAL_ECHOLNPAIR_P(port, " T3 E", TMC_GET_PWMTHRS(E, E3));
#endif #endif
#if AXIS_IS_TMC(E4) #if AXIS_HAS_STEALTHCHOP(E4)
say_M913(PORTVAR_SOLO); say_M913(PORTVAR_SOLO);
SERIAL_ECHOLNPAIR_P(port, " T4 E", TMC_GET_PWMTHRS(E, E4)); SERIAL_ECHOLNPAIR_P(port, " T4 E", TMC_GET_PWMTHRS(E, E4));
#endif #endif
#if AXIS_IS_TMC(E5) #if AXIS_HAS_STEALTHCHOP(E5)
say_M913(PORTVAR_SOLO); say_M913(PORTVAR_SOLO);
SERIAL_ECHOLNPAIR_P(port, " T5 E", TMC_GET_PWMTHRS(E, E5)); SERIAL_ECHOLNPAIR_P(port, " T5 E", TMC_GET_PWMTHRS(E, E5));
#endif #endif
@ -2824,7 +2758,7 @@ void MarlinSettings::reset(PORTARG_SOLO) {
#endif // HYBRID_THRESHOLD #endif // HYBRID_THRESHOLD
/** /**
* TMC2130 Sensorless homing thresholds * TMC Sensorless homing thresholds
*/ */
#if USE_SENSORLESS #if USE_SENSORLESS
if (!forReplay) { if (!forReplay) {

View file

@ -139,171 +139,104 @@
} }
#endif // TMC26X #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 // TMC2130 Driver objects and inits
// //
#if HAS_DRIVER(TMC2130) #if HAS_DRIVER(TMC2130)
#include <SPI.h> #include <SPI.h>
#include <TMC2130Stepper.h>
#include "planner.h" #include "planner.h"
#include "../core/enum.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) #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<TMC2130Stepper, L> 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 #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<TMC2130Stepper, L> stepper##ST(ST##_CS_PIN, R_SENSE)
#define TMC2130_DEFINE(ST) _TMC2130_DEFINE(ST, TMC_##ST##_LABEL)
#endif #endif
// Stepper objects of TMC2130 steppers used // Stepper objects of TMC2130 steppers used
#if AXIS_DRIVER_TYPE(X, TMC2130) #if AXIS_DRIVER_TYPE(X, TMC2130)
_TMC2130_DEFINE(X); TMC2130_DEFINE(X);
#endif #endif
#if AXIS_DRIVER_TYPE(X2, TMC2130) #if AXIS_DRIVER_TYPE(X2, TMC2130)
_TMC2130_DEFINE(X2); TMC2130_DEFINE(X2);
#endif #endif
#if AXIS_DRIVER_TYPE(Y, TMC2130) #if AXIS_DRIVER_TYPE(Y, TMC2130)
_TMC2130_DEFINE(Y); TMC2130_DEFINE(Y);
#endif #endif
#if AXIS_DRIVER_TYPE(Y2, TMC2130) #if AXIS_DRIVER_TYPE(Y2, TMC2130)
_TMC2130_DEFINE(Y2); TMC2130_DEFINE(Y2);
#endif #endif
#if AXIS_DRIVER_TYPE(Z, TMC2130) #if AXIS_DRIVER_TYPE(Z, TMC2130)
_TMC2130_DEFINE(Z); TMC2130_DEFINE(Z);
#endif #endif
#if AXIS_DRIVER_TYPE(Z2, TMC2130) #if AXIS_DRIVER_TYPE(Z2, TMC2130)
_TMC2130_DEFINE(Z2); TMC2130_DEFINE(Z2);
#endif #endif
#if AXIS_DRIVER_TYPE(Z3, TMC2130) #if AXIS_DRIVER_TYPE(Z3, TMC2130)
_TMC2130_DEFINE(Z3); TMC2130_DEFINE(Z3);
#endif #endif
#if AXIS_DRIVER_TYPE(E0, TMC2130) #if AXIS_DRIVER_TYPE(E0, TMC2130)
_TMC2130_DEFINE(E0); TMC2130_DEFINE(E0);
#endif #endif
#if AXIS_DRIVER_TYPE(E1, TMC2130) #if AXIS_DRIVER_TYPE(E1, TMC2130)
_TMC2130_DEFINE(E1); TMC2130_DEFINE(E1);
#endif #endif
#if AXIS_DRIVER_TYPE(E2, TMC2130) #if AXIS_DRIVER_TYPE(E2, TMC2130)
_TMC2130_DEFINE(E2); TMC2130_DEFINE(E2);
#endif #endif
#if AXIS_DRIVER_TYPE(E3, TMC2130) #if AXIS_DRIVER_TYPE(E3, TMC2130)
_TMC2130_DEFINE(E3); TMC2130_DEFINE(E3);
#endif #endif
#if AXIS_DRIVER_TYPE(E4, TMC2130) #if AXIS_DRIVER_TYPE(E4, TMC2130)
_TMC2130_DEFINE(E4); TMC2130_DEFINE(E4);
#endif #endif
#if AXIS_DRIVER_TYPE(E5, TMC2130) #if AXIS_DRIVER_TYPE(E5, TMC2130)
_TMC2130_DEFINE(E5); TMC2130_DEFINE(E5);
#endif #endif
// Use internal reference voltage for current calculations. This is the default. template<char AXIS_LETTER, char DRIVER_ID>
// Following values from Trinamic's spreadsheet with values for a NEMA17 (42BYGHW609) void tmc_init(TMCMarlin<TMC2130Stepper, AXIS_LETTER, DRIVER_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
// 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) {
#if DISABLED(STEALTHCHOP) || DISABLED(HYBRID_THRESHOLD) #if DISABLED(STEALTHCHOP) || DISABLED(HYBRID_THRESHOLD)
UNUSED(thrs); UNUSED(thrs);
UNUSED(spmm); UNUSED(spmm);
#endif #endif
st.begin(); 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.microsteps(microsteps);
st.blank_time(24); st.iholddelay(10);
st.off_time(5); // Only enables the driver if used with stealthChop st.TPOWERDOWN(128); // ~2s until driver lowers to hold current
st.interpolate(INTERPOLATE);
st.power_down_delay(128); // ~2s until driver lowers to hold current
st.hysteresis_start(3);
st.hysteresis_end(2);
#if ENABLED(STEALTHCHOP) #if ENABLED(STEALTHCHOP)
st.stealth_freq(1); // f_pwm = 2/683 f_clk st.en_pwm_mode(true);
st.stealth_autoscale(1);
st.stealth_gradient(5); PWMCONF_t pwmconf{0};
st.stealth_amplitude(255); pwmconf.pwm_freq = 0b01; // f_pwm = 2/683 f_clk
st.stealthChop(1); pwmconf.pwm_autoscale = true;
pwmconf.pwm_grad = 5;
pwmconf.pwm_ampl = 180;
st.PWMCONF(pwmconf.sr);
#if ENABLED(HYBRID_THRESHOLD) #if ENABLED(HYBRID_THRESHOLD)
st.stealth_max_speed(12650000UL*microsteps/(256*thrs*spmm)); st.TPWMTHRS(12650000UL*microsteps/(256*thrs*spmm));
#endif #endif
#endif #endif
st.GSTAT(); // Clear GSTAT st.GSTAT(); // Clear GSTAT
} }
#define _TMC2130_INIT(ST, SPMM) tmc2130_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, SPMM)
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
#endif
#endif
}
#endif // TMC2130 #endif // TMC2130
// //
@ -311,106 +244,104 @@
// //
#if HAS_DRIVER(TMC2208) #if HAS_DRIVER(TMC2208)
#include <HardwareSerial.h> #include <HardwareSerial.h>
#include <TMC2208Stepper.h>
#include "planner.h" #include "planner.h"
#if TMC2208STEPPER_VERSION < 0x000101 #define _TMC2208_DEFINE_HARDWARE(ST, L) TMCMarlin<TMC2208Stepper, L> stepper##ST(&ST##_HARDWARE_SERIAL, R_SENSE)
#error "Update TMC2208Stepper library to 0.1.1 or newer." #define TMC2208_DEFINE_HARDWARE(ST) _TMC2208_DEFINE_HARDWARE(ST, TMC_##ST##_LABEL)
#endif
#define _TMC2208_DEFINE_HARDWARE(ST) TMC2208Stepper stepper##ST(&ST##_HARDWARE_SERIAL) #define _TMC2208_DEFINE_SOFTWARE(ST, L) TMCMarlin<TMC2208Stepper, L> stepper##ST(ST##_SERIAL_RX_PIN, ST##_SERIAL_TX_PIN, R_SENSE, ST##_SERIAL_RX_PIN > -1)
#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) _TMC2208_DEFINE_SOFTWARE(ST, TMC_##ST##_LABEL)
// Stepper objects of TMC2208 steppers used // Stepper objects of TMC2208 steppers used
#if AXIS_DRIVER_TYPE(X, TMC2208) #if AXIS_DRIVER_TYPE(X, TMC2208)
#ifdef X_HARDWARE_SERIAL #ifdef X_HARDWARE_SERIAL
_TMC2208_DEFINE_HARDWARE(X); TMC2208_DEFINE_HARDWARE(X);
#else #else
_TMC2208_DEFINE_SOFTWARE(X); TMC2208_DEFINE_SOFTWARE(X);
#endif #endif
#endif #endif
#if AXIS_DRIVER_TYPE(X2, TMC2208) #if AXIS_DRIVER_TYPE(X2, TMC2208)
#ifdef X2_HARDWARE_SERIAL #ifdef X2_HARDWARE_SERIAL
_TMC2208_DEFINE_HARDWARE(X2); TMC2208_DEFINE_HARDWARE(X2);
#else #else
_TMC2208_DEFINE_SOFTWARE(X2); TMC2208_DEFINE_SOFTWARE(X2);
#endif #endif
#endif #endif
#if AXIS_DRIVER_TYPE(Y, TMC2208) #if AXIS_DRIVER_TYPE(Y, TMC2208)
#ifdef Y_HARDWARE_SERIAL #ifdef Y_HARDWARE_SERIAL
_TMC2208_DEFINE_HARDWARE(Y); TMC2208_DEFINE_HARDWARE(Y);
#else #else
_TMC2208_DEFINE_SOFTWARE(Y); TMC2208_DEFINE_SOFTWARE(Y);
#endif #endif
#endif #endif
#if AXIS_DRIVER_TYPE(Y2, TMC2208) #if AXIS_DRIVER_TYPE(Y2, TMC2208)
#ifdef Y2_HARDWARE_SERIAL #ifdef Y2_HARDWARE_SERIAL
_TMC2208_DEFINE_HARDWARE(Y2); TMC2208_DEFINE_HARDWARE(Y2);
#else #else
_TMC2208_DEFINE_SOFTWARE(Y2); TMC2208_DEFINE_SOFTWARE(Y2);
#endif #endif
#endif #endif
#if AXIS_DRIVER_TYPE(Z, TMC2208) #if AXIS_DRIVER_TYPE(Z, TMC2208)
#ifdef Z_HARDWARE_SERIAL #ifdef Z_HARDWARE_SERIAL
_TMC2208_DEFINE_HARDWARE(Z); TMC2208_DEFINE_HARDWARE(Z);
#else #else
_TMC2208_DEFINE_SOFTWARE(Z); TMC2208_DEFINE_SOFTWARE(Z);
#endif #endif
#endif #endif
#if AXIS_DRIVER_TYPE(Z2, TMC2208) #if AXIS_DRIVER_TYPE(Z2, TMC2208)
#ifdef Z2_HARDWARE_SERIAL #ifdef Z2_HARDWARE_SERIAL
_TMC2208_DEFINE_HARDWARE(Z2); TMC2208_DEFINE_HARDWARE(Z2);
#else #else
_TMC2208_DEFINE_SOFTWARE(Z2); TMC2208_DEFINE_SOFTWARE(Z2);
#endif #endif
#endif #endif
#if AXIS_DRIVER_TYPE(Z3, TMC2208) #if AXIS_DRIVER_TYPE(Z3, TMC2208)
#ifdef Z3_HARDWARE_SERIAL #ifdef Z3_HARDWARE_SERIAL
_TMC2208_DEFINE_HARDWARE(Z3); TMC2208_DEFINE_HARDWARE(Z3);
#else #else
_TMC2208_DEFINE_SOFTWARE(Z3); TMC2208_DEFINE_SOFTWARE(Z3);
#endif #endif
#endif #endif
#if AXIS_DRIVER_TYPE(E0, TMC2208) #if AXIS_DRIVER_TYPE(E0, TMC2208)
#ifdef E0_HARDWARE_SERIAL #ifdef E0_HARDWARE_SERIAL
_TMC2208_DEFINE_HARDWARE(E0); TMC2208_DEFINE_HARDWARE(E0);
#else #else
_TMC2208_DEFINE_SOFTWARE(E0); TMC2208_DEFINE_SOFTWARE(E0);
#endif #endif
#endif #endif
#if AXIS_DRIVER_TYPE(E1, TMC2208) #if AXIS_DRIVER_TYPE(E1, TMC2208)
#ifdef E1_HARDWARE_SERIAL #ifdef E1_HARDWARE_SERIAL
_TMC2208_DEFINE_HARDWARE(E1); TMC2208_DEFINE_HARDWARE(E1);
#else #else
_TMC2208_DEFINE_SOFTWARE(E1); TMC2208_DEFINE_SOFTWARE(E1);
#endif #endif
#endif #endif
#if AXIS_DRIVER_TYPE(E2, TMC2208) #if AXIS_DRIVER_TYPE(E2, TMC2208)
#ifdef E2_HARDWARE_SERIAL #ifdef E2_HARDWARE_SERIAL
_TMC2208_DEFINE_HARDWARE(E2); TMC2208_DEFINE_HARDWARE(E2);
#else #else
_TMC2208_DEFINE_SOFTWARE(E2); TMC2208_DEFINE_SOFTWARE(E2);
#endif #endif
#endif #endif
#if AXIS_DRIVER_TYPE(E3, TMC2208) #if AXIS_DRIVER_TYPE(E3, TMC2208)
#ifdef E3_HARDWARE_SERIAL #ifdef E3_HARDWARE_SERIAL
_TMC2208_DEFINE_HARDWARE(E3); TMC2208_DEFINE_HARDWARE(E3);
#else #else
_TMC2208_DEFINE_SOFTWARE(E3); TMC2208_DEFINE_SOFTWARE(E3);
#endif #endif
#endif #endif
#if AXIS_DRIVER_TYPE(E4, TMC2208) #if AXIS_DRIVER_TYPE(E4, TMC2208)
#ifdef E4_HARDWARE_SERIAL #ifdef E4_HARDWARE_SERIAL
_TMC2208_DEFINE_HARDWARE(E4); TMC2208_DEFINE_HARDWARE(E4);
#else #else
_TMC2208_DEFINE_SOFTWARE(E4); TMC2208_DEFINE_SOFTWARE(E4);
#endif #endif
#endif #endif
#if AXIS_DRIVER_TYPE(E5, TMC2208) #if AXIS_DRIVER_TYPE(E5, TMC2208)
#ifdef E5_HARDWARE_SERIAL #ifdef E5_HARDWARE_SERIAL
_TMC2208_DEFINE_HARDWARE(E5); TMC2208_DEFINE_HARDWARE(E5);
#else #else
_TMC2208_DEFINE_SOFTWARE(E5); TMC2208_DEFINE_SOFTWARE(E5);
#endif #endif
#endif #endif
@ -508,85 +439,52 @@
#endif #endif
} }
// Use internal reference voltage for current calculations. This is the default. template<char AXIS_LETTER, char DRIVER_ID>
// Following values from Trinamic's spreadsheet with values for a NEMA17 (42BYGHW609) void tmc_init(TMCMarlin<TMC2208Stepper, AXIS_LETTER, DRIVER_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
void tmc2208_init(TMC2208Stepper &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) { #if DISABLED(STEALTHCHOP) || DISABLED(HYBRID_THRESHOLD)
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);
st.microsteps(microsteps);
st.blank_time(24);
st.toff(5);
st.intpol(INTERPOLATE);
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);
#if ENABLED(HYBRID_THRESHOLD)
st.TPWMTHRS(12650000UL*microsteps/(256*thrs*spmm));
#else
UNUSED(thrs); UNUSED(thrs);
UNUSED(spmm); UNUSED(spmm);
#endif #endif
#else
st.en_spreadCycle(true); 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.iholddelay(10);
st.TPOWERDOWN(128); // ~2s until driver lowers to hold current
#if ENABLED(STEALTHCHOP)
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));
#endif #endif
#else
gconf.en_spreadcycle = true;
#endif
st.GCONF(gconf.sr);
st.GSTAT(0b111); // Clear st.GSTAT(0b111); // Clear
delay(200); 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 #endif // TMC2208
void restore_stepper_drivers() { void restore_stepper_drivers() {
@ -635,20 +533,84 @@ void reset_stepper_drivers() {
#if HAS_DRIVER(TMC26X) #if HAS_DRIVER(TMC26X)
tmc26x_init_to_defaults(); tmc26x_init_to_defaults();
#endif #endif
#if HAS_DRIVER(TMC2130) #if ENABLED(HAVE_L6470DRIVER)
delay(100); L6470_init_to_defaults();
tmc2130_init_to_defaults();
#endif #endif
#if HAS_DRIVER(TMC2208)
delay(100); #if AXIS_IS_TMC(X)
tmc2208_init_to_defaults(); _TMC_INIT(X, planner.axis_steps_per_mm[X_AXIS]);
#endif #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 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 #ifdef TMC_ADV
TMC_ADV() TMC_ADV()
#endif #endif
#if HAS_DRIVER(L6470)
L6470_init_to_defaults();
#endif
stepper.set_directions(); stepper.set_directions();
} }

View file

@ -57,15 +57,20 @@
void tmc26x_init_to_defaults(); void tmc26x_init_to_defaults();
#endif #endif
#if HAS_DRIVER(TMC2130) #if HAS_TRINAMIC
#include <TMC2130Stepper.h> #include <TMCStepper.h>
void tmc2130_init_to_defaults(); #include "../feature/tmc_util.h"
#if TMCSTEPPER_VERSION < 0x000001
#error "Update TMCStepper library to 0.0.1 or newer."
#endif #endif
#define __TMC_CLASS(MODEL, A, I) TMCMarlin<TMC##MODEL##Stepper, A, I>
#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) #if HAS_DRIVER(TMC2208)
#include <TMC2208Stepper.h>
void tmc2208_serial_begin(); void tmc2208_serial_begin();
void tmc2208_init_to_defaults(); #endif
#endif #endif
// L6470 has STEP on normal pins, but DIR/ENABLE via SPI // 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_WRITE(STATE) stepperX.Step_Clock(STATE)
#define X_DIR_READ (stepperX.getStatus() & STATUS_DIR) #define X_DIR_READ (stepperX.getStatus() & STATUS_DIR)
#else #else
#if AXIS_IS_TMC(X)
extern TMC_CLASS(X) stepperX;
#endif
#if AXIS_DRIVER_TYPE(X, TMC26X) #if AXIS_DRIVER_TYPE(X, TMC26X)
extern TMC26XStepper stepperX; extern TMC26XStepper stepperX;
#define X_ENABLE_INIT NOOP #define X_ENABLE_INIT NOOP
#define X_ENABLE_WRITE(STATE) stepperX.setEnabled(STATE) #define X_ENABLE_WRITE(STATE) stepperX.setEnabled(STATE)
#define X_ENABLE_READ stepperX.isEnabled() #define X_ENABLE_READ stepperX.isEnabled()
#else #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_INIT SET_OUTPUT(X_ENABLE_PIN)
#define X_ENABLE_WRITE(STATE) WRITE(X_ENABLE_PIN,STATE) #define X_ENABLE_WRITE(STATE) WRITE(X_ENABLE_PIN,STATE)
#define X_ENABLE_READ READ(X_ENABLE_PIN) #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_WRITE(STATE) stepperY.Step_Clock(STATE)
#define Y_DIR_READ (stepperY.getStatus() & STATUS_DIR) #define Y_DIR_READ (stepperY.getStatus() & STATUS_DIR)
#else #else
#if AXIS_IS_TMC(Y)
extern TMC_CLASS(Y) stepperY;
#endif
#if AXIS_DRIVER_TYPE(Y, TMC26X) #if AXIS_DRIVER_TYPE(Y, TMC26X)
extern TMC26XStepper stepperY; extern TMC26XStepper stepperY;
#define Y_ENABLE_INIT NOOP #define Y_ENABLE_INIT NOOP
#define Y_ENABLE_WRITE(STATE) stepperY.setEnabled(STATE) #define Y_ENABLE_WRITE(STATE) stepperY.setEnabled(STATE)
#define Y_ENABLE_READ stepperY.isEnabled() #define Y_ENABLE_READ stepperY.isEnabled()
#else #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_INIT SET_OUTPUT(Y_ENABLE_PIN)
#define Y_ENABLE_WRITE(STATE) WRITE(Y_ENABLE_PIN,STATE) #define Y_ENABLE_WRITE(STATE) WRITE(Y_ENABLE_PIN,STATE)
#define Y_ENABLE_READ READ(Y_ENABLE_PIN) #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_WRITE(STATE) stepperZ.Step_Clock(STATE)
#define Z_DIR_READ (stepperZ.getStatus() & STATUS_DIR) #define Z_DIR_READ (stepperZ.getStatus() & STATUS_DIR)
#else #else
#if AXIS_IS_TMC(Z)
extern TMC_CLASS(Z) stepperZ;
#endif
#if AXIS_DRIVER_TYPE(Z, TMC26X) #if AXIS_DRIVER_TYPE(Z, TMC26X)
extern TMC26XStepper stepperZ; extern TMC26XStepper stepperZ;
#define Z_ENABLE_INIT NOOP #define Z_ENABLE_INIT NOOP
#define Z_ENABLE_WRITE(STATE) stepperZ.setEnabled(STATE) #define Z_ENABLE_WRITE(STATE) stepperZ.setEnabled(STATE)
#define Z_ENABLE_READ stepperZ.isEnabled() #define Z_ENABLE_READ stepperZ.isEnabled()
#else #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_INIT SET_OUTPUT(Z_ENABLE_PIN)
#define Z_ENABLE_WRITE(STATE) WRITE(Z_ENABLE_PIN,STATE) #define Z_ENABLE_WRITE(STATE) WRITE(Z_ENABLE_PIN,STATE)
#define Z_ENABLE_READ READ(Z_ENABLE_PIN) #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_WRITE(STATE) stepperX2.Step_Clock(STATE)
#define X2_DIR_READ (stepperX2.getStatus() & STATUS_DIR) #define X2_DIR_READ (stepperX2.getStatus() & STATUS_DIR)
#else #else
#if AXIS_IS_TMC(X2)
extern TMC_CLASS(X2) stepperX2;
#endif
#if AXIS_DRIVER_TYPE(X2, TMC26X) #if AXIS_DRIVER_TYPE(X2, TMC26X)
extern TMC26XStepper stepperX2; extern TMC26XStepper stepperX2;
#define X2_ENABLE_INIT NOOP #define X2_ENABLE_INIT NOOP
#define X2_ENABLE_WRITE(STATE) stepperX2.setEnabled(STATE) #define X2_ENABLE_WRITE(STATE) stepperX2.setEnabled(STATE)
#define X2_ENABLE_READ stepperX2.isEnabled() #define X2_ENABLE_READ stepperX2.isEnabled()
#else #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_INIT SET_OUTPUT(X2_ENABLE_PIN)
#define X2_ENABLE_WRITE(STATE) WRITE(X2_ENABLE_PIN,STATE) #define X2_ENABLE_WRITE(STATE) WRITE(X2_ENABLE_PIN,STATE)
#define X2_ENABLE_READ READ(X2_ENABLE_PIN) #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_WRITE(STATE) stepperY2.Step_Clock(STATE)
#define Y2_DIR_READ (stepperY2.getStatus() & STATUS_DIR) #define Y2_DIR_READ (stepperY2.getStatus() & STATUS_DIR)
#else #else
#if AXIS_IS_TMC(Y2)
extern TMC_CLASS(Y2) stepperY2;
#endif
#if AXIS_DRIVER_TYPE(Y2, TMC26X) #if AXIS_DRIVER_TYPE(Y2, TMC26X)
extern TMC26XStepper stepperY2; extern TMC26XStepper stepperY2;
#define Y2_ENABLE_INIT NOOP #define Y2_ENABLE_INIT NOOP
#define Y2_ENABLE_WRITE(STATE) stepperY2.setEnabled(STATE) #define Y2_ENABLE_WRITE(STATE) stepperY2.setEnabled(STATE)
#define Y2_ENABLE_READ stepperY2.isEnabled() #define Y2_ENABLE_READ stepperY2.isEnabled()
#else #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_INIT SET_OUTPUT(Y2_ENABLE_PIN)
#define Y2_ENABLE_WRITE(STATE) WRITE(Y2_ENABLE_PIN,STATE) #define Y2_ENABLE_WRITE(STATE) WRITE(Y2_ENABLE_PIN,STATE)
#define Y2_ENABLE_READ READ(Y2_ENABLE_PIN) #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_WRITE(STATE) stepperZ2.Step_Clock(STATE)
#define Z2_DIR_READ (stepperZ2.getStatus() & STATUS_DIR) #define Z2_DIR_READ (stepperZ2.getStatus() & STATUS_DIR)
#else #else
#if AXIS_IS_TMC(Z2)
extern TMC_CLASS(Z2) stepperZ2;
#endif
#if AXIS_DRIVER_TYPE(Z2, TMC26X) #if AXIS_DRIVER_TYPE(Z2, TMC26X)
extern TMC26XStepper stepperZ2; extern TMC26XStepper stepperZ2;
#define Z2_ENABLE_INIT NOOP #define Z2_ENABLE_INIT NOOP
#define Z2_ENABLE_WRITE(STATE) stepperZ2.setEnabled(STATE) #define Z2_ENABLE_WRITE(STATE) stepperZ2.setEnabled(STATE)
#define Z2_ENABLE_READ stepperZ2.isEnabled() #define Z2_ENABLE_READ stepperZ2.isEnabled()
#else #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_INIT SET_OUTPUT(Z2_ENABLE_PIN)
#define Z2_ENABLE_WRITE(STATE) WRITE(Z2_ENABLE_PIN,STATE) #define Z2_ENABLE_WRITE(STATE) WRITE(Z2_ENABLE_PIN,STATE)
#define Z2_ENABLE_READ READ(Z2_ENABLE_PIN) #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_WRITE(STATE) stepperZ3.Step_Clock(STATE)
#define Z3_DIR_READ (stepperZ3.getStatus() & STATUS_DIR) #define Z3_DIR_READ (stepperZ3.getStatus() & STATUS_DIR)
#else #else
#if AXIS_IS_TMC(Z3)
extern TMC_CLASS(Z3) stepperZ3;
#endif
#if ENABLED(Z3_IS_TMC26X) #if ENABLED(Z3_IS_TMC26X)
extern TMC26XStepper stepperZ3; extern TMC26XStepper stepperZ3;
#define Z3_ENABLE_INIT NOOP #define Z3_ENABLE_INIT NOOP
#define Z3_ENABLE_WRITE(STATE) stepperZ3.setEnabled(STATE) #define Z3_ENABLE_WRITE(STATE) stepperZ3.setEnabled(STATE)
#define Z3_ENABLE_READ stepperZ3.isEnabled() #define Z3_ENABLE_READ stepperZ3.isEnabled()
#else #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_INIT SET_OUTPUT(Z3_ENABLE_PIN)
#define Z3_ENABLE_WRITE(STATE) WRITE(Z3_ENABLE_PIN,STATE) #define Z3_ENABLE_WRITE(STATE) WRITE(Z3_ENABLE_PIN,STATE)
#define Z3_ENABLE_READ READ(Z3_ENABLE_PIN) #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_WRITE(STATE) stepperE0.Step_Clock(STATE)
#define E0_DIR_READ (stepperE0.getStatus() & STATUS_DIR) #define E0_DIR_READ (stepperE0.getStatus() & STATUS_DIR)
#else #else
#if AXIS_IS_TMC(E0)
extern TMC_CLASS(E0) stepperE0;
#endif
#if AXIS_DRIVER_TYPE(E0, TMC26X) #if AXIS_DRIVER_TYPE(E0, TMC26X)
extern TMC26XStepper stepperE0; extern TMC26XStepper stepperE0;
#define E0_ENABLE_INIT NOOP #define E0_ENABLE_INIT NOOP
#define E0_ENABLE_WRITE(STATE) stepperE0.setEnabled(STATE) #define E0_ENABLE_WRITE(STATE) stepperE0.setEnabled(STATE)
#define E0_ENABLE_READ stepperE0.isEnabled() #define E0_ENABLE_READ stepperE0.isEnabled()
#else #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_INIT SET_OUTPUT(E0_ENABLE_PIN)
#define E0_ENABLE_WRITE(STATE) WRITE(E0_ENABLE_PIN,STATE) #define E0_ENABLE_WRITE(STATE) WRITE(E0_ENABLE_PIN,STATE)
#define E0_ENABLE_READ READ(E0_ENABLE_PIN) #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_WRITE(STATE) stepperE1.Step_Clock(STATE)
#define E1_DIR_READ (stepperE1.getStatus() & STATUS_DIR) #define E1_DIR_READ (stepperE1.getStatus() & STATUS_DIR)
#else #else
#if AXIS_IS_TMC(E1)
extern TMC_CLASS(E1) stepperE1;
#endif
#if AXIS_DRIVER_TYPE(E1, TMC26X) #if AXIS_DRIVER_TYPE(E1, TMC26X)
extern TMC26XStepper stepperE1; extern TMC26XStepper stepperE1;
#define E1_ENABLE_INIT NOOP #define E1_ENABLE_INIT NOOP
#define E1_ENABLE_WRITE(STATE) stepperE1.setEnabled(STATE) #define E1_ENABLE_WRITE(STATE) stepperE1.setEnabled(STATE)
#define E1_ENABLE_READ stepperE1.isEnabled() #define E1_ENABLE_READ stepperE1.isEnabled()
#else #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_INIT SET_OUTPUT(E1_ENABLE_PIN)
#define E1_ENABLE_WRITE(STATE) WRITE(E1_ENABLE_PIN,STATE) #define E1_ENABLE_WRITE(STATE) WRITE(E1_ENABLE_PIN,STATE)
#define E1_ENABLE_READ READ(E1_ENABLE_PIN) #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_WRITE(STATE) stepperE2.Step_Clock(STATE)
#define E2_DIR_READ (stepperE2.getStatus() & STATUS_DIR) #define E2_DIR_READ (stepperE2.getStatus() & STATUS_DIR)
#else #else
#if AXIS_IS_TMC(E2)
extern TMC_CLASS(E2) stepperE2;
#endif
#if AXIS_DRIVER_TYPE(E2, TMC26X) #if AXIS_DRIVER_TYPE(E2, TMC26X)
extern TMC26XStepper stepperE2; extern TMC26XStepper stepperE2;
#define E2_ENABLE_INIT NOOP #define E2_ENABLE_INIT NOOP
#define E2_ENABLE_WRITE(STATE) stepperE2.setEnabled(STATE) #define E2_ENABLE_WRITE(STATE) stepperE2.setEnabled(STATE)
#define E2_ENABLE_READ stepperE2.isEnabled() #define E2_ENABLE_READ stepperE2.isEnabled()
#else #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_INIT SET_OUTPUT(E2_ENABLE_PIN)
#define E2_ENABLE_WRITE(STATE) WRITE(E2_ENABLE_PIN,STATE) #define E2_ENABLE_WRITE(STATE) WRITE(E2_ENABLE_PIN,STATE)
#define E2_ENABLE_READ READ(E2_ENABLE_PIN) #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_WRITE(STATE) stepperE3.Step_Clock(STATE)
#define E3_DIR_READ (stepperE3.getStatus() & STATUS_DIR) #define E3_DIR_READ (stepperE3.getStatus() & STATUS_DIR)
#else #else
#if AXIS_IS_TMC(E3)
extern TMC_CLASS(E3) stepperE3;
#endif
#if AXIS_DRIVER_TYPE(E3, TMC26X) #if AXIS_DRIVER_TYPE(E3, TMC26X)
extern TMC26XStepper stepperE3; extern TMC26XStepper stepperE3;
#define E3_ENABLE_INIT NOOP #define E3_ENABLE_INIT NOOP
#define E3_ENABLE_WRITE(STATE) stepperE3.setEnabled(STATE) #define E3_ENABLE_WRITE(STATE) stepperE3.setEnabled(STATE)
#define E3_ENABLE_READ stepperE3.isEnabled() #define E3_ENABLE_READ stepperE3.isEnabled()
#else #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_INIT SET_OUTPUT(E3_ENABLE_PIN)
#define E3_ENABLE_WRITE(STATE) WRITE(E3_ENABLE_PIN,STATE) #define E3_ENABLE_WRITE(STATE) WRITE(E3_ENABLE_PIN,STATE)
#define E3_ENABLE_READ READ(E3_ENABLE_PIN) #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_WRITE(STATE) stepperE4.Step_Clock(STATE)
#define E4_DIR_READ (stepperE4.getStatus() & STATUS_DIR) #define E4_DIR_READ (stepperE4.getStatus() & STATUS_DIR)
#else #else
#if AXIS_IS_TMC(E4)
extern TMC_CLASS(E4) stepperE4;
#endif
#if AXIS_DRIVER_TYPE(E4, TMC26X) #if AXIS_DRIVER_TYPE(E4, TMC26X)
extern TMC26XStepper stepperE4; extern TMC26XStepper stepperE4;
#define E4_ENABLE_INIT NOOP #define E4_ENABLE_INIT NOOP
#define E4_ENABLE_WRITE(STATE) stepperE4.setEnabled(STATE) #define E4_ENABLE_WRITE(STATE) stepperE4.setEnabled(STATE)
#define E4_ENABLE_READ stepperE4.isEnabled() #define E4_ENABLE_READ stepperE4.isEnabled()
#else #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_INIT SET_OUTPUT(E4_ENABLE_PIN)
#define E4_ENABLE_WRITE(STATE) WRITE(E4_ENABLE_PIN,STATE) #define E4_ENABLE_WRITE(STATE) WRITE(E4_ENABLE_PIN,STATE)
#define E4_ENABLE_READ READ(E4_ENABLE_PIN) #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_WRITE(STATE) stepperE5.Step_Clock(STATE)
#define E5_DIR_READ (stepperE5.getStatus() & STATUS_DIR) #define E5_DIR_READ (stepperE5.getStatus() & STATUS_DIR)
#else #else
#if AXIS_IS_TMC(E5)
extern TMC_CLASS(E5) stepperE5;
#endif
#if AXIS_DRIVER_TYPE(E5, TMC26X) #if AXIS_DRIVER_TYPE(E5, TMC26X)
extern TMC26XStepper stepperE5; extern TMC26XStepper stepperE5;
#define E5_ENABLE_INIT NOOP #define E5_ENABLE_INIT NOOP
#define E5_ENABLE_WRITE(STATE) stepperE5.setEnabled(STATE) #define E5_ENABLE_WRITE(STATE) stepperE5.setEnabled(STATE)
#define E5_ENABLE_READ stepperE5.isEnabled() #define E5_ENABLE_READ stepperE5.isEnabled()
#else #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_INIT SET_OUTPUT(E5_ENABLE_PIN)
#define E5_ENABLE_WRITE(STATE) WRITE(E5_ENABLE_PIN,STATE) #define E5_ENABLE_WRITE(STATE) WRITE(E5_ENABLE_PIN,STATE)
#define E5_ENABLE_READ READ(E5_ENABLE_PIN) #define E5_ENABLE_READ READ(E5_ENABLE_PIN)

View file

@ -31,8 +31,7 @@ build_flags = -fmax-errors=5
lib_deps = lib_deps =
https://github.com/MarlinFirmware/U8glib-HAL/archive/dev.zip https://github.com/MarlinFirmware/U8glib-HAL/archive/dev.zip
LiquidCrystal@1.3.4 LiquidCrystal@1.3.4
TMC2130Stepper https://github.com/teemuatlut/TMCStepper.git
https://github.com/teemuatlut/TMC2208Stepper/archive/v0.2.5.zip
Adafruit NeoPixel@1.1.3 Adafruit NeoPixel@1.1.3
https://github.com/lincomatic/LiquidTWI2/archive/30aa480.zip https://github.com/lincomatic/LiquidTWI2/archive/30aa480.zip
https://github.com/ameyer/Arduino-L6470/archive/master.zip https://github.com/ameyer/Arduino-L6470/archive/master.zip
@ -162,7 +161,7 @@ lib_ldf_mode = off
lib_extra_dirs = frameworks lib_extra_dirs = frameworks
lib_deps = CMSIS-LPC1768 lib_deps = CMSIS-LPC1768
https://github.com/MarlinFirmware/U8glib-HAL/archive/dev.zip 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 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} +<src/HAL/HAL_LPC1768> src_filter = ${common.default_src_filter} +<src/HAL/HAL_LPC1768>
monitor_speed = 250000 monitor_speed = 250000
@ -270,7 +269,7 @@ framework = arduino
board = disco_f407vg board = disco_f407vg
build_flags = ${common.build_flags} -DUSE_STM32GENERIC -DSTM32GENERIC -DMENU_USB_SERIAL -DMENU_SERIAL=SerialUSB build_flags = ${common.build_flags} -DUSE_STM32GENERIC -DSTM32GENERIC -DMENU_USB_SERIAL -DMENU_SERIAL=SerialUSB
lib_deps = ${common.lib_deps} lib_deps = ${common.lib_deps}
lib_ignore = Adafruit NeoPixel, c1921b4, TMC2130Stepper lib_ignore = Adafruit NeoPixel, c1921b4, TMCStepper
src_filter = ${common.default_src_filter} +<src/HAL/HAL_STM32F4> src_filter = ${common.default_src_filter} +<src/HAL/HAL_STM32F4>
monitor_speed = 250000 monitor_speed = 250000
@ -301,11 +300,10 @@ lib_ignore =
NewliquidCrystal NewliquidCrystal
LiquidTWI2 LiquidTWI2
Adafruit NeoPixel Adafruit NeoPixel
TMC2130Stepper TMCStepper
Servo(STM32F1) Servo(STM32F1)
TMC26XStepper TMC26XStepper
U8glib-HAL U8glib-HAL
TMC2208Stepper
c1921b4 c1921b4
# #