2017-12-15 22:03:14 +01:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-12-15 22:03:14 +01:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-12-15 22:03:14 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#if HAS_TRINAMIC
|
|
|
|
|
|
|
|
#include "tmc_util.h"
|
|
|
|
#include "../Marlin.h"
|
|
|
|
|
2019-09-01 02:44:45 +02:00
|
|
|
#include "../module/stepper/indirection.h"
|
2017-12-15 22:03:14 +01:00
|
|
|
#include "../module/printcounter.h"
|
|
|
|
#include "../libs/duration_t.h"
|
|
|
|
#include "../gcode/gcode.h"
|
|
|
|
|
2018-01-10 02:14:07 +01:00
|
|
|
#if ENABLED(TMC_DEBUG)
|
|
|
|
#include "../module/planner.h"
|
2018-12-10 03:54:48 +01:00
|
|
|
#include "../libs/hex_print_routines.h"
|
|
|
|
#if ENABLED(MONITOR_DRIVER_STATUS)
|
2019-02-20 09:22:42 +01:00
|
|
|
static uint16_t report_tmc_status_interval; // = 0
|
2018-12-10 03:54:48 +01:00
|
|
|
#endif
|
2018-01-10 02:14:07 +01:00
|
|
|
#endif
|
|
|
|
|
2019-01-17 20:17:16 +01:00
|
|
|
#if HAS_LCD_MENU
|
|
|
|
#include "../module/stepper.h"
|
|
|
|
#endif
|
|
|
|
|
2018-03-07 02:01:07 +01:00
|
|
|
/**
|
2017-12-15 22:03:14 +01:00
|
|
|
* Check for over temperature or short to ground error flags.
|
|
|
|
* Report and log warning of overtemperature condition.
|
|
|
|
* Reduce driver current in a persistent otpw condition.
|
|
|
|
* Keep track of otpw counter so we don't reduce current on a single instance,
|
|
|
|
* and so we don't repeatedly report warning before the condition is cleared.
|
|
|
|
*/
|
|
|
|
#if ENABLED(MONITOR_DRIVER_STATUS)
|
2018-10-03 09:48:49 +02:00
|
|
|
|
2017-12-15 22:03:14 +01:00
|
|
|
struct TMC_driver_data {
|
|
|
|
uint32_t drv_status;
|
2019-02-20 09:22:42 +01:00
|
|
|
bool is_otpw:1,
|
|
|
|
is_ot:1,
|
|
|
|
is_s2g:1,
|
|
|
|
is_error:1
|
|
|
|
#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)
|
2019-07-09 05:59:51 +02:00
|
|
|
#if HAS_TMCX1X0 || HAS_TMC220x
|
2019-02-20 09:22:42 +01:00
|
|
|
uint8_t cs_actual;
|
|
|
|
#endif
|
|
|
|
#if HAS_STALLGUARD
|
|
|
|
uint16_t sg_result;
|
|
|
|
#endif
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
};
|
2019-02-20 09:22:42 +01:00
|
|
|
|
|
|
|
#if HAS_TMCX1X0
|
|
|
|
|
2018-10-07 00:18:10 +02:00
|
|
|
#if ENABLED(TMC_DEBUG)
|
|
|
|
static uint32_t get_pwm_scale(TMC2130Stepper &st) { return st.PWM_SCALE(); }
|
|
|
|
#endif
|
2019-02-20 09:22:42 +01:00
|
|
|
|
2017-12-15 22:03:14 +01:00
|
|
|
static TMC_driver_data get_driver_data(TMC2130Stepper &st) {
|
2019-05-06 05:04:47 +02:00
|
|
|
constexpr uint8_t OT_bp = 25, OTPW_bp = 26;
|
2019-02-20 09:22:42 +01:00
|
|
|
constexpr uint32_t S2G_bm = 0x18000000;
|
2019-05-06 05:04:47 +02:00
|
|
|
#if ENABLED(TMC_DEBUG)
|
|
|
|
constexpr uint16_t SG_RESULT_bm = 0x3FF; // 0:9
|
|
|
|
constexpr uint8_t STEALTH_bp = 14;
|
|
|
|
constexpr uint32_t CS_ACTUAL_bm = 0x1F0000; // 16:20
|
|
|
|
constexpr uint8_t STALL_GUARD_bp = 24;
|
|
|
|
constexpr uint8_t STST_bp = 31;
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
TMC_driver_data data;
|
2019-06-13 03:17:01 +02:00
|
|
|
const auto ds = data.drv_status = st.DRV_STATUS();
|
2019-02-20 09:22:42 +01:00
|
|
|
#ifdef __AVR__
|
2019-06-20 22:47:50 +02:00
|
|
|
|
2019-02-20 09:22:42 +01:00
|
|
|
// 8-bit optimization saves up to 70 bytes of PROGMEM per axis
|
|
|
|
uint8_t spart;
|
|
|
|
#if ENABLED(TMC_DEBUG)
|
2019-06-13 03:17:01 +02:00
|
|
|
data.sg_result = ds & SG_RESULT_bm;
|
|
|
|
spart = ds >> 8;
|
|
|
|
data.is_stealth = TEST(spart, STEALTH_bp - 8);
|
|
|
|
spart = ds >> 16;
|
2019-02-20 09:22:42 +01:00
|
|
|
data.cs_actual = spart & (CS_ACTUAL_bm >> 16);
|
|
|
|
#endif
|
2019-06-13 03:17:01 +02:00
|
|
|
spart = ds >> 24;
|
|
|
|
data.is_ot = TEST(spart, OT_bp - 24);
|
|
|
|
data.is_otpw = TEST(spart, OTPW_bp - 24);
|
2019-02-20 09:22:42 +01:00
|
|
|
data.is_s2g = !!(spart & (S2G_bm >> 24));
|
|
|
|
#if ENABLED(TMC_DEBUG)
|
2019-06-13 03:17:01 +02:00
|
|
|
data.is_stall = TEST(spart, STALL_GUARD_bp - 24);
|
|
|
|
data.is_standstill = TEST(spart, STST_bp - 24);
|
2019-02-20 09:22:42 +01:00
|
|
|
data.sg_result_reasonable = !data.is_standstill; // sg_result has no reasonable meaning while standstill
|
|
|
|
#endif
|
2019-06-20 22:47:50 +02:00
|
|
|
|
2019-02-20 09:22:42 +01:00
|
|
|
#else // !__AVR__
|
|
|
|
|
2019-06-13 03:17:01 +02:00
|
|
|
data.is_ot = TEST(ds, OT_bp);
|
|
|
|
data.is_otpw = TEST(ds, OTPW_bp);
|
|
|
|
data.is_s2g = !!(ds & S2G_bm);
|
2019-02-20 09:22:42 +01:00
|
|
|
#if ENABLED(TMC_DEBUG)
|
2019-05-06 05:04:47 +02:00
|
|
|
constexpr uint8_t CS_ACTUAL_sb = 16;
|
2019-06-13 03:17:01 +02:00
|
|
|
data.sg_result = ds & SG_RESULT_bm;
|
|
|
|
data.is_stealth = TEST(ds, STEALTH_bp);
|
|
|
|
data.cs_actual = (ds & CS_ACTUAL_bm) >> CS_ACTUAL_sb;
|
|
|
|
data.is_stall = TEST(ds, STALL_GUARD_bp);
|
|
|
|
data.is_standstill = TEST(ds, STST_bp);
|
2019-02-20 09:22:42 +01:00
|
|
|
data.sg_result_reasonable = !data.is_standstill; // sg_result has no reasonable meaning while standstill
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // !__AVR__
|
|
|
|
|
2017-12-15 22:03:14 +01:00
|
|
|
return data;
|
|
|
|
}
|
2019-02-20 09:22:42 +01:00
|
|
|
|
|
|
|
#endif // HAS_TMCX1X0
|
|
|
|
|
2019-07-09 05:59:51 +02:00
|
|
|
#if HAS_TMC220x
|
2019-02-20 09:22:42 +01:00
|
|
|
|
2018-10-07 00:18:10 +02:00
|
|
|
#if ENABLED(TMC_DEBUG)
|
|
|
|
static uint32_t get_pwm_scale(TMC2208Stepper &st) { return st.pwm_scale_sum(); }
|
|
|
|
#endif
|
2019-02-20 09:22:42 +01:00
|
|
|
|
2017-12-15 22:03:14 +01:00
|
|
|
static TMC_driver_data get_driver_data(TMC2208Stepper &st) {
|
2019-02-20 09:22:42 +01:00
|
|
|
constexpr uint8_t OTPW_bp = 0, OT_bp = 1;
|
|
|
|
constexpr uint8_t S2G_bm = 0b11110; // 2..5
|
2017-12-15 22:03:14 +01:00
|
|
|
TMC_driver_data data;
|
2019-06-13 03:17:01 +02:00
|
|
|
const auto ds = data.drv_status = st.DRV_STATUS();
|
|
|
|
data.is_otpw = TEST(ds, OTPW_bp);
|
|
|
|
data.is_ot = TEST(ds, OT_bp);
|
|
|
|
data.is_s2g = !!(ds & S2G_bm);
|
2019-02-20 09:22:42 +01:00
|
|
|
#if ENABLED(TMC_DEBUG)
|
2019-05-06 05:04:47 +02:00
|
|
|
constexpr uint32_t CS_ACTUAL_bm = 0x1F0000; // 16:20
|
|
|
|
constexpr uint8_t STEALTH_bp = 30, STST_bp = 31;
|
2019-02-20 09:22:42 +01:00
|
|
|
#ifdef __AVR__
|
|
|
|
// 8-bit optimization saves up to 12 bytes of PROGMEM per axis
|
2019-06-13 03:17:01 +02:00
|
|
|
uint8_t spart = ds >> 16;
|
2019-02-20 09:22:42 +01:00
|
|
|
data.cs_actual = spart & (CS_ACTUAL_bm >> 16);
|
2019-06-13 03:17:01 +02:00
|
|
|
spart = ds >> 24;
|
|
|
|
data.is_stealth = TEST(spart, STEALTH_bp - 24);
|
|
|
|
data.is_standstill = TEST(spart, STST_bp - 24);
|
2019-02-20 09:22:42 +01:00
|
|
|
#else
|
2019-05-06 05:04:47 +02:00
|
|
|
constexpr uint8_t CS_ACTUAL_sb = 16;
|
2019-06-13 03:17:01 +02:00
|
|
|
data.cs_actual = (ds & CS_ACTUAL_bm) >> CS_ACTUAL_sb;
|
|
|
|
data.is_stealth = TEST(ds, STEALTH_bp);
|
|
|
|
data.is_standstill = TEST(ds, STST_bp);
|
2019-02-20 09:22:42 +01:00
|
|
|
#endif
|
|
|
|
#if HAS_STALLGUARD
|
|
|
|
data.sg_result_reasonable = false;
|
|
|
|
#endif
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
return data;
|
|
|
|
}
|
2019-02-20 09:22:42 +01:00
|
|
|
|
2019-06-20 22:47:50 +02:00
|
|
|
#endif // TMC2208 || TMC2209
|
2019-02-20 09:22:42 +01:00
|
|
|
|
2018-10-07 00:18:10 +02:00
|
|
|
#if HAS_DRIVER(TMC2660)
|
2019-02-20 09:22:42 +01:00
|
|
|
|
2018-10-07 00:18:10 +02:00
|
|
|
#if ENABLED(TMC_DEBUG)
|
|
|
|
static uint32_t get_pwm_scale(TMC2660Stepper) { return 0; }
|
|
|
|
#endif
|
2019-02-20 09:22:42 +01:00
|
|
|
|
2018-10-07 00:18:10 +02:00
|
|
|
static TMC_driver_data get_driver_data(TMC2660Stepper &st) {
|
2019-02-20 09:22:42 +01:00
|
|
|
constexpr uint8_t OT_bp = 1, OTPW_bp = 2;
|
|
|
|
constexpr uint8_t S2G_bm = 0b11000;
|
2018-10-07 00:18:10 +02:00
|
|
|
TMC_driver_data data;
|
2019-06-13 03:17:01 +02:00
|
|
|
const auto ds = data.drv_status = st.DRVSTATUS();
|
|
|
|
uint8_t spart = ds & 0xFF;
|
|
|
|
data.is_otpw = TEST(spart, OTPW_bp);
|
|
|
|
data.is_ot = TEST(spart, OT_bp);
|
|
|
|
data.is_s2g = !!(ds & S2G_bm);
|
2019-02-20 09:22:42 +01:00
|
|
|
#if ENABLED(TMC_DEBUG)
|
2019-05-06 05:04:47 +02:00
|
|
|
constexpr uint8_t STALL_GUARD_bp = 0;
|
|
|
|
constexpr uint8_t STST_bp = 7, SG_RESULT_sp = 10;
|
|
|
|
constexpr uint32_t SG_RESULT_bm = 0xFFC00; // 10:19
|
2019-06-13 03:17:01 +02:00
|
|
|
data.is_stall = TEST(spart, STALL_GUARD_bp);
|
|
|
|
data.is_standstill = TEST(spart, STST_bp);
|
|
|
|
data.sg_result = (ds & SG_RESULT_bm) >> SG_RESULT_sp;
|
2019-02-20 09:22:42 +01:00
|
|
|
data.sg_result_reasonable = true;
|
|
|
|
#endif
|
2018-10-07 00:18:10 +02:00
|
|
|
return data;
|
|
|
|
}
|
2019-02-20 09:22:42 +01:00
|
|
|
|
|
|
|
#endif // TMC2660
|
2017-12-15 22:03:14 +01:00
|
|
|
|
2018-12-07 22:34:21 +01:00
|
|
|
#if ENABLED(STOP_ON_ERROR)
|
|
|
|
void report_driver_error(const TMC_driver_data &data) {
|
|
|
|
SERIAL_ECHOPGM(" driver error detected: 0x");
|
|
|
|
SERIAL_PRINTLN(data.drv_status, HEX);
|
|
|
|
if (data.is_ot) SERIAL_ECHOLNPGM("overtemperature");
|
2019-02-20 09:22:42 +01:00
|
|
|
if (data.is_s2g) SERIAL_ECHOLNPGM("coil short circuit");
|
2018-12-07 22:34:21 +01:00
|
|
|
#if ENABLED(TMC_DEBUG)
|
2018-12-10 03:54:48 +01:00
|
|
|
tmc_report_all(true, true, true, true);
|
2018-12-07 22:34:21 +01:00
|
|
|
#endif
|
|
|
|
kill(PSTR("Driver error"));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template<typename TMC>
|
|
|
|
void report_driver_otpw(TMC &st) {
|
|
|
|
char timestamp[14];
|
|
|
|
duration_t elapsed = print_job_timer.duration();
|
|
|
|
const bool has_days = (elapsed.value > 60*60*24L);
|
|
|
|
(void)elapsed.toDigital(timestamp, has_days);
|
|
|
|
SERIAL_EOL();
|
|
|
|
SERIAL_ECHO(timestamp);
|
|
|
|
SERIAL_ECHOPGM(": ");
|
|
|
|
st.printLabel();
|
2019-06-20 22:47:50 +02:00
|
|
|
SERIAL_ECHOLNPAIR(" driver overtemperature warning! (", st.getMilliamps(), "mA)");
|
2018-12-07 22:34:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename TMC>
|
|
|
|
void report_polled_driver_data(TMC &st, const TMC_driver_data &data) {
|
|
|
|
const uint32_t pwm_scale = get_pwm_scale(st);
|
|
|
|
st.printLabel();
|
2019-02-20 09:22:42 +01:00
|
|
|
SERIAL_CHAR(':'); SERIAL_PRINT(pwm_scale, DEC);
|
|
|
|
#if ENABLED(TMC_DEBUG)
|
2019-07-09 05:59:51 +02:00
|
|
|
#if HAS_TMCX1X0 || HAS_TMC220x
|
2019-02-20 09:22:42 +01:00
|
|
|
SERIAL_CHAR('/'); SERIAL_PRINT(data.cs_actual, DEC);
|
|
|
|
#endif
|
|
|
|
#if HAS_STALLGUARD
|
|
|
|
SERIAL_CHAR('/');
|
|
|
|
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);
|
2018-12-07 22:34:21 +01:00
|
|
|
SERIAL_CHAR('\t');
|
|
|
|
}
|
|
|
|
|
2019-11-30 13:59:44 +01:00
|
|
|
#if CURRENT_STEP_DOWN > 0
|
|
|
|
|
|
|
|
template<typename TMC>
|
|
|
|
void step_current_down(TMC &st) {
|
|
|
|
if (st.isEnabled()) {
|
|
|
|
const uint16_t I_rms = st.getMilliamps() - (CURRENT_STEP_DOWN);
|
|
|
|
if (I_rms > 50) {
|
|
|
|
st.rms_current(I_rms);
|
|
|
|
#if ENABLED(REPORT_CURRENT_CHANGE)
|
|
|
|
st.printLabel();
|
|
|
|
SERIAL_ECHOLNPAIR(" current decreased to ", I_rms);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-12-15 22:03:14 +01:00
|
|
|
template<typename TMC>
|
2019-11-30 13:59:44 +01:00
|
|
|
bool monitor_tmc_driver(TMC &st, const bool need_update_error_counters, const bool need_debug_reporting) {
|
2017-12-15 22:03:14 +01:00
|
|
|
TMC_driver_data data = get_driver_data(st);
|
2019-11-30 13:59:44 +01:00
|
|
|
if (data.drv_status == 0xFFFFFFFF || data.drv_status == 0x0) return false;
|
|
|
|
|
|
|
|
bool did_step_down = false;
|
2018-12-07 22:34:21 +01:00
|
|
|
|
2019-02-20 09:22:42 +01:00
|
|
|
if (need_update_error_counters) {
|
|
|
|
if (data.is_ot /* | data.s2ga | data.s2gb*/) st.error_count++;
|
|
|
|
else if (st.error_count > 0) st.error_count--;
|
2017-12-15 22:03:14 +01:00
|
|
|
|
2019-02-20 09:22:42 +01:00
|
|
|
#if ENABLED(STOP_ON_ERROR)
|
|
|
|
if (st.error_count >= 10) {
|
|
|
|
SERIAL_EOL();
|
|
|
|
st.printLabel();
|
|
|
|
report_driver_error(data);
|
|
|
|
}
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
|
2019-02-20 09:22:42 +01:00
|
|
|
// 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
|
2019-11-30 13:59:44 +01:00
|
|
|
if (data.is_otpw && st.otpw_count > 4 && st.isEnabled()) {
|
|
|
|
step_current_down(st);
|
|
|
|
did_step_down = true;
|
2018-12-07 22:34:21 +01:00
|
|
|
}
|
2019-02-20 09:22:42 +01:00
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
|
2019-02-20 09:22:42 +01:00
|
|
|
if (data.is_otpw) {
|
|
|
|
st.otpw_count++;
|
|
|
|
st.flag_otpw = true;
|
|
|
|
}
|
|
|
|
else if (st.otpw_count > 0) st.otpw_count = 0;
|
2017-12-15 22:03:14 +01:00
|
|
|
}
|
|
|
|
|
2018-10-03 18:56:49 +02:00
|
|
|
#if ENABLED(TMC_DEBUG)
|
2019-11-30 13:59:44 +01:00
|
|
|
if (need_debug_reporting) report_polled_driver_data(st, data);
|
2018-10-03 18:56:49 +02:00
|
|
|
#endif
|
2019-11-30 13:59:44 +01:00
|
|
|
|
|
|
|
return did_step_down;
|
2017-12-15 22:03:14 +01:00
|
|
|
}
|
|
|
|
|
2019-11-30 13:59:44 +01:00
|
|
|
void monitor_tmc_drivers() {
|
2018-12-07 22:34:21 +01:00
|
|
|
const millis_t ms = millis();
|
2019-11-30 13:59:44 +01:00
|
|
|
|
|
|
|
// Poll TMC drivers at the configured interval
|
|
|
|
static millis_t next_poll = 0;
|
|
|
|
const bool need_update_error_counters = ELAPSED(ms, next_poll);
|
|
|
|
if (need_update_error_counters) next_poll = ms + MONITOR_DRIVER_STATUS_INTERVAL_MS;
|
|
|
|
|
|
|
|
// Also poll at intervals for debugging
|
2019-02-20 09:22:42 +01:00
|
|
|
#if ENABLED(TMC_DEBUG)
|
|
|
|
static millis_t next_debug_reporting = 0;
|
2019-11-30 13:59:44 +01:00
|
|
|
const bool need_debug_reporting = report_tmc_status_interval && ELAPSED(ms, next_debug_reporting);
|
|
|
|
if (need_debug_reporting) next_debug_reporting = ms + report_tmc_status_interval;
|
|
|
|
#else
|
|
|
|
constexpr bool need_debug_reporting = false;
|
2019-02-20 09:22:42 +01:00
|
|
|
#endif
|
2019-11-30 13:59:44 +01:00
|
|
|
|
2019-02-20 09:22:42 +01:00
|
|
|
if (need_update_error_counters || need_debug_reporting) {
|
2019-05-26 01:22:12 +02:00
|
|
|
#if AXIS_IS_TMC(X)
|
2019-11-30 13:59:44 +01:00
|
|
|
if (monitor_tmc_driver(stepperX, need_update_error_counters, need_debug_reporting)) {
|
|
|
|
#if AXIS_IS_TMC(X2)
|
2019-12-02 00:30:22 +01:00
|
|
|
step_current_down(stepperX2);
|
2019-11-30 13:59:44 +01:00
|
|
|
#endif
|
|
|
|
}
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2019-05-26 01:22:12 +02:00
|
|
|
#if AXIS_IS_TMC(X2)
|
2019-11-30 13:59:44 +01:00
|
|
|
if (monitor_tmc_driver(stepperX2, need_update_error_counters, need_debug_reporting)) {
|
|
|
|
#if AXIS_IS_TMC(X)
|
2019-12-02 00:30:22 +01:00
|
|
|
step_current_down(stepperX);
|
2019-11-30 13:59:44 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Y)
|
|
|
|
if (monitor_tmc_driver(stepperY, need_update_error_counters, need_debug_reporting)) {
|
|
|
|
#if AXIS_IS_TMC(Y2)
|
2019-12-02 00:30:22 +01:00
|
|
|
step_current_down(stepperY2);
|
2019-11-30 13:59:44 +01:00
|
|
|
#endif
|
|
|
|
}
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2019-05-26 01:22:12 +02:00
|
|
|
#if AXIS_IS_TMC(Y2)
|
2019-11-30 13:59:44 +01:00
|
|
|
if (monitor_tmc_driver(stepperY2, need_update_error_counters, need_debug_reporting)) {
|
|
|
|
#if AXIS_IS_TMC(Y)
|
2019-12-02 00:30:22 +01:00
|
|
|
step_current_down(stepperY);
|
2019-11-30 13:59:44 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Z)
|
|
|
|
if (monitor_tmc_driver(stepperZ, need_update_error_counters, need_debug_reporting)) {
|
|
|
|
#if AXIS_IS_TMC(Z2)
|
2019-12-02 00:30:22 +01:00
|
|
|
step_current_down(stepperZ2);
|
2019-11-30 13:59:44 +01:00
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Z3)
|
2019-12-02 00:30:22 +01:00
|
|
|
step_current_down(stepperZ3);
|
2019-11-30 13:59:44 +01:00
|
|
|
#endif
|
|
|
|
}
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2019-05-26 01:22:12 +02:00
|
|
|
#if AXIS_IS_TMC(Z2)
|
2019-11-30 13:59:44 +01:00
|
|
|
if (monitor_tmc_driver(stepperZ2, need_update_error_counters, need_debug_reporting)) {
|
|
|
|
#if AXIS_IS_TMC(Z)
|
2019-12-02 00:30:22 +01:00
|
|
|
step_current_down(stepperZ);
|
2019-11-30 13:59:44 +01:00
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Z3)
|
2019-12-02 00:30:22 +01:00
|
|
|
step_current_down(stepperZ3);
|
2019-11-30 13:59:44 +01:00
|
|
|
#endif
|
|
|
|
}
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2019-05-26 01:22:12 +02:00
|
|
|
#if AXIS_IS_TMC(Z3)
|
2019-11-30 13:59:44 +01:00
|
|
|
if (monitor_tmc_driver(stepperZ3, need_update_error_counters, need_debug_reporting)) {
|
|
|
|
#if AXIS_IS_TMC(Z)
|
2019-12-02 00:30:22 +01:00
|
|
|
step_current_down(stepperZ);
|
2019-11-30 13:59:44 +01:00
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Z2)
|
2019-12-02 00:30:22 +01:00
|
|
|
step_current_down(stepperZ2);
|
2019-11-30 13:59:44 +01:00
|
|
|
#endif
|
|
|
|
}
|
2018-06-19 18:55:49 +02:00
|
|
|
#endif
|
2019-05-26 01:22:12 +02:00
|
|
|
#if AXIS_IS_TMC(E0)
|
2019-11-30 13:59:44 +01:00
|
|
|
(void)monitor_tmc_driver(stepperE0, need_update_error_counters, need_debug_reporting);
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2019-05-26 01:22:12 +02:00
|
|
|
#if AXIS_IS_TMC(E1)
|
2019-11-30 13:59:44 +01:00
|
|
|
(void)monitor_tmc_driver(stepperE1, need_update_error_counters, need_debug_reporting);
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2019-05-26 01:22:12 +02:00
|
|
|
#if AXIS_IS_TMC(E2)
|
2019-11-30 13:59:44 +01:00
|
|
|
(void)monitor_tmc_driver(stepperE2, need_update_error_counters, need_debug_reporting);
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2019-05-26 01:22:12 +02:00
|
|
|
#if AXIS_IS_TMC(E3)
|
2019-11-30 13:59:44 +01:00
|
|
|
(void)monitor_tmc_driver(stepperE3, need_update_error_counters, need_debug_reporting);
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2019-05-26 01:22:12 +02:00
|
|
|
#if AXIS_IS_TMC(E4)
|
2019-11-30 13:59:44 +01:00
|
|
|
(void)monitor_tmc_driver(stepperE4, need_update_error_counters, need_debug_reporting);
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2019-05-26 01:22:12 +02:00
|
|
|
#if AXIS_IS_TMC(E5)
|
2019-11-30 13:59:44 +01:00
|
|
|
(void)monitor_tmc_driver(stepperE5, need_update_error_counters, need_debug_reporting);
|
2018-09-13 08:35:55 +02:00
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
|
2018-10-03 18:56:49 +02:00
|
|
|
#if ENABLED(TMC_DEBUG)
|
2019-02-20 09:22:42 +01:00
|
|
|
if (need_debug_reporting) SERIAL_EOL();
|
2018-10-03 18:56:49 +02:00
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MONITOR_DRIVER_STATUS
|
|
|
|
|
2018-01-10 02:14:07 +01:00
|
|
|
#if ENABLED(TMC_DEBUG)
|
|
|
|
|
2018-10-07 00:18:10 +02:00
|
|
|
/**
|
2019-02-20 09:22:42 +01:00
|
|
|
* M122 [S<0|1>] [Pnnn] Enable periodic status reports
|
2018-10-07 00:18:10 +02:00
|
|
|
*/
|
|
|
|
#if ENABLED(MONITOR_DRIVER_STATUS)
|
2019-02-20 09:22:42 +01:00
|
|
|
void tmc_set_report_interval(const uint16_t update_interval) {
|
|
|
|
if ((report_tmc_status_interval = update_interval))
|
|
|
|
SERIAL_ECHOLNPGM("axis:pwm_scale"
|
|
|
|
#if HAS_STEALTHCHOP
|
2019-06-20 22:47:50 +02:00
|
|
|
"/curr_scale"
|
2019-02-20 09:22:42 +01:00
|
|
|
#endif
|
|
|
|
#if HAS_STALLGUARD
|
|
|
|
"/mech_load"
|
|
|
|
#endif
|
|
|
|
"|flags|warncount"
|
|
|
|
);
|
2018-10-07 00:18:10 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-03-07 05:35:22 +01:00
|
|
|
enum TMC_debug_enum : char {
|
2018-01-10 02:14:07 +01:00
|
|
|
TMC_CODES,
|
2019-06-20 22:47:50 +02:00
|
|
|
TMC_UART_ADDR,
|
2018-01-10 02:14:07 +01:00
|
|
|
TMC_ENABLED,
|
|
|
|
TMC_CURRENT,
|
|
|
|
TMC_RMS_CURRENT,
|
|
|
|
TMC_MAX_CURRENT,
|
|
|
|
TMC_IRUN,
|
|
|
|
TMC_IHOLD,
|
2019-02-06 13:33:14 +01:00
|
|
|
TMC_GLOBAL_SCALER,
|
2018-01-10 02:14:07 +01:00
|
|
|
TMC_CS_ACTUAL,
|
|
|
|
TMC_PWM_SCALE,
|
|
|
|
TMC_VSENSE,
|
|
|
|
TMC_STEALTHCHOP,
|
|
|
|
TMC_MICROSTEPS,
|
|
|
|
TMC_TSTEP,
|
|
|
|
TMC_TPWMTHRS,
|
|
|
|
TMC_TPWMTHRS_MMS,
|
|
|
|
TMC_OTPW,
|
|
|
|
TMC_OTPW_TRIGGERED,
|
|
|
|
TMC_TOFF,
|
|
|
|
TMC_TBL,
|
|
|
|
TMC_HEND,
|
|
|
|
TMC_HSTRT,
|
|
|
|
TMC_SGT
|
|
|
|
};
|
2018-03-07 05:35:22 +01:00
|
|
|
enum TMC_drv_status_enum : char {
|
2018-01-10 02:14:07 +01:00
|
|
|
TMC_DRV_CODES,
|
|
|
|
TMC_STST,
|
|
|
|
TMC_OLB,
|
|
|
|
TMC_OLA,
|
|
|
|
TMC_S2GB,
|
|
|
|
TMC_S2GA,
|
|
|
|
TMC_DRV_OTPW,
|
|
|
|
TMC_OT,
|
|
|
|
TMC_STALLGUARD,
|
|
|
|
TMC_DRV_CS_ACTUAL,
|
|
|
|
TMC_FSACTIVE,
|
|
|
|
TMC_SG_RESULT,
|
|
|
|
TMC_DRV_STATUS_HEX,
|
|
|
|
TMC_T157,
|
|
|
|
TMC_T150,
|
|
|
|
TMC_T143,
|
|
|
|
TMC_T120,
|
|
|
|
TMC_STEALTH,
|
|
|
|
TMC_S2VSB,
|
|
|
|
TMC_S2VSA
|
|
|
|
};
|
2018-12-10 03:54:48 +01:00
|
|
|
enum TMC_get_registers_enum : char {
|
|
|
|
TMC_AXIS_CODES,
|
|
|
|
TMC_GET_GCONF,
|
|
|
|
TMC_GET_IHOLD_IRUN,
|
|
|
|
TMC_GET_GSTAT,
|
|
|
|
TMC_GET_IOIN,
|
|
|
|
TMC_GET_TPOWERDOWN,
|
|
|
|
TMC_GET_TSTEP,
|
|
|
|
TMC_GET_TPWMTHRS,
|
|
|
|
TMC_GET_TCOOLTHRS,
|
|
|
|
TMC_GET_THIGH,
|
|
|
|
TMC_GET_CHOPCONF,
|
|
|
|
TMC_GET_COOLCONF,
|
|
|
|
TMC_GET_PWMCONF,
|
|
|
|
TMC_GET_PWM_SCALE,
|
|
|
|
TMC_GET_DRV_STATUS,
|
|
|
|
TMC_GET_DRVCONF,
|
|
|
|
TMC_GET_DRVCTRL,
|
|
|
|
TMC_GET_DRVSTATUS,
|
|
|
|
TMC_GET_SGCSCONF,
|
|
|
|
TMC_GET_SMARTEN
|
|
|
|
};
|
2018-01-10 02:14:07 +01:00
|
|
|
|
2018-10-03 09:48:49 +02:00
|
|
|
template<class TMC>
|
|
|
|
static void print_vsense(TMC &st) { serialprintPGM(st.vsense() ? PSTR("1=.18") : PSTR("0=.325")); }
|
|
|
|
|
2019-05-26 01:22:12 +02:00
|
|
|
#if HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC5130)
|
|
|
|
static void _tmc_status(TMC2130Stepper &st, const TMC_debug_enum i) {
|
2018-03-08 03:30:19 +01:00
|
|
|
switch (i) {
|
2018-01-10 02:14:07 +01:00
|
|
|
case TMC_PWM_SCALE: SERIAL_PRINT(st.PWM_SCALE(), DEC); break;
|
|
|
|
case TMC_SGT: SERIAL_PRINT(st.sgt(), DEC); break;
|
2019-04-06 03:02:46 +02:00
|
|
|
case TMC_STEALTHCHOP: serialprint_truefalse(st.en_pwm_mode()); break;
|
2018-01-10 02:14:07 +01:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
2019-05-26 01:22:12 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_TMCX1X0
|
2018-10-03 09:48:49 +02:00
|
|
|
static void _tmc_parse_drv_status(TMC2130Stepper &st, const TMC_drv_status_enum i) {
|
2018-03-08 03:30:19 +01:00
|
|
|
switch (i) {
|
2019-06-20 22:47:50 +02:00
|
|
|
case TMC_STALLGUARD: if (st.stallguard()) SERIAL_CHAR('*'); break;
|
|
|
|
case TMC_SG_RESULT: SERIAL_PRINT(st.sg_result(), DEC); break;
|
|
|
|
case TMC_FSACTIVE: if (st.fsactive()) SERIAL_CHAR('*'); break;
|
2018-10-07 00:18:10 +02:00
|
|
|
case TMC_DRV_CS_ACTUAL: SERIAL_PRINT(st.cs_actual(), DEC); break;
|
2018-01-10 02:14:07 +01:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2018-03-14 11:43:18 +01:00
|
|
|
|
2019-02-06 13:33:14 +01:00
|
|
|
#if HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC5160)
|
2019-05-26 01:22:12 +02:00
|
|
|
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
|
|
|
|
void print_vsense(TMCMarlin<TMC2160Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &) { }
|
|
|
|
|
|
|
|
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
|
|
|
|
void print_vsense(TMCMarlin<TMC5160Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &) { }
|
2019-02-06 13:33:14 +01:00
|
|
|
|
2019-05-26 01:22:12 +02:00
|
|
|
static void _tmc_status(TMC2160Stepper &st, const TMC_debug_enum i) {
|
2019-02-06 13:33:14 +01:00
|
|
|
switch (i) {
|
|
|
|
case TMC_PWM_SCALE: SERIAL_PRINT(st.PWM_SCALE(), DEC); break;
|
|
|
|
case TMC_SGT: SERIAL_PRINT(st.sgt(), DEC); break;
|
2019-04-06 03:02:46 +02:00
|
|
|
case TMC_STEALTHCHOP: serialprint_truefalse(st.en_pwm_mode()); break;
|
2019-02-06 13:33:14 +01:00
|
|
|
case TMC_GLOBAL_SCALER:
|
|
|
|
{
|
|
|
|
uint16_t value = st.GLOBAL_SCALER();
|
2019-10-02 02:59:48 +02:00
|
|
|
SERIAL_PRINT(value ?: 256, DEC);
|
2019-02-06 13:33:14 +01:00
|
|
|
SERIAL_ECHOPGM("/256");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-07-09 05:59:51 +02:00
|
|
|
#if HAS_TMC220x
|
2019-05-26 01:22:12 +02:00
|
|
|
static void _tmc_status(TMC2208Stepper &st, const TMC_debug_enum i) {
|
2018-03-08 03:30:19 +01:00
|
|
|
switch (i) {
|
2018-01-10 02:14:07 +01:00
|
|
|
case TMC_PWM_SCALE: SERIAL_PRINT(st.pwm_scale_sum(), DEC); break;
|
2019-04-06 03:02:46 +02:00
|
|
|
case TMC_STEALTHCHOP: serialprint_truefalse(st.stealth()); break;
|
2019-06-20 22:47:50 +02:00
|
|
|
case TMC_S2VSA: if (st.s2vsa()) SERIAL_CHAR('*'); break;
|
|
|
|
case TMC_S2VSB: if (st.s2vsb()) SERIAL_CHAR('*'); break;
|
2018-01-10 02:14:07 +01:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
2019-06-20 22:47:50 +02:00
|
|
|
|
|
|
|
#if HAS_DRIVER(TMC2209)
|
|
|
|
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
|
|
|
|
static void _tmc_status(TMCMarlin<TMC2209Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const TMC_debug_enum i) {
|
|
|
|
switch (i) {
|
|
|
|
case TMC_SGT: SERIAL_PRINT(st.SGTHRS(), DEC); break;
|
|
|
|
case TMC_UART_ADDR: SERIAL_PRINT(st.get_address(), DEC); break;
|
|
|
|
default:
|
|
|
|
TMC2208Stepper *parent = &st;
|
|
|
|
_tmc_status(*parent, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-10-03 09:48:49 +02:00
|
|
|
static void _tmc_parse_drv_status(TMC2208Stepper &st, const TMC_drv_status_enum i) {
|
2018-03-08 03:30:19 +01:00
|
|
|
switch (i) {
|
2019-06-20 22:47:50 +02:00
|
|
|
case TMC_T157: if (st.t157()) SERIAL_CHAR('*'); break;
|
|
|
|
case TMC_T150: if (st.t150()) SERIAL_CHAR('*'); break;
|
|
|
|
case TMC_T143: if (st.t143()) SERIAL_CHAR('*'); break;
|
|
|
|
case TMC_T120: if (st.t120()) SERIAL_CHAR('*'); break;
|
2018-10-07 00:18:10 +02:00
|
|
|
case TMC_DRV_CS_ACTUAL: SERIAL_PRINT(st.cs_actual(), DEC); break;
|
2018-01-10 02:14:07 +01:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-10-07 00:18:10 +02:00
|
|
|
#if HAS_DRIVER(TMC2660)
|
|
|
|
static void _tmc_parse_drv_status(TMC2660Stepper, const TMC_drv_status_enum) { }
|
|
|
|
#endif
|
|
|
|
|
2018-01-10 02:14:07 +01:00
|
|
|
template <typename TMC>
|
2019-05-26 01:22:12 +02:00
|
|
|
static void tmc_status(TMC &st, const TMC_debug_enum i) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_CHAR('\t');
|
2018-03-08 03:30:19 +01:00
|
|
|
switch (i) {
|
2018-10-03 09:48:49 +02:00
|
|
|
case TMC_CODES: st.printLabel(); break;
|
2019-04-06 03:02:46 +02:00
|
|
|
case TMC_ENABLED: serialprint_truefalse(st.isEnabled()); break;
|
2018-10-03 09:48:49 +02:00
|
|
|
case TMC_CURRENT: SERIAL_ECHO(st.getMilliamps()); break;
|
2018-11-29 23:58:58 +01:00
|
|
|
case TMC_RMS_CURRENT: SERIAL_ECHO(st.rms_current()); break;
|
2018-01-10 02:14:07 +01:00
|
|
|
case TMC_MAX_CURRENT: SERIAL_PRINT((float)st.rms_current() * 1.41, 0); break;
|
|
|
|
case TMC_IRUN:
|
|
|
|
SERIAL_PRINT(st.irun(), DEC);
|
|
|
|
SERIAL_ECHOPGM("/31");
|
|
|
|
break;
|
|
|
|
case TMC_IHOLD:
|
|
|
|
SERIAL_PRINT(st.ihold(), DEC);
|
|
|
|
SERIAL_ECHOPGM("/31");
|
|
|
|
break;
|
|
|
|
case TMC_CS_ACTUAL:
|
|
|
|
SERIAL_PRINT(st.cs_actual(), DEC);
|
|
|
|
SERIAL_ECHOPGM("/31");
|
|
|
|
break;
|
2018-10-03 09:48:49 +02:00
|
|
|
case TMC_VSENSE: print_vsense(st); break;
|
2018-01-10 02:14:07 +01:00
|
|
|
case TMC_MICROSTEPS: SERIAL_ECHO(st.microsteps()); break;
|
2018-12-07 22:34:21 +01:00
|
|
|
case TMC_TSTEP: {
|
2019-05-28 04:24:20 +02:00
|
|
|
const uint32_t tstep_value = st.TSTEP();
|
|
|
|
if (tstep_value != 0xFFFFF) SERIAL_ECHO(tstep_value); else SERIAL_ECHOPGM("max");
|
|
|
|
} break;
|
|
|
|
#if ENABLED(HYBRID_THRESHOLD)
|
|
|
|
case TMC_TPWMTHRS: SERIAL_ECHO(uint32_t(st.TPWMTHRS())); break;
|
|
|
|
case TMC_TPWMTHRS_MMS: {
|
|
|
|
const uint32_t tpwmthrs_val = st.get_pwm_thrs();
|
|
|
|
if (tpwmthrs_val) SERIAL_ECHO(tpwmthrs_val); else SERIAL_CHAR('-');
|
|
|
|
} break;
|
|
|
|
#endif
|
2019-04-06 03:02:46 +02:00
|
|
|
case TMC_OTPW: serialprint_truefalse(st.otpw()); break;
|
2018-10-07 00:18:10 +02:00
|
|
|
#if ENABLED(MONITOR_DRIVER_STATUS)
|
2019-04-06 03:02:46 +02:00
|
|
|
case TMC_OTPW_TRIGGERED: serialprint_truefalse(st.getOTPW()); break;
|
2018-10-07 00:18:10 +02:00
|
|
|
#endif
|
2018-01-10 02:14:07 +01:00
|
|
|
case TMC_TOFF: SERIAL_PRINT(st.toff(), DEC); break;
|
|
|
|
case TMC_TBL: SERIAL_PRINT(st.blank_time(), DEC); break;
|
2018-03-16 03:03:12 +01:00
|
|
|
case TMC_HEND: SERIAL_PRINT(st.hysteresis_end(), DEC); break;
|
|
|
|
case TMC_HSTRT: SERIAL_PRINT(st.hysteresis_start(), DEC); break;
|
2019-05-26 01:22:12 +02:00
|
|
|
default: _tmc_status(st, i); break;
|
2018-01-10 02:14:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-07 00:18:10 +02:00
|
|
|
#if HAS_DRIVER(TMC2660)
|
2019-05-26 01:22:12 +02:00
|
|
|
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
|
|
|
|
void tmc_status(TMCMarlin<TMC2660Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const TMC_debug_enum i) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_CHAR('\t');
|
2018-10-07 00:18:10 +02:00
|
|
|
switch (i) {
|
|
|
|
case TMC_CODES: st.printLabel(); break;
|
2019-04-06 03:02:46 +02:00
|
|
|
case TMC_ENABLED: serialprint_truefalse(st.isEnabled()); break;
|
2018-10-07 00:18:10 +02:00
|
|
|
case TMC_CURRENT: SERIAL_ECHO(st.getMilliamps()); break;
|
2018-11-29 23:58:58 +01:00
|
|
|
case TMC_RMS_CURRENT: SERIAL_ECHO(st.rms_current()); break;
|
2018-10-07 00:18:10 +02:00
|
|
|
case TMC_MAX_CURRENT: SERIAL_PRINT((float)st.rms_current() * 1.41, 0); break;
|
|
|
|
case TMC_IRUN:
|
|
|
|
SERIAL_PRINT(st.cs(), DEC);
|
|
|
|
SERIAL_ECHOPGM("/31");
|
|
|
|
break;
|
|
|
|
case TMC_VSENSE: serialprintPGM(st.vsense() ? PSTR("1=.165") : PSTR("0=.310")); break;
|
|
|
|
case TMC_MICROSTEPS: SERIAL_ECHO(st.microsteps()); break;
|
2019-04-06 03:02:46 +02:00
|
|
|
//case TMC_OTPW: serialprint_truefalse(st.otpw()); break;
|
|
|
|
//case TMC_OTPW_TRIGGERED: serialprint_truefalse(st.getOTPW()); break;
|
2018-10-07 00:18:10 +02:00
|
|
|
case TMC_SGT: SERIAL_PRINT(st.sgt(), DEC); break;
|
|
|
|
case TMC_TOFF: SERIAL_PRINT(st.toff(), DEC); break;
|
|
|
|
case TMC_TBL: SERIAL_PRINT(st.blank_time(), DEC); break;
|
|
|
|
case TMC_HEND: SERIAL_PRINT(st.hysteresis_end(), DEC); break;
|
|
|
|
case TMC_HSTRT: SERIAL_PRINT(st.hysteresis_start(), DEC); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-01-10 02:14:07 +01:00
|
|
|
template <typename TMC>
|
2018-10-03 09:48:49 +02:00
|
|
|
static void tmc_parse_drv_status(TMC &st, const TMC_drv_status_enum i) {
|
2018-01-10 02:14:07 +01:00
|
|
|
SERIAL_CHAR('\t');
|
2018-03-08 03:30:19 +01:00
|
|
|
switch (i) {
|
2018-10-03 09:48:49 +02:00
|
|
|
case TMC_DRV_CODES: st.printLabel(); break;
|
2019-06-20 22:47:50 +02:00
|
|
|
case TMC_STST: if (st.stst()) SERIAL_CHAR('*'); break;
|
|
|
|
case TMC_OLB: if (st.olb()) SERIAL_CHAR('*'); break;
|
|
|
|
case TMC_OLA: if (st.ola()) SERIAL_CHAR('*'); break;
|
|
|
|
case TMC_S2GB: if (st.s2gb()) SERIAL_CHAR('*'); break;
|
|
|
|
case TMC_S2GA: if (st.s2ga()) SERIAL_CHAR('*'); break;
|
|
|
|
case TMC_DRV_OTPW: if (st.otpw()) SERIAL_CHAR('*'); break;
|
|
|
|
case TMC_OT: if (st.ot()) SERIAL_CHAR('*'); break;
|
2018-12-10 03:54:48 +01:00
|
|
|
case TMC_DRV_STATUS_HEX: {
|
|
|
|
const uint32_t drv_status = st.DRV_STATUS();
|
|
|
|
SERIAL_CHAR('\t');
|
2018-10-03 09:48:49 +02:00
|
|
|
st.printLabel();
|
2018-12-10 03:54:48 +01:00
|
|
|
SERIAL_CHAR('\t');
|
|
|
|
print_hex_long(drv_status, ':');
|
|
|
|
if (drv_status == 0xFFFFFFFF || drv_status == 0) SERIAL_ECHOPGM("\t Bad response!");
|
|
|
|
SERIAL_EOL();
|
2018-10-03 09:48:49 +02:00
|
|
|
break;
|
2018-12-10 03:54:48 +01:00
|
|
|
}
|
2018-10-03 09:48:49 +02:00
|
|
|
default: _tmc_parse_drv_status(st, i); break;
|
2018-01-10 02:14:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-10 03:54:48 +01:00
|
|
|
static void tmc_debug_loop(const TMC_debug_enum i, const bool print_x, const bool print_y, const bool print_z, const bool print_e) {
|
|
|
|
if (print_x) {
|
|
|
|
#if AXIS_IS_TMC(X)
|
2019-05-26 01:22:12 +02:00
|
|
|
tmc_status(stepperX, i);
|
2018-12-10 03:54:48 +01:00
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(X2)
|
2019-05-26 01:22:12 +02:00
|
|
|
tmc_status(stepperX2, i);
|
2018-12-10 03:54:48 +01:00
|
|
|
#endif
|
|
|
|
}
|
2018-01-10 02:14:07 +01:00
|
|
|
|
2018-12-10 03:54:48 +01:00
|
|
|
if (print_y) {
|
|
|
|
#if AXIS_IS_TMC(Y)
|
2019-05-26 01:22:12 +02:00
|
|
|
tmc_status(stepperY, i);
|
2018-12-10 03:54:48 +01:00
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Y2)
|
2019-05-26 01:22:12 +02:00
|
|
|
tmc_status(stepperY2, i);
|
2018-12-10 03:54:48 +01:00
|
|
|
#endif
|
|
|
|
}
|
2018-01-10 02:14:07 +01:00
|
|
|
|
2018-12-10 03:54:48 +01:00
|
|
|
if (print_z) {
|
|
|
|
#if AXIS_IS_TMC(Z)
|
2019-05-26 01:22:12 +02:00
|
|
|
tmc_status(stepperZ, i);
|
2018-12-10 03:54:48 +01:00
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Z2)
|
2019-05-26 01:22:12 +02:00
|
|
|
tmc_status(stepperZ2, i);
|
2018-12-10 03:54:48 +01:00
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Z3)
|
2019-05-26 01:22:12 +02:00
|
|
|
tmc_status(stepperZ3, i);
|
2018-12-10 03:54:48 +01:00
|
|
|
#endif
|
|
|
|
}
|
2018-01-10 02:14:07 +01:00
|
|
|
|
2018-12-10 03:54:48 +01:00
|
|
|
if (print_e) {
|
|
|
|
#if AXIS_IS_TMC(E0)
|
2019-05-26 01:22:12 +02:00
|
|
|
tmc_status(stepperE0, i);
|
2018-12-10 03:54:48 +01:00
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E1)
|
2019-05-26 01:22:12 +02:00
|
|
|
tmc_status(stepperE1, i);
|
2018-12-10 03:54:48 +01:00
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E2)
|
2019-05-26 01:22:12 +02:00
|
|
|
tmc_status(stepperE2, i);
|
2018-12-10 03:54:48 +01:00
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E3)
|
2019-05-26 01:22:12 +02:00
|
|
|
tmc_status(stepperE3, i);
|
2018-12-10 03:54:48 +01:00
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E4)
|
2019-05-26 01:22:12 +02:00
|
|
|
tmc_status(stepperE4, i);
|
2018-12-10 03:54:48 +01:00
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E5)
|
2019-05-26 01:22:12 +02:00
|
|
|
tmc_status(stepperE5, i);
|
2018-12-10 03:54:48 +01:00
|
|
|
#endif
|
|
|
|
}
|
2018-01-10 02:14:07 +01:00
|
|
|
|
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
|
2018-12-10 03:54:48 +01:00
|
|
|
static void drv_status_loop(const TMC_drv_status_enum i, const bool print_x, const bool print_y, const bool print_z, const bool print_e) {
|
|
|
|
if (print_x) {
|
|
|
|
#if AXIS_IS_TMC(X)
|
|
|
|
tmc_parse_drv_status(stepperX, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(X2)
|
|
|
|
tmc_parse_drv_status(stepperX2, i);
|
|
|
|
#endif
|
|
|
|
}
|
2018-01-10 02:14:07 +01:00
|
|
|
|
2018-12-10 03:54:48 +01:00
|
|
|
if (print_y) {
|
|
|
|
#if AXIS_IS_TMC(Y)
|
|
|
|
tmc_parse_drv_status(stepperY, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Y2)
|
|
|
|
tmc_parse_drv_status(stepperY2, i);
|
|
|
|
#endif
|
|
|
|
}
|
2018-01-10 02:14:07 +01:00
|
|
|
|
2018-12-10 03:54:48 +01:00
|
|
|
if (print_z) {
|
|
|
|
#if AXIS_IS_TMC(Z)
|
|
|
|
tmc_parse_drv_status(stepperZ, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Z2)
|
|
|
|
tmc_parse_drv_status(stepperZ2, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Z3)
|
|
|
|
tmc_parse_drv_status(stepperZ3, i);
|
|
|
|
#endif
|
|
|
|
}
|
2018-01-10 02:14:07 +01:00
|
|
|
|
2018-12-10 03:54:48 +01:00
|
|
|
if (print_e) {
|
|
|
|
#if AXIS_IS_TMC(E0)
|
|
|
|
tmc_parse_drv_status(stepperE0, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E1)
|
|
|
|
tmc_parse_drv_status(stepperE1, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E2)
|
|
|
|
tmc_parse_drv_status(stepperE2, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E3)
|
|
|
|
tmc_parse_drv_status(stepperE3, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E4)
|
|
|
|
tmc_parse_drv_status(stepperE4, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E5)
|
|
|
|
tmc_parse_drv_status(stepperE5, i);
|
|
|
|
#endif
|
|
|
|
}
|
2018-01-10 02:14:07 +01:00
|
|
|
|
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* M122 report functions
|
|
|
|
*/
|
|
|
|
|
2018-12-10 03:54:48 +01:00
|
|
|
void tmc_report_all(bool print_x, const bool print_y, const bool print_z, const bool print_e) {
|
|
|
|
#define TMC_REPORT(LABEL, ITEM) do{ SERIAL_ECHOPGM(LABEL); tmc_debug_loop(ITEM, print_x, print_y, print_z, print_e); }while(0)
|
|
|
|
#define DRV_REPORT(LABEL, ITEM) do{ SERIAL_ECHOPGM(LABEL); drv_status_loop(ITEM, print_x, print_y, print_z, print_e); }while(0)
|
2018-01-10 02:14:07 +01:00
|
|
|
TMC_REPORT("\t", TMC_CODES);
|
2019-06-20 22:47:50 +02:00
|
|
|
#if HAS_DRIVER(TMC2209)
|
|
|
|
TMC_REPORT("Address\t", TMC_UART_ADDR);
|
|
|
|
#endif
|
2018-01-10 02:14:07 +01:00
|
|
|
TMC_REPORT("Enabled\t", TMC_ENABLED);
|
|
|
|
TMC_REPORT("Set current", TMC_CURRENT);
|
|
|
|
TMC_REPORT("RMS current", TMC_RMS_CURRENT);
|
|
|
|
TMC_REPORT("MAX current", TMC_MAX_CURRENT);
|
|
|
|
TMC_REPORT("Run current", TMC_IRUN);
|
|
|
|
TMC_REPORT("Hold current", TMC_IHOLD);
|
2019-02-06 13:33:14 +01:00
|
|
|
#if HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC5160)
|
|
|
|
TMC_REPORT("Global scaler", TMC_GLOBAL_SCALER);
|
|
|
|
#endif
|
2019-07-31 00:11:17 +02:00
|
|
|
TMC_REPORT("CS actual", TMC_CS_ACTUAL);
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC_REPORT("PWM scale", TMC_PWM_SCALE);
|
2019-07-09 05:59:51 +02:00
|
|
|
#if HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2224) || HAS_DRIVER(TMC2660) || HAS_TMC220x
|
2019-05-05 05:00:24 +02:00
|
|
|
TMC_REPORT("vsense\t", TMC_VSENSE);
|
|
|
|
#endif
|
2018-01-10 02:14:07 +01:00
|
|
|
TMC_REPORT("stealthChop", TMC_STEALTHCHOP);
|
|
|
|
TMC_REPORT("msteps\t", TMC_MICROSTEPS);
|
|
|
|
TMC_REPORT("tstep\t", TMC_TSTEP);
|
2019-07-31 00:11:17 +02:00
|
|
|
TMC_REPORT("pwm\nthreshold", TMC_TPWMTHRS);
|
2018-01-10 02:14:07 +01:00
|
|
|
TMC_REPORT("[mm/s]\t", TMC_TPWMTHRS_MMS);
|
|
|
|
TMC_REPORT("OT prewarn", TMC_OTPW);
|
2018-10-07 00:18:10 +02:00
|
|
|
#if ENABLED(MONITOR_DRIVER_STATUS)
|
|
|
|
TMC_REPORT("OT prewarn has\n"
|
|
|
|
"been triggered", TMC_OTPW_TRIGGERED);
|
|
|
|
#endif
|
2019-07-31 00:11:17 +02:00
|
|
|
TMC_REPORT("off time", TMC_TOFF);
|
2018-01-10 02:14:07 +01:00
|
|
|
TMC_REPORT("blank time", TMC_TBL);
|
2018-03-16 03:03:12 +01:00
|
|
|
TMC_REPORT("hysteresis\n-end\t", TMC_HEND);
|
2018-01-10 02:14:07 +01:00
|
|
|
TMC_REPORT("-start\t", TMC_HSTRT);
|
|
|
|
TMC_REPORT("Stallguard thrs", TMC_SGT);
|
|
|
|
|
|
|
|
DRV_REPORT("DRVSTATUS", TMC_DRV_CODES);
|
2019-02-20 09:22:42 +01:00
|
|
|
#if HAS_TMCX1X0
|
2018-01-10 02:14:07 +01:00
|
|
|
DRV_REPORT("stallguard\t", TMC_STALLGUARD);
|
2019-07-31 00:11:17 +02:00
|
|
|
DRV_REPORT("sg_result", TMC_SG_RESULT);
|
2018-01-10 02:14:07 +01:00
|
|
|
DRV_REPORT("fsactive\t", TMC_FSACTIVE);
|
|
|
|
#endif
|
|
|
|
DRV_REPORT("stst\t", TMC_STST);
|
|
|
|
DRV_REPORT("olb\t", TMC_OLB);
|
|
|
|
DRV_REPORT("ola\t", TMC_OLA);
|
|
|
|
DRV_REPORT("s2gb\t", TMC_S2GB);
|
|
|
|
DRV_REPORT("s2ga\t", TMC_S2GA);
|
|
|
|
DRV_REPORT("otpw\t", TMC_DRV_OTPW);
|
|
|
|
DRV_REPORT("ot\t", TMC_OT);
|
2019-07-09 05:59:51 +02:00
|
|
|
#if HAS_TMC220x
|
2018-01-10 02:14:07 +01:00
|
|
|
DRV_REPORT("157C\t", TMC_T157);
|
|
|
|
DRV_REPORT("150C\t", TMC_T150);
|
|
|
|
DRV_REPORT("143C\t", TMC_T143);
|
|
|
|
DRV_REPORT("120C\t", TMC_T120);
|
|
|
|
DRV_REPORT("s2vsa\t", TMC_S2VSA);
|
|
|
|
DRV_REPORT("s2vsb\t", TMC_S2VSB);
|
|
|
|
#endif
|
2018-10-03 09:48:49 +02:00
|
|
|
DRV_REPORT("Driver registers:\n",TMC_DRV_STATUS_HEX);
|
2018-01-10 02:14:07 +01:00
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
|
2018-12-10 03:54:48 +01:00
|
|
|
#define PRINT_TMC_REGISTER(REG_CASE) case TMC_GET_##REG_CASE: print_hex_long(st.REG_CASE(), ':'); break
|
|
|
|
|
2019-02-20 09:22:42 +01:00
|
|
|
#if HAS_TMCX1X0
|
2018-12-10 03:54:48 +01:00
|
|
|
static void tmc_get_ic_registers(TMC2130Stepper &st, const TMC_get_registers_enum i) {
|
|
|
|
switch (i) {
|
|
|
|
PRINT_TMC_REGISTER(TCOOLTHRS);
|
|
|
|
PRINT_TMC_REGISTER(THIGH);
|
|
|
|
PRINT_TMC_REGISTER(COOLCONF);
|
|
|
|
default: SERIAL_CHAR('\t'); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2019-07-09 05:59:51 +02:00
|
|
|
#if HAS_TMC220x
|
2018-12-10 03:54:48 +01:00
|
|
|
static void tmc_get_ic_registers(TMC2208Stepper, const TMC_get_registers_enum) { SERIAL_CHAR('\t'); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_TRINAMIC
|
|
|
|
template<class TMC>
|
|
|
|
static void tmc_get_registers(TMC &st, const TMC_get_registers_enum i) {
|
|
|
|
switch (i) {
|
|
|
|
case TMC_AXIS_CODES: SERIAL_CHAR('\t'); st.printLabel(); break;
|
|
|
|
PRINT_TMC_REGISTER(GCONF);
|
|
|
|
PRINT_TMC_REGISTER(IHOLD_IRUN);
|
|
|
|
PRINT_TMC_REGISTER(GSTAT);
|
|
|
|
PRINT_TMC_REGISTER(IOIN);
|
|
|
|
PRINT_TMC_REGISTER(TPOWERDOWN);
|
|
|
|
PRINT_TMC_REGISTER(TSTEP);
|
|
|
|
PRINT_TMC_REGISTER(TPWMTHRS);
|
|
|
|
PRINT_TMC_REGISTER(CHOPCONF);
|
|
|
|
PRINT_TMC_REGISTER(PWMCONF);
|
|
|
|
PRINT_TMC_REGISTER(PWM_SCALE);
|
|
|
|
PRINT_TMC_REGISTER(DRV_STATUS);
|
|
|
|
default: tmc_get_ic_registers(st, i); break;
|
|
|
|
}
|
|
|
|
SERIAL_CHAR('\t');
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if HAS_DRIVER(TMC2660)
|
2019-05-26 01:22:12 +02:00
|
|
|
template <char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
|
|
|
|
static void tmc_get_registers(TMCMarlin<TMC2660Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const TMC_get_registers_enum i) {
|
2018-12-10 03:54:48 +01:00
|
|
|
switch (i) {
|
|
|
|
case TMC_AXIS_CODES: SERIAL_CHAR('\t'); st.printLabel(); break;
|
|
|
|
PRINT_TMC_REGISTER(DRVCONF);
|
|
|
|
PRINT_TMC_REGISTER(DRVCTRL);
|
|
|
|
PRINT_TMC_REGISTER(CHOPCONF);
|
|
|
|
PRINT_TMC_REGISTER(DRVSTATUS);
|
|
|
|
PRINT_TMC_REGISTER(SGCSCONF);
|
|
|
|
PRINT_TMC_REGISTER(SMARTEN);
|
|
|
|
default: SERIAL_CHAR('\t'); break;
|
|
|
|
}
|
|
|
|
SERIAL_CHAR('\t');
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void tmc_get_registers(TMC_get_registers_enum i, const bool print_x, const bool print_y, const bool print_z, const bool print_e) {
|
|
|
|
if (print_x) {
|
|
|
|
#if AXIS_IS_TMC(X)
|
|
|
|
tmc_get_registers(stepperX, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(X2)
|
|
|
|
tmc_get_registers(stepperX2, i);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (print_y) {
|
|
|
|
#if AXIS_IS_TMC(Y)
|
|
|
|
tmc_get_registers(stepperY, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Y2)
|
|
|
|
tmc_get_registers(stepperY2, i);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (print_z) {
|
|
|
|
#if AXIS_IS_TMC(Z)
|
|
|
|
tmc_get_registers(stepperZ, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Z2)
|
|
|
|
tmc_get_registers(stepperZ2, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Z3)
|
|
|
|
tmc_get_registers(stepperZ3, i);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (print_e) {
|
|
|
|
#if AXIS_IS_TMC(E0)
|
|
|
|
tmc_get_registers(stepperE0, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E1)
|
|
|
|
tmc_get_registers(stepperE1, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E2)
|
|
|
|
tmc_get_registers(stepperE2, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E3)
|
|
|
|
tmc_get_registers(stepperE3, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E4)
|
|
|
|
tmc_get_registers(stepperE4, i);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E5)
|
|
|
|
tmc_get_registers(stepperE5, i);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tmc_get_registers(bool print_x, bool print_y, bool print_z, bool print_e) {
|
|
|
|
#define _TMC_GET_REG(LABEL, ITEM) do{ SERIAL_ECHOPGM(LABEL); tmc_get_registers(ITEM, print_x, print_y, print_z, print_e); }while(0)
|
|
|
|
#define TMC_GET_REG(NAME, TABS) _TMC_GET_REG(STRINGIFY(NAME) TABS, TMC_GET_##NAME)
|
|
|
|
_TMC_GET_REG("\t", TMC_AXIS_CODES);
|
|
|
|
TMC_GET_REG(GCONF, "\t\t");
|
|
|
|
TMC_GET_REG(IHOLD_IRUN, "\t");
|
|
|
|
TMC_GET_REG(GSTAT, "\t\t");
|
|
|
|
TMC_GET_REG(IOIN, "\t\t");
|
|
|
|
TMC_GET_REG(TPOWERDOWN, "\t");
|
|
|
|
TMC_GET_REG(TSTEP, "\t\t");
|
|
|
|
TMC_GET_REG(TPWMTHRS, "\t");
|
|
|
|
TMC_GET_REG(TCOOLTHRS, "\t");
|
|
|
|
TMC_GET_REG(THIGH, "\t\t");
|
|
|
|
TMC_GET_REG(CHOPCONF, "\t");
|
|
|
|
TMC_GET_REG(COOLCONF, "\t");
|
|
|
|
TMC_GET_REG(PWMCONF, "\t");
|
|
|
|
TMC_GET_REG(PWM_SCALE, "\t");
|
|
|
|
TMC_GET_REG(DRV_STATUS, "\t");
|
|
|
|
}
|
|
|
|
|
2018-01-10 02:14:07 +01:00
|
|
|
#endif // TMC_DEBUG
|
|
|
|
|
2018-09-09 21:59:12 +02:00
|
|
|
#if USE_SENSORLESS
|
2018-01-10 02:14:07 +01:00
|
|
|
|
2018-12-07 22:34:21 +01:00
|
|
|
bool tmc_enable_stallguard(TMC2130Stepper &st) {
|
2019-12-19 22:54:29 +01:00
|
|
|
const bool stealthchop_was_enabled = st.en_pwm_mode();
|
2018-12-07 22:34:21 +01:00
|
|
|
|
|
|
|
st.TCOOLTHRS(0xFFFFF);
|
2019-01-21 06:54:57 +01:00
|
|
|
st.en_pwm_mode(false);
|
2018-12-07 22:34:21 +01:00
|
|
|
st.diag1_stall(true);
|
|
|
|
|
|
|
|
return stealthchop_was_enabled;
|
|
|
|
}
|
|
|
|
void tmc_disable_stallguard(TMC2130Stepper &st, const bool restore_stealth) {
|
|
|
|
st.TCOOLTHRS(0);
|
2019-01-21 06:54:57 +01:00
|
|
|
st.en_pwm_mode(restore_stealth);
|
2018-12-07 22:34:21 +01:00
|
|
|
st.diag1_stall(false);
|
2018-01-10 02:14:07 +01:00
|
|
|
}
|
2019-06-20 22:47:50 +02:00
|
|
|
|
|
|
|
bool tmc_enable_stallguard(TMC2209Stepper &st) {
|
|
|
|
st.TCOOLTHRS(0xFFFFF);
|
2019-12-19 22:54:29 +01:00
|
|
|
return !st.en_spreadCycle();
|
2019-06-20 22:47:50 +02:00
|
|
|
}
|
2019-12-19 09:23:54 +01:00
|
|
|
void tmc_disable_stallguard(TMC2209Stepper &st, const bool restore_stealth) {
|
|
|
|
st.en_spreadCycle(!restore_stealth);
|
2019-06-20 22:47:50 +02:00
|
|
|
st.TCOOLTHRS(0);
|
|
|
|
}
|
|
|
|
|
2018-12-07 22:34:21 +01:00
|
|
|
bool tmc_enable_stallguard(TMC2660Stepper) {
|
2018-10-07 00:18:10 +02:00
|
|
|
// TODO
|
2018-12-07 22:34:21 +01:00
|
|
|
return false;
|
2018-10-07 00:18:10 +02:00
|
|
|
}
|
2018-12-07 22:34:21 +01:00
|
|
|
void tmc_disable_stallguard(TMC2660Stepper, const bool) {};
|
2018-01-10 02:14:07 +01:00
|
|
|
|
2018-09-09 21:59:12 +02:00
|
|
|
#endif // USE_SENSORLESS
|
2018-01-10 02:14:07 +01:00
|
|
|
|
2018-10-07 00:18:10 +02:00
|
|
|
#if TMC_HAS_SPI
|
2018-02-10 21:08:53 +01:00
|
|
|
#define SET_CS_PIN(st) OUT_WRITE(st##_CS_PIN, HIGH)
|
|
|
|
void tmc_init_cs_pins() {
|
2018-10-07 00:18:10 +02:00
|
|
|
#if AXIS_HAS_SPI(X)
|
2018-02-10 21:08:53 +01:00
|
|
|
SET_CS_PIN(X);
|
|
|
|
#endif
|
2018-10-07 00:18:10 +02:00
|
|
|
#if AXIS_HAS_SPI(Y)
|
2018-02-10 21:08:53 +01:00
|
|
|
SET_CS_PIN(Y);
|
|
|
|
#endif
|
2018-10-07 00:18:10 +02:00
|
|
|
#if AXIS_HAS_SPI(Z)
|
2018-02-10 21:08:53 +01:00
|
|
|
SET_CS_PIN(Z);
|
|
|
|
#endif
|
2018-10-07 00:18:10 +02:00
|
|
|
#if AXIS_HAS_SPI(X2)
|
2018-02-10 21:08:53 +01:00
|
|
|
SET_CS_PIN(X2);
|
|
|
|
#endif
|
2018-10-07 00:18:10 +02:00
|
|
|
#if AXIS_HAS_SPI(Y2)
|
2018-02-10 21:08:53 +01:00
|
|
|
SET_CS_PIN(Y2);
|
|
|
|
#endif
|
2018-10-07 00:18:10 +02:00
|
|
|
#if AXIS_HAS_SPI(Z2)
|
2018-02-10 21:08:53 +01:00
|
|
|
SET_CS_PIN(Z2);
|
|
|
|
#endif
|
2018-10-07 00:18:10 +02:00
|
|
|
#if AXIS_HAS_SPI(Z3)
|
2018-06-19 18:55:49 +02:00
|
|
|
SET_CS_PIN(Z3);
|
|
|
|
#endif
|
2018-10-07 00:18:10 +02:00
|
|
|
#if AXIS_HAS_SPI(E0)
|
2018-02-10 21:08:53 +01:00
|
|
|
SET_CS_PIN(E0);
|
|
|
|
#endif
|
2018-10-07 00:18:10 +02:00
|
|
|
#if AXIS_HAS_SPI(E1)
|
2018-02-10 21:08:53 +01:00
|
|
|
SET_CS_PIN(E1);
|
|
|
|
#endif
|
2018-10-07 00:18:10 +02:00
|
|
|
#if AXIS_HAS_SPI(E2)
|
2018-02-10 21:08:53 +01:00
|
|
|
SET_CS_PIN(E2);
|
|
|
|
#endif
|
2018-10-07 00:18:10 +02:00
|
|
|
#if AXIS_HAS_SPI(E3)
|
2018-02-10 21:08:53 +01:00
|
|
|
SET_CS_PIN(E3);
|
|
|
|
#endif
|
2018-10-07 00:18:10 +02:00
|
|
|
#if AXIS_HAS_SPI(E4)
|
2018-02-10 21:08:53 +01:00
|
|
|
SET_CS_PIN(E4);
|
|
|
|
#endif
|
2018-10-07 00:18:10 +02:00
|
|
|
#if AXIS_HAS_SPI(E5)
|
2018-09-13 08:35:55 +02:00
|
|
|
SET_CS_PIN(E5);
|
|
|
|
#endif
|
2018-02-10 21:08:53 +01:00
|
|
|
}
|
2018-10-07 00:18:10 +02:00
|
|
|
#endif // TMC_HAS_SPI
|
2018-02-10 21:08:53 +01:00
|
|
|
|
2018-12-10 03:54:48 +01:00
|
|
|
template<typename TMC>
|
|
|
|
static bool test_connection(TMC &st) {
|
|
|
|
SERIAL_ECHOPGM("Testing ");
|
|
|
|
st.printLabel();
|
|
|
|
SERIAL_ECHOPGM(" connection... ");
|
|
|
|
const uint8_t test_result = st.test_connection();
|
|
|
|
|
|
|
|
if (test_result > 0) SERIAL_ECHOPGM("Error: All ");
|
|
|
|
|
|
|
|
const char *stat;
|
|
|
|
switch (test_result) {
|
|
|
|
default:
|
|
|
|
case 0: stat = PSTR("OK"); break;
|
|
|
|
case 1: stat = PSTR("HIGH"); break;
|
|
|
|
case 2: stat = PSTR("LOW"); break;
|
|
|
|
}
|
|
|
|
serialprintPGM(stat);
|
|
|
|
SERIAL_EOL();
|
|
|
|
|
|
|
|
return test_result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_tmc_connection(const bool test_x, const bool test_y, const bool test_z, const bool test_e) {
|
|
|
|
uint8_t axis_connection = 0;
|
|
|
|
|
|
|
|
if (test_x) {
|
|
|
|
#if AXIS_IS_TMC(X)
|
|
|
|
axis_connection += test_connection(stepperX);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(X2)
|
|
|
|
axis_connection += test_connection(stepperX2);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test_y) {
|
|
|
|
#if AXIS_IS_TMC(Y)
|
|
|
|
axis_connection += test_connection(stepperY);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Y2)
|
|
|
|
axis_connection += test_connection(stepperY2);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test_z) {
|
|
|
|
#if AXIS_IS_TMC(Z)
|
|
|
|
axis_connection += test_connection(stepperZ);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Z2)
|
|
|
|
axis_connection += test_connection(stepperZ2);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Z3)
|
|
|
|
axis_connection += test_connection(stepperZ3);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test_e) {
|
|
|
|
#if AXIS_IS_TMC(E0)
|
|
|
|
axis_connection += test_connection(stepperE0);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E1)
|
|
|
|
axis_connection += test_connection(stepperE1);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E2)
|
|
|
|
axis_connection += test_connection(stepperE2);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E3)
|
|
|
|
axis_connection += test_connection(stepperE3);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E4)
|
|
|
|
axis_connection += test_connection(stepperE4);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E5)
|
|
|
|
axis_connection += test_connection(stepperE5);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-10-10 02:46:10 +02:00
|
|
|
if (axis_connection) ui.set_status_P(GET_TEXT(MSG_ERROR_TMC));
|
2018-12-10 03:54:48 +01:00
|
|
|
}
|
|
|
|
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif // HAS_TRINAMIC
|