TMC_DEBUG optimization and improvements (#13135)

This commit is contained in:
LinFor 2019-02-20 11:22:42 +03:00 committed by Scott Lahteine
parent 1424b368cf
commit ba39186364
7 changed files with 240 additions and 122 deletions

View file

@ -36,7 +36,7 @@
#include "../module/planner.h" #include "../module/planner.h"
#include "../libs/hex_print_routines.h" #include "../libs/hex_print_routines.h"
#if ENABLED(MONITOR_DRIVER_STATUS) #if ENABLED(MONITOR_DRIVER_STATUS)
static bool report_tmc_status; // = false; static uint16_t report_tmc_status_interval; // = 0
#endif #endif
#endif #endif
@ -55,87 +55,159 @@
struct TMC_driver_data { struct TMC_driver_data {
uint32_t drv_status; uint32_t drv_status;
bool is_otpw, bool is_otpw:1,
is_ot, is_ot:1,
is_s2ga, is_s2g:1,
is_s2gb, is_error:1
is_error; #if ENABLED(TMC_DEBUG)
, is_stall:1
, is_stealth:1
, is_standstill:1
#if HAS_STALLGUARD
, sg_result_reasonable:1
#endif
#endif
;
#if ENABLED(TMC_DEBUG)
#if HAS_TMCX1X0 || HAS_DRIVER(TMC2208)
uint8_t cs_actual;
#endif
#if HAS_STALLGUARD
uint16_t sg_result;
#endif
#endif
}; };
#if HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160)
#if HAS_TMCX1X0
#if ENABLED(TMC_DEBUG) #if ENABLED(TMC_DEBUG)
static uint32_t get_pwm_scale(TMC2130Stepper &st) { return st.PWM_SCALE(); } static uint32_t get_pwm_scale(TMC2130Stepper &st) { return st.PWM_SCALE(); }
static uint8_t get_status_response(TMC2130Stepper &st, uint32_t) { return st.status_response & 0xF; }
#endif #endif
static TMC_driver_data get_driver_data(TMC2130Stepper &st) { static TMC_driver_data get_driver_data(TMC2130Stepper &st) {
constexpr uint32_t OTPW_bm = 0x4000000UL; constexpr uint16_t SG_RESULT_bm = 0x3FF; // 0:9
constexpr uint8_t OTPW_bp = 26; constexpr uint8_t STEALTH_bp = 14, CS_ACTUAL_sb = 16;
constexpr uint32_t OT_bm = 0x2000000UL; constexpr uint32_t CS_ACTUAL_bm = 0x1F0000; // 16:20
constexpr uint8_t OT_bp = 25; constexpr uint8_t STALL_GUARD_bp = 24, OT_bp = 25, OTPW_bp = 26;
constexpr uint8_t S2GA_bp = 27; constexpr uint32_t S2G_bm = 0x18000000;
constexpr uint8_t S2GB_bp = 28; constexpr uint8_t STST_bp = 31;
TMC_driver_data data; TMC_driver_data data;
data.drv_status = st.DRV_STATUS(); data.drv_status = st.DRV_STATUS();
data.is_otpw = (data.drv_status & OTPW_bm) >> OTPW_bp; #ifdef __AVR__
data.is_ot = (data.drv_status & OT_bm) >> OT_bp; // 8-bit optimization saves up to 70 bytes of PROGMEM per axis
data.is_s2ga = (data.drv_status >> S2GA_bp) & 0b1; uint8_t spart;
data.is_s2gb = (data.drv_status >> S2GB_bp) & 0b1; #if ENABLED(TMC_DEBUG)
data.sg_result = data.drv_status & SG_RESULT_bm;
spart = data.drv_status >> 8;
data.is_stealth = !!(spart & _BV(STEALTH_bp - 8));
spart = data.drv_status >> 16;
data.cs_actual = spart & (CS_ACTUAL_bm >> 16);
#endif
spart = data.drv_status >> 24;
data.is_ot = !!(spart & _BV(OT_bp - 24));
data.is_otpw = !!(spart & _BV(OTPW_bp - 24));
data.is_s2g = !!(spart & (S2G_bm >> 24));
#if ENABLED(TMC_DEBUG)
data.is_stall = !!(spart & _BV(STALL_GUARD_bp - 24));
data.is_standstill = !!(spart & _BV(STST_bp - 24));
data.sg_result_reasonable = !data.is_standstill; // sg_result has no reasonable meaning while standstill
#endif
#else // !__AVR__
data.is_ot = !!(data.drv_status & _BV(OT_bp));
data.is_otpw = !!(data.drv_status & _BV(OTPW_bp));
data.is_s2g = !!(data.drv_status & S2G_bm);
#if ENABLED(TMC_DEBUG)
data.sg_result = data.drv_status & SG_RESULT_bm;
data.is_stealth = !!(data.drv_status & _BV(STEALTH_bp));
data.cs_actual = (data.drv_status & CS_ACTUAL_bm) >> CS_ACTUAL_sb;
data.is_stall = !!(data.drv_status & _BV(STALL_GUARD_bp));
data.is_standstill = !!(data.drv_status & _BV(STST_bp));
data.sg_result_reasonable = !data.is_standstill; // sg_result has no reasonable meaning while standstill
#endif
#endif // !__AVR__
return data; return data;
} }
#endif
#endif // HAS_TMCX1X0
#if HAS_DRIVER(TMC2208) #if HAS_DRIVER(TMC2208)
#if ENABLED(TMC_DEBUG) #if ENABLED(TMC_DEBUG)
static uint32_t get_pwm_scale(TMC2208Stepper &st) { return st.pwm_scale_sum(); } static uint32_t get_pwm_scale(TMC2208Stepper &st) { return st.pwm_scale_sum(); }
static uint8_t get_status_response(TMC2208Stepper &st, uint32_t drv_status) {
uint8_t gstat = st.GSTAT();
uint8_t response = 0;
response |= (drv_status >> (31 - 3)) & 0b1000;
response |= gstat & 0b11;
return response;
}
#endif #endif
static TMC_driver_data get_driver_data(TMC2208Stepper &st) { static TMC_driver_data get_driver_data(TMC2208Stepper &st) {
constexpr uint32_t OTPW_bm = 0b1ul; constexpr uint8_t OTPW_bp = 0, OT_bp = 1;
constexpr uint8_t OTPW_bp = 0; constexpr uint8_t S2G_bm = 0b11110; // 2..5
constexpr uint32_t OT_bm = 0b10ul; constexpr uint8_t CS_ACTUAL_sb = 16;
constexpr uint8_t OT_bp = 1; constexpr uint32_t CS_ACTUAL_bm = 0x1F0000; // 16:20
constexpr uint8_t S2GA_bp = 2; constexpr uint8_t STEALTH_bp = 30, STST_bp = 31;
constexpr uint8_t S2GB_bp = 3;
TMC_driver_data data; TMC_driver_data data;
data.drv_status = st.DRV_STATUS(); data.drv_status = st.DRV_STATUS();
data.is_otpw = (data.drv_status & OTPW_bm) >> OTPW_bp; data.is_otpw = !!(data.drv_status & _BV(OTPW_bp));
data.is_ot = (data.drv_status & OT_bm) >> OT_bp; data.is_ot = !!(data.drv_status & _BV(OT_bp));
data.is_s2ga = (data.drv_status >> S2GA_bp) & 0b1; data.is_s2g = !!(data.drv_status & S2G_bm);
data.is_s2gb = (data.drv_status >> S2GB_bp) & 0b1; #if ENABLED(TMC_DEBUG)
#ifdef __AVR__
// 8-bit optimization saves up to 12 bytes of PROGMEM per axis
uint8_t spart = data.drv_status >> 16;
data.cs_actual = spart & (CS_ACTUAL_bm >> 16);
spart = data.drv_status >> 24;
data.is_stealth = !!(spart & _BV(STEALTH_bp - 24));
data.is_standstill = !!(spart & _BV(STST_bp - 24));
#else
data.cs_actual = (data.drv_status & CS_ACTUAL_bm) >> CS_ACTUAL_sb;
data.is_stealth = !!(data.drv_status & _BV(STEALTH_bp));
data.is_standstill = !!(data.drv_status & _BV(STST_bp));
#endif
#if HAS_STALLGUARD
data.sg_result_reasonable = false;
#endif
#endif
return data; return data;
} }
#endif
#endif // TMC2208
#if HAS_DRIVER(TMC2660) #if HAS_DRIVER(TMC2660)
#if ENABLED(TMC_DEBUG) #if ENABLED(TMC_DEBUG)
static uint32_t get_pwm_scale(TMC2660Stepper) { return 0; } static uint32_t get_pwm_scale(TMC2660Stepper) { return 0; }
static uint8_t get_status_response(TMC2660Stepper, uint32_t drv_status) {
return drv_status & 0xFF;
}
#endif #endif
static TMC_driver_data get_driver_data(TMC2660Stepper &st) { static TMC_driver_data get_driver_data(TMC2660Stepper &st) {
constexpr uint32_t OTPW_bm = 0x4UL; constexpr uint8_t STALL_GUARD_bp = 0;
constexpr uint8_t OTPW_bp = 2; constexpr uint8_t OT_bp = 1, OTPW_bp = 2;
constexpr uint32_t OT_bm = 0x2UL; constexpr uint8_t S2G_bm = 0b11000;
constexpr uint8_t OT_bp = 1; constexpr uint8_t STST_bp = 7, SG_RESULT_sp = 10;
constexpr uint32_t SG_RESULT_bm = 0xFFC00; // 10:19
TMC_driver_data data; TMC_driver_data data;
data.drv_status = st.DRVSTATUS(); data.drv_status = st.DRVSTATUS();
data.is_otpw = (data.drv_status & OTPW_bm) >> OTPW_bp; uint8_t spart = data.drv_status & 0xFF;
data.is_ot = (data.drv_status & OT_bm) >> OT_bp; data.is_otpw = !!(spart & _BV(OTPW_bp));
data.is_ot = !!(spart & _BV(OT_bp));
data.is_s2g = !!(data.drv_status & S2G_bm);
#if ENABLED(TMC_DEBUG)
data.is_stall = !!(spart & _BV(STALL_GUARD_bp));
data.is_standstill = !!(spart & _BV(STST_bp));
data.sg_result = (data.drv_status & SG_RESULT_bm) >> SG_RESULT_sp;
data.sg_result_reasonable = true;
#endif
return data; return data;
} }
#endif
#endif // TMC2660
#if ENABLED(STOP_ON_ERROR) #if ENABLED(STOP_ON_ERROR)
void report_driver_error(const TMC_driver_data &data) { void report_driver_error(const TMC_driver_data &data) {
SERIAL_ECHOPGM(" driver error detected: 0x"); SERIAL_ECHOPGM(" driver error detected: 0x");
SERIAL_PRINTLN(data.drv_status, HEX); SERIAL_PRINTLN(data.drv_status, HEX);
if (data.is_ot) SERIAL_ECHOLNPGM("overtemperature"); if (data.is_ot) SERIAL_ECHOLNPGM("overtemperature");
if (data.is_s2ga) SERIAL_ECHOLNPGM("short to ground (coil A)"); if (data.is_s2g) SERIAL_ECHOLNPGM("coil short circuit");
if (data.is_s2gb) SERIAL_ECHOLNPGM("short to ground (coil B)");
#if ENABLED(TMC_DEBUG) #if ENABLED(TMC_DEBUG)
tmc_report_all(true, true, true, true); tmc_report_all(true, true, true, true);
#endif #endif
@ -162,61 +234,79 @@
void report_polled_driver_data(TMC &st, const TMC_driver_data &data) { void report_polled_driver_data(TMC &st, const TMC_driver_data &data) {
const uint32_t pwm_scale = get_pwm_scale(st); const uint32_t pwm_scale = get_pwm_scale(st);
st.printLabel(); st.printLabel();
SERIAL_ECHOPAIR(":", pwm_scale); SERIAL_CHAR(':'); SERIAL_PRINT(pwm_scale, DEC);
SERIAL_ECHOPGM(" |0b"); SERIAL_PRINT(get_status_response(st, data.drv_status), BIN); #if ENABLED(TMC_DEBUG)
SERIAL_ECHOPGM("| "); #if HAS_TMCX1X0 || HAS_DRIVER(TMC2208)
if (st.error_count) SERIAL_CHAR('E'); SERIAL_CHAR('/'); SERIAL_PRINT(data.cs_actual, DEC);
else if (data.is_ot) SERIAL_CHAR('O'); #endif
else if (data.is_otpw) SERIAL_CHAR('W'); #if HAS_STALLGUARD
else if (st.otpw_count > 0) SERIAL_PRINT(st.otpw_count, DEC); SERIAL_CHAR('/');
else if (st.flag_otpw) SERIAL_CHAR('F'); if (data.sg_result_reasonable)
SERIAL_ECHO(data.sg_result);
else
SERIAL_CHAR('-');
#endif
#endif
SERIAL_CHAR('|');
if (st.error_count) SERIAL_CHAR('E'); // Error
if (data.is_ot) SERIAL_CHAR('O'); // Over-temperature
if (data.is_otpw) SERIAL_CHAR('W'); // over-temperature pre-Warning
#if ENABLED(TMC_DEBUG)
if (data.is_stall) SERIAL_CHAR('G'); // stallGuard
if (data.is_stealth) SERIAL_CHAR('T'); // stealthChop
if (data.is_standstill) SERIAL_CHAR('I'); // standstIll
#endif
if (st.flag_otpw) SERIAL_CHAR('F'); // otpw Flag
SERIAL_CHAR('|');
if (st.otpw_count > 0) SERIAL_PRINT(st.otpw_count, DEC);
SERIAL_CHAR('\t'); SERIAL_CHAR('\t');
} }
template<typename TMC> template<typename TMC>
void monitor_tmc_driver(TMC &st) { void monitor_tmc_driver(TMC &st, const bool need_update_error_counters, const bool need_debug_reporting) {
TMC_driver_data data = get_driver_data(st); TMC_driver_data data = get_driver_data(st);
if ((data.drv_status == 0xFFFFFFFF) || (data.drv_status == 0x0)) return; if (data.drv_status == 0xFFFFFFFF || data.drv_status == 0x0) return;
if (data.is_ot /* | data.s2ga | data.s2gb*/) st.error_count++; if (need_update_error_counters) {
else if (st.error_count > 0) st.error_count--; if (data.is_ot /* | data.s2ga | data.s2gb*/) st.error_count++;
else if (st.error_count > 0) st.error_count--;
#if ENABLED(STOP_ON_ERROR) #if ENABLED(STOP_ON_ERROR)
if (st.error_count >= 10) { if (st.error_count >= 10) {
SERIAL_EOL(); SERIAL_EOL();
st.printLabel(); st.printLabel();
report_driver_error(data); report_driver_error(data);
}
#endif
// Report if a warning was triggered
if (data.is_otpw && st.otpw_count == 0) {
report_driver_otpw(st);
}
#if CURRENT_STEP_DOWN > 0
// Decrease current if is_otpw is true and driver is enabled and there's been more than 4 warnings
if (data.is_otpw && st.otpw_count > 4) {
uint16_t I_rms = st.getMilliamps();
if (st.isEnabled() && I_rms > 100) {
st.rms_current(I_rms - (CURRENT_STEP_DOWN));
#if ENABLED(REPORT_CURRENT_CHANGE)
st.printLabel();
SERIAL_ECHOLNPAIR(" current decreased to ", st.getMilliamps());
#endif
} }
} #endif
#endif
if (data.is_otpw) { // Report if a warning was triggered
st.otpw_count++; if (data.is_otpw && st.otpw_count == 0)
st.flag_otpw = true; report_driver_otpw(st);
#if CURRENT_STEP_DOWN > 0
// Decrease current if is_otpw is true and driver is enabled and there's been more than 4 warnings
if (data.is_otpw && st.otpw_count > 4) {
uint16_t I_rms = st.getMilliamps();
if (st.isEnabled() && I_rms > 100) {
st.rms_current(I_rms - (CURRENT_STEP_DOWN));
#if ENABLED(REPORT_CURRENT_CHANGE)
st.printLabel();
SERIAL_ECHOLNPAIR(" current decreased to ", st.getMilliamps());
#endif
}
}
#endif
if (data.is_otpw) {
st.otpw_count++;
st.flag_otpw = true;
}
else if (st.otpw_count > 0) st.otpw_count = 0;
} }
else if (st.otpw_count > 0) st.otpw_count = 0;
#if ENABLED(TMC_DEBUG) #if ENABLED(TMC_DEBUG)
if (report_tmc_status) { if (need_debug_reporting)
report_polled_driver_data(st, data); report_polled_driver_data(st, data);
}
#endif #endif
} }
@ -225,50 +315,60 @@
void monitor_tmc_driver() { void monitor_tmc_driver() {
static millis_t next_poll = 0; static millis_t next_poll = 0;
const millis_t ms = millis(); const millis_t ms = millis();
if (ELAPSED(ms, next_poll)) { bool need_update_error_counters = ELAPSED(ms, next_poll);
next_poll = ms + 500; bool need_debug_reporting = false;
if (need_update_error_counters)
next_poll = ms + MONITOR_DRIVER_STATUS_INTERVAL_MS;
#if ENABLED(TMC_DEBUG)
static millis_t next_debug_reporting = 0;
if (report_tmc_status_interval && ELAPSED(ms, next_debug_reporting)) {
need_debug_reporting = true;
next_debug_reporting = ms + report_tmc_status_interval;
}
#endif
if (need_update_error_counters || need_debug_reporting) {
#if HAS_HW_COMMS(X) #if HAS_HW_COMMS(X)
monitor_tmc_driver(stepperX); monitor_tmc_driver(stepperX, need_update_error_counters, need_debug_reporting);
#endif #endif
#if HAS_HW_COMMS(Y) #if HAS_HW_COMMS(Y)
monitor_tmc_driver(stepperY); monitor_tmc_driver(stepperY, need_update_error_counters, need_debug_reporting);
#endif #endif
#if HAS_HW_COMMS(Z) #if HAS_HW_COMMS(Z)
monitor_tmc_driver(stepperZ); monitor_tmc_driver(stepperZ, need_update_error_counters, need_debug_reporting);
#endif #endif
#if HAS_HW_COMMS(X2) #if HAS_HW_COMMS(X2)
monitor_tmc_driver(stepperX2); monitor_tmc_driver(stepperX2, need_update_error_counters, need_debug_reporting);
#endif #endif
#if HAS_HW_COMMS(Y2) #if HAS_HW_COMMS(Y2)
monitor_tmc_driver(stepperY2); monitor_tmc_driver(stepperY2, need_update_error_counters, need_debug_reporting);
#endif #endif
#if HAS_HW_COMMS(Z2) #if HAS_HW_COMMS(Z2)
monitor_tmc_driver(stepperZ2); monitor_tmc_driver(stepperZ2, need_update_error_counters, need_debug_reporting);
#endif #endif
#if HAS_HW_COMMS(Z3) #if HAS_HW_COMMS(Z3)
monitor_tmc_driver(stepperZ3); monitor_tmc_driver(stepperZ3, need_update_error_counters, need_debug_reporting);
#endif #endif
#if HAS_HW_COMMS(E0) #if HAS_HW_COMMS(E0)
monitor_tmc_driver(stepperE0); monitor_tmc_driver(stepperE0, need_update_error_counters, need_debug_reporting);
#endif #endif
#if HAS_HW_COMMS(E1) #if HAS_HW_COMMS(E1)
monitor_tmc_driver(stepperE1); monitor_tmc_driver(stepperE1, need_update_error_counters, need_debug_reporting);
#endif #endif
#if HAS_HW_COMMS(E2) #if HAS_HW_COMMS(E2)
monitor_tmc_driver(stepperE2); monitor_tmc_driver(stepperE2, need_update_error_counters, need_debug_reporting);
#endif #endif
#if HAS_HW_COMMS(E3) #if HAS_HW_COMMS(E3)
monitor_tmc_driver(stepperE3); monitor_tmc_driver(stepperE3, need_update_error_counters, need_debug_reporting);
#endif #endif
#if HAS_HW_COMMS(E4) #if HAS_HW_COMMS(E4)
monitor_tmc_driver(stepperE4); monitor_tmc_driver(stepperE4, need_update_error_counters, need_debug_reporting);
#endif #endif
#if HAS_HW_COMMS(E5) #if HAS_HW_COMMS(E5)
monitor_tmc_driver(stepperE5); monitor_tmc_driver(stepperE5, need_update_error_counters, need_debug_reporting);
#endif #endif
#if ENABLED(TMC_DEBUG) #if ENABLED(TMC_DEBUG)
if (report_tmc_status) SERIAL_EOL(); if (need_debug_reporting) SERIAL_EOL();
#endif #endif
} }
} }
@ -278,12 +378,20 @@
#if ENABLED(TMC_DEBUG) #if ENABLED(TMC_DEBUG)
/** /**
* M122 S[1,0] Enable periodic status reports * M122 [S<0|1>] [Pnnn] Enable periodic status reports
*/ */
#if ENABLED(MONITOR_DRIVER_STATUS) #if ENABLED(MONITOR_DRIVER_STATUS)
void tmc_set_report_status(const bool status) { void tmc_set_report_interval(const uint16_t update_interval) {
if ((report_tmc_status = status)) if ((report_tmc_status_interval = update_interval))
SERIAL_ECHOLNPGM("axis:pwm_scale |status_response|"); SERIAL_ECHOLNPGM("axis:pwm_scale"
#if HAS_STEALTHCHOP
"/current_scale"
#endif
#if HAS_STALLGUARD
"/mech_load"
#endif
"|flags|warncount"
);
} }
#endif #endif
@ -360,7 +468,7 @@
template<class TMC> template<class TMC>
static void print_vsense(TMC &st) { serialprintPGM(st.vsense() ? PSTR("1=.18") : PSTR("0=.325")); } static void print_vsense(TMC &st) { serialprintPGM(st.vsense() ? PSTR("1=.18") : PSTR("0=.325")); }
#if HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160) #if HAS_TMCX1X0
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;
@ -702,7 +810,7 @@
TMC_REPORT("Stallguard thrs", TMC_SGT); TMC_REPORT("Stallguard thrs", TMC_SGT);
DRV_REPORT("DRVSTATUS", TMC_DRV_CODES); DRV_REPORT("DRVSTATUS", TMC_DRV_CODES);
#if HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160) #if HAS_TMCX1X0
DRV_REPORT("stallguard\t", TMC_STALLGUARD); DRV_REPORT("stallguard\t", TMC_STALLGUARD);
DRV_REPORT("sg_result\t", TMC_SG_RESULT); DRV_REPORT("sg_result\t", TMC_SG_RESULT);
DRV_REPORT("fsactive\t", TMC_FSACTIVE); DRV_REPORT("fsactive\t", TMC_FSACTIVE);
@ -728,7 +836,7 @@
#define PRINT_TMC_REGISTER(REG_CASE) case TMC_GET_##REG_CASE: print_hex_long(st.REG_CASE(), ':'); break #define PRINT_TMC_REGISTER(REG_CASE) case TMC_GET_##REG_CASE: print_hex_long(st.REG_CASE(), ':'); break
#if HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160) #if HAS_TMCX1X0
static void tmc_get_ic_registers(TMC2130Stepper &st, const TMC_get_registers_enum i) { static void tmc_get_ic_registers(TMC2130Stepper &st, const TMC_get_registers_enum i) {
switch (i) { switch (i) {
PRINT_TMC_REGISTER(TCOOLTHRS); PRINT_TMC_REGISTER(TCOOLTHRS);

View file

@ -53,6 +53,10 @@
#define CHOPPER_PRUSAMK3_24V { 4, 1, 4 } #define CHOPPER_PRUSAMK3_24V { 4, 1, 4 }
#define CHOPPER_MARLIN_119 { 5, 2, 3 } #define CHOPPER_MARLIN_119 { 5, 2, 3 }
#if ENABLED(MONITOR_DRIVER_STATUS) && !defined(MONITOR_DRIVER_STATUS_INTERVAL_MS)
#define MONITOR_DRIVER_STATUS_INTERVAL_MS 500u
#endif
constexpr uint16_t _tmc_thrs(const uint16_t msteps, const int32_t thrs, const uint32_t spmm) { constexpr uint16_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);
} }
@ -258,7 +262,7 @@ void test_tmc_connection(const bool test_x, const bool test_y, const bool test_z
#if ENABLED(TMC_DEBUG) #if ENABLED(TMC_DEBUG)
#if ENABLED(MONITOR_DRIVER_STATUS) #if ENABLED(MONITOR_DRIVER_STATUS)
void tmc_set_report_status(const bool status); void tmc_set_report_interval(const uint16_t update_interval);
#endif #endif
void tmc_report_all(const bool print_x, const bool print_y, const bool print_z, const bool print_e); void tmc_report_all(const bool print_x, const bool print_y, const bool print_z, const bool print_e);
void tmc_get_registers(const bool print_x, const bool print_y, const bool print_z, const bool print_e); void tmc_get_registers(const bool print_x, const bool print_y, const bool print_z, const bool print_e);

View file

@ -65,7 +65,7 @@ void GcodeSuite::M122() {
#define L6470_SAY_STATUS(Q) L6470_status_decode(stepper##Q.getStatus(), Q) #define L6470_SAY_STATUS(Q) L6470_status_decode(stepper##Q.getStatus(), Q)
//if (parser.seen('S')) //if (parser.seen('S'))
// tmc_set_report_status(parser.value_bool()); // tmc_set_report_interval(parser.value_bool());
//else //else
#if AXIS_DRIVER_TYPE_X(L6470) #if AXIS_DRIVER_TYPE_X(L6470)

View file

@ -39,8 +39,9 @@ void GcodeSuite::M122() {
#if ENABLED(TMC_DEBUG) #if ENABLED(TMC_DEBUG)
#if ENABLED(MONITOR_DRIVER_STATUS) #if ENABLED(MONITOR_DRIVER_STATUS)
if (parser.seen('S')) const bool sflag = parser.seen('S'), s0 = sflag && !parser.value_bool();
tmc_set_report_status(parser.value_bool()); if (sflag) tmc_set_report_interval(s0 ? 0 : MONITOR_DRIVER_STATUS_INTERVAL_MS);
if (!s0 && parser.seenval('P')) tmc_set_report_interval(MIN(parser.value_ushort(), MONITOR_DRIVER_STATUS_INTERVAL_MS));
#endif #endif
if (parser.seen('V')) if (parser.seen('V'))

View file

@ -662,7 +662,7 @@ void GcodeSuite::process_parsed_command(
#endif #endif
#if HAS_TRINAMIC #if HAS_TRINAMIC
case 122: M122(); break; case 122: M122(); break; // M122: Report driver configuration and status
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 HAS_STEALTHCHOP #if HAS_STEALTHCHOP
case 569: M569(); break; // M569: Enable stealthChop on an axis. case 569: M569(); break; // M569: Enable stealthChop on an axis.

View file

@ -853,9 +853,10 @@
// Trinamic Stepper Drivers // Trinamic Stepper Drivers
#if HAS_TRINAMIC #if HAS_TRINAMIC
#define TMC_HAS_SPI (HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC2660) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160)) #define HAS_TMCX1X0 (HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160))
#define HAS_STALLGUARD (HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC2660) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160)) #define TMC_HAS_SPI (HAS_TMCX1X0 || HAS_DRIVER(TMC2660))
#define HAS_STEALTHCHOP (HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC2208) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160)) #define HAS_STALLGUARD (HAS_TMCX1X0 || HAS_DRIVER(TMC2660))
#define HAS_STEALTHCHOP (HAS_TMCX1X0 || HAS_DRIVER(TMC2208))
#define AXIS_HAS_SPI(ST) (AXIS_DRIVER_TYPE(ST, TMC2130) || AXIS_DRIVER_TYPE(ST, TMC2160) || AXIS_DRIVER_TYPE(ST, TMC2660)) #define AXIS_HAS_SPI(ST) (AXIS_DRIVER_TYPE(ST, TMC2130) || AXIS_DRIVER_TYPE(ST, TMC2160) || AXIS_DRIVER_TYPE(ST, TMC2660))
#define AXIS_HAS_STALLGUARD(ST) (AXIS_DRIVER_TYPE(ST, TMC2130) || AXIS_DRIVER_TYPE(ST, TMC2160) || AXIS_DRIVER_TYPE(ST, TMC2660) || AXIS_DRIVER_TYPE(ST, TMC5130) || AXIS_DRIVER_TYPE(ST, TMC5160)) #define AXIS_HAS_STALLGUARD(ST) (AXIS_DRIVER_TYPE(ST, TMC2130) || AXIS_DRIVER_TYPE(ST, TMC2160) || AXIS_DRIVER_TYPE(ST, TMC2660) || AXIS_DRIVER_TYPE(ST, TMC5130) || AXIS_DRIVER_TYPE(ST, TMC5160))
#define AXIS_HAS_STEALTHCHOP(ST) (AXIS_DRIVER_TYPE(ST, TMC2130) || AXIS_DRIVER_TYPE(ST, TMC2160) || AXIS_DRIVER_TYPE(ST, TMC2208) || AXIS_DRIVER_TYPE(ST, TMC5130) || AXIS_DRIVER_TYPE(ST, TMC5160)) #define AXIS_HAS_STEALTHCHOP(ST) (AXIS_DRIVER_TYPE(ST, TMC2130) || AXIS_DRIVER_TYPE(ST, TMC2160) || AXIS_DRIVER_TYPE(ST, TMC2208) || AXIS_DRIVER_TYPE(ST, TMC5130) || AXIS_DRIVER_TYPE(ST, TMC5160))

View file

@ -662,6 +662,10 @@
st.microsteps(microsteps); st.microsteps(microsteps);
st.intpol(INTERPOLATE); st.intpol(INTERPOLATE);
st.diss2g(true); // Disable short to ground protection. Too many false readings? st.diss2g(true); // Disable short to ground protection. Too many false readings?
#if ENABLED(TMC_DEBUG)
st.rdsel(0b01);
#endif
} }
#endif // TMC2660 #endif // TMC2660