|
@@ -32,6 +32,10 @@
|
32
|
32
|
#include "../libs/duration_t.h"
|
33
|
33
|
#include "../gcode/gcode.h"
|
34
|
34
|
|
|
35
|
+#if ENABLED(TMC_DEBUG)
|
|
36
|
+ #include "../module/planner.h"
|
|
37
|
+#endif
|
|
38
|
+
|
35
|
39
|
bool report_tmc_status = false;
|
36
|
40
|
char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1", "E2", "E3", "E4" };
|
37
|
41
|
|
|
@@ -51,7 +55,7 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
|
51
|
55
|
};
|
52
|
56
|
#if ENABLED(HAVE_TMC2130)
|
53
|
57
|
static uint32_t get_pwm_scale(TMC2130Stepper &st) { return st.PWM_SCALE(); }
|
54
|
|
- static uint8_t get_status_response(TMC2130Stepper &st) { return st.status_response&0xF; }
|
|
58
|
+ static uint8_t get_status_response(TMC2130Stepper &st) { return st.status_response & 0xF; }
|
55
|
59
|
static TMC_driver_data get_driver_data(TMC2130Stepper &st) {
|
56
|
60
|
constexpr uint32_t OTPW_bm = 0x4000000UL;
|
57
|
61
|
constexpr uint8_t OTPW_bp = 26;
|
|
@@ -61,9 +65,9 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
|
61
|
65
|
constexpr uint8_t DRIVER_ERROR_bp = 1;
|
62
|
66
|
TMC_driver_data data;
|
63
|
67
|
data.drv_status = st.DRV_STATUS();
|
64
|
|
- data.is_otpw = (data.drv_status & OTPW_bm)>>OTPW_bp;
|
65
|
|
- data.is_ot = (data.drv_status & OT_bm)>>OT_bp;
|
66
|
|
- data.is_error = (st.status_response & DRIVER_ERROR_bm)>>DRIVER_ERROR_bp;
|
|
68
|
+ data.is_otpw = (data.drv_status & OTPW_bm) >> OTPW_bp;
|
|
69
|
+ data.is_ot = (data.drv_status & OT_bm) >> OT_bp;
|
|
70
|
+ data.is_error = (st.status_response & DRIVER_ERROR_bm) >> DRIVER_ERROR_bp;
|
67
|
71
|
return data;
|
68
|
72
|
}
|
69
|
73
|
#endif
|
|
@@ -84,35 +88,35 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
|
84
|
88
|
constexpr uint8_t OT_bp = 1;
|
85
|
89
|
TMC_driver_data data;
|
86
|
90
|
data.drv_status = st.DRV_STATUS();
|
87
|
|
- data.is_otpw = (data.drv_status & OTPW_bm)>>OTPW_bp;
|
88
|
|
- data.is_ot = (data.drv_status & OT_bm)>>OT_bp;
|
|
91
|
+ data.is_otpw = (data.drv_status & OTPW_bm) >> OTPW_bp;
|
|
92
|
+ data.is_ot = (data.drv_status & OT_bm) >> OT_bp;
|
89
|
93
|
data.is_error = st.drv_err();
|
90
|
94
|
return data;
|
91
|
95
|
}
|
92
|
96
|
#endif
|
93
|
97
|
|
94
|
98
|
template<typename TMC>
|
95
|
|
- uint8_t monitor_tmc_driver(TMC &st, const char axisID, uint8_t otpw_cnt) {
|
|
99
|
+ void monitor_tmc_driver(TMC &st, const char axisID, uint8_t &otpw_cnt) {
|
96
|
100
|
TMC_driver_data data = get_driver_data(st);
|
97
|
101
|
|
98
|
102
|
#if ENABLED(STOP_ON_ERROR)
|
99
|
103
|
if (data.is_error) {
|
100
|
104
|
SERIAL_EOL();
|
101
|
105
|
SERIAL_ECHO(axisID);
|
102
|
|
- SERIAL_ECHO(" driver error detected:");
|
103
|
|
- if (data.is_ot) SERIAL_ECHO("\novertemperature");
|
104
|
|
- if (st.s2ga()) SERIAL_ECHO("\nshort to ground (coil A)");
|
105
|
|
- if (st.s2gb()) SERIAL_ECHO("\nshort to ground (coil B)");
|
|
106
|
+ SERIAL_ECHOPGM(" driver error detected:");
|
|
107
|
+ if (data.is_ot) SERIAL_ECHOPGM("\novertemperature");
|
|
108
|
+ if (st.s2ga()) SERIAL_ECHOPGM("\nshort to ground (coil A)");
|
|
109
|
+ if (st.s2gb()) SERIAL_ECHOPGM("\nshort to ground (coil B)");
|
106
|
110
|
SERIAL_EOL();
|
107
|
111
|
#if ENABLED(TMC_DEBUG)
|
108
|
|
- _M122();
|
|
112
|
+ tmc_report_all();
|
109
|
113
|
#endif
|
110
|
114
|
kill(PSTR("Driver error"));
|
111
|
115
|
}
|
112
|
116
|
#endif
|
113
|
117
|
|
114
|
118
|
// Report if a warning was triggered
|
115
|
|
- if (data.is_otpw && otpw_cnt==0) {
|
|
119
|
+ if (data.is_otpw && otpw_cnt == 0) {
|
116
|
120
|
char timestamp[10];
|
117
|
121
|
duration_t elapsed = print_job_timer.duration();
|
118
|
122
|
const bool has_days = (elapsed.value > 60*60*24L);
|
|
@@ -123,7 +127,7 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
|
123
|
127
|
SERIAL_ECHO(axisID);
|
124
|
128
|
SERIAL_ECHOPGM(" driver overtemperature warning! (");
|
125
|
129
|
SERIAL_ECHO(st.getCurrent());
|
126
|
|
- SERIAL_ECHOLN("mA)");
|
|
130
|
+ SERIAL_ECHOLNPGM("mA)");
|
127
|
131
|
}
|
128
|
132
|
#if CURRENT_STEP_DOWN > 0
|
129
|
133
|
// Decrease current if is_otpw is true and driver is enabled and there's been more then 4 warnings
|
|
@@ -140,23 +144,21 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
|
140
|
144
|
otpw_cnt++;
|
141
|
145
|
st.flag_otpw = true;
|
142
|
146
|
}
|
143
|
|
- else if (otpw_cnt>0) otpw_cnt--;
|
|
147
|
+ else if (otpw_cnt > 0) otpw_cnt--;
|
144
|
148
|
|
145
|
149
|
if (report_tmc_status) {
|
146
|
150
|
const uint32_t pwm_scale = get_pwm_scale(st);
|
147
|
151
|
SERIAL_ECHO(axisID);
|
148
|
152
|
SERIAL_ECHOPAIR(":", pwm_scale);
|
149
|
|
- SERIAL_ECHO(" |0b"); SERIAL_PRINT(get_status_response(st), BIN);
|
150
|
|
- SERIAL_ECHO("| ");
|
151
|
|
- if (data.is_error) SERIAL_ECHO('E');
|
152
|
|
- else if (data.is_ot) SERIAL_ECHO('O');
|
153
|
|
- else if (data.is_otpw) SERIAL_ECHO('W');
|
154
|
|
- else if (otpw_cnt>0) SERIAL_PRINT(otpw_cnt, DEC);
|
155
|
|
- else if (st.flag_otpw) SERIAL_ECHO('F');
|
156
|
|
- SERIAL_ECHO("\t");
|
|
153
|
+ SERIAL_ECHOPGM(" |0b"); MYSERIAL0.print(get_status_response(st), BIN);
|
|
154
|
+ SERIAL_ECHOPGM("| ");
|
|
155
|
+ if (data.is_error) SERIAL_CHAR('E');
|
|
156
|
+ else if (data.is_ot) SERIAL_CHAR('O');
|
|
157
|
+ else if (data.is_otpw) SERIAL_CHAR('W');
|
|
158
|
+ else if (otpw_cnt > 0) SERIAL_PRINT(otpw_cnt, DEC);
|
|
159
|
+ else if (st.flag_otpw) SERIAL_CHAR('F');
|
|
160
|
+ SERIAL_CHAR('\t');
|
157
|
161
|
}
|
158
|
|
-
|
159
|
|
- return otpw_cnt;
|
160
|
162
|
}
|
161
|
163
|
|
162
|
164
|
#define HAS_HW_COMMS(ST) ENABLED(ST##_IS_TMC2130)|| (ENABLED(ST##_IS_TMC2208) && defined(ST##_HARDWARE_SERIAL))
|
|
@@ -167,47 +169,47 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
|
167
|
169
|
next_cOT = millis() + 500;
|
168
|
170
|
#if HAS_HW_COMMS(X) || ENABLED(IS_TRAMS)
|
169
|
171
|
static uint8_t x_otpw_cnt = 0;
|
170
|
|
- x_otpw_cnt = monitor_tmc_driver(stepperX, axis_codes[X_AXIS], x_otpw_cnt);
|
|
172
|
+ monitor_tmc_driver(stepperX, axis_codes[X_AXIS], x_otpw_cnt);
|
171
|
173
|
#endif
|
172
|
174
|
#if HAS_HW_COMMS(Y) || ENABLED(IS_TRAMS)
|
173
|
175
|
static uint8_t y_otpw_cnt = 0;
|
174
|
|
- y_otpw_cnt = monitor_tmc_driver(stepperY, axis_codes[Y_AXIS], y_otpw_cnt);
|
|
176
|
+ monitor_tmc_driver(stepperY, axis_codes[Y_AXIS], y_otpw_cnt);
|
175
|
177
|
#endif
|
176
|
178
|
#if HAS_HW_COMMS(Z) || ENABLED(IS_TRAMS)
|
177
|
179
|
static uint8_t z_otpw_cnt = 0;
|
178
|
|
- z_otpw_cnt = monitor_tmc_driver(stepperZ, axis_codes[Z_AXIS], z_otpw_cnt);
|
|
180
|
+ monitor_tmc_driver(stepperZ, axis_codes[Z_AXIS], z_otpw_cnt);
|
179
|
181
|
#endif
|
180
|
182
|
#if HAS_HW_COMMS(X2)
|
181
|
183
|
static uint8_t x2_otpw_cnt = 0;
|
182
|
|
- x2_otpw_cnt = monitor_tmc_driver(stepperX2, axis_codes[X_AXIS], x2_otpw_cnt);
|
|
184
|
+ monitor_tmc_driver(stepperX2, axis_codes[X_AXIS], x2_otpw_cnt);
|
183
|
185
|
#endif
|
184
|
186
|
#if HAS_HW_COMMS(Y2)
|
185
|
187
|
static uint8_t y2_otpw_cnt = 0;
|
186
|
|
- y2_otpw_cnt = monitor_tmc_driver(stepperY2, axis_codes[Y_AXIS], y2_otpw_cnt);
|
|
188
|
+ monitor_tmc_driver(stepperY2, axis_codes[Y_AXIS], y2_otpw_cnt);
|
187
|
189
|
#endif
|
188
|
190
|
#if HAS_HW_COMMS(Z2)
|
189
|
191
|
static uint8_t z2_otpw_cnt = 0;
|
190
|
|
- z2_otpw_cnt = monitor_tmc_driver(stepperZ2, axis_codes[Z_AXIS], z2_otpw_cnt);
|
|
192
|
+ monitor_tmc_driver(stepperZ2, axis_codes[Z_AXIS], z2_otpw_cnt);
|
191
|
193
|
#endif
|
192
|
194
|
#if HAS_HW_COMMS(E0) || ENABLED(IS_TRAMS)
|
193
|
195
|
static uint8_t e0_otpw_cnt = 0;
|
194
|
|
- e0_otpw_cnt = monitor_tmc_driver(stepperE0, axis_codes[E_AXIS], e0_otpw_cnt);
|
|
196
|
+ monitor_tmc_driver(stepperE0, axis_codes[E_AXIS], e0_otpw_cnt);
|
195
|
197
|
#endif
|
196
|
198
|
#if HAS_HW_COMMS(E1)
|
197
|
199
|
static uint8_t e1_otpw_cnt = 0;
|
198
|
|
- e1_otpw_cnt = monitor_tmc_driver(stepperE1, axis_codes[E_AXIS], e1_otpw_cnt);
|
|
200
|
+ monitor_tmc_driver(stepperE1, axis_codes[E_AXIS], e1_otpw_cnt);
|
199
|
201
|
#endif
|
200
|
202
|
#if HAS_HW_COMMS(E2)
|
201
|
203
|
static uint8_t e2_otpw_cnt = 0;
|
202
|
|
- e2_otpw_cnt = monitor_tmc_driver(stepperE2, axis_codes[E_AXIS], e2_otpw_cnt);
|
|
204
|
+ monitor_tmc_driver(stepperE2, axis_codes[E_AXIS], e2_otpw_cnt);
|
203
|
205
|
#endif
|
204
|
206
|
#if HAS_HW_COMMS(E3)
|
205
|
207
|
static uint8_t e3_otpw_cnt = 0;
|
206
|
|
- e3_otpw_cnt = monitor_tmc_driver(stepperE3, axis_codes[E_AXIS], e3_otpw_cnt);
|
|
208
|
+ monitor_tmc_driver(stepperE3, axis_codes[E_AXIS], e3_otpw_cnt);
|
207
|
209
|
#endif
|
208
|
210
|
#if HAS_HW_COMMS(E4)
|
209
|
211
|
static uint8_t e4_otpw_cnt = 0;
|
210
|
|
- e4_otpw_cnt = monitor_tmc_driver(stepperE4, axis_codes[E_AXIS], e4_otpw_cnt);
|
|
212
|
+ monitor_tmc_driver(stepperE4, axis_codes[E_AXIS], e4_otpw_cnt);
|
211
|
213
|
#endif
|
212
|
214
|
|
213
|
215
|
if (report_tmc_status) SERIAL_EOL();
|
|
@@ -216,4 +218,349 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
|
216
|
218
|
|
217
|
219
|
#endif // MONITOR_DRIVER_STATUS
|
218
|
220
|
|
|
221
|
+void _tmc_say_current(const char name[], const uint16_t curr) {
|
|
222
|
+ SERIAL_ECHO(name);
|
|
223
|
+ SERIAL_ECHOLNPAIR(" axis driver current: ", curr);
|
|
224
|
+}
|
|
225
|
+void _tmc_say_otpw(const char name[], const bool otpw) {
|
|
226
|
+ SERIAL_ECHO(name);
|
|
227
|
+ SERIAL_ECHOPGM(" axis temperature prewarn triggered: ");
|
|
228
|
+ serialprintPGM(otpw ? PSTR("true") : PSTR("false"));
|
|
229
|
+ SERIAL_EOL();
|
|
230
|
+}
|
|
231
|
+void _tmc_say_otpw_cleared(const char name[]) {
|
|
232
|
+ SERIAL_ECHO(name);
|
|
233
|
+ SERIAL_ECHOLNPGM(" prewarn flag cleared");
|
|
234
|
+}
|
|
235
|
+void _tmc_say_pwmthrs(const char name[], const uint32_t thrs) {
|
|
236
|
+ SERIAL_ECHO(name);
|
|
237
|
+ SERIAL_ECHOLNPAIR(" stealthChop max speed set to ", thrs);
|
|
238
|
+}
|
|
239
|
+void _tmc_say_sgt(const char name[], const uint32_t sgt) {
|
|
240
|
+ SERIAL_ECHO(name);
|
|
241
|
+ SERIAL_ECHOPGM(" driver homing sensitivity set to ");
|
|
242
|
+ MYSERIAL0.println(sgt, DEC);
|
|
243
|
+}
|
|
244
|
+
|
|
245
|
+#if ENABLED(TMC_DEBUG)
|
|
246
|
+
|
|
247
|
+ enum TMC_debug_enum {
|
|
248
|
+ TMC_CODES,
|
|
249
|
+ TMC_ENABLED,
|
|
250
|
+ TMC_CURRENT,
|
|
251
|
+ TMC_RMS_CURRENT,
|
|
252
|
+ TMC_MAX_CURRENT,
|
|
253
|
+ TMC_IRUN,
|
|
254
|
+ TMC_IHOLD,
|
|
255
|
+ TMC_CS_ACTUAL,
|
|
256
|
+ TMC_PWM_SCALE,
|
|
257
|
+ TMC_VSENSE,
|
|
258
|
+ TMC_STEALTHCHOP,
|
|
259
|
+ TMC_MICROSTEPS,
|
|
260
|
+ TMC_TSTEP,
|
|
261
|
+ TMC_TPWMTHRS,
|
|
262
|
+ TMC_TPWMTHRS_MMS,
|
|
263
|
+ TMC_OTPW,
|
|
264
|
+ TMC_OTPW_TRIGGERED,
|
|
265
|
+ TMC_TOFF,
|
|
266
|
+ TMC_TBL,
|
|
267
|
+ TMC_HEND,
|
|
268
|
+ TMC_HSTRT,
|
|
269
|
+ TMC_SGT
|
|
270
|
+ };
|
|
271
|
+ enum TMC_drv_status_enum {
|
|
272
|
+ TMC_DRV_CODES,
|
|
273
|
+ TMC_STST,
|
|
274
|
+ TMC_OLB,
|
|
275
|
+ TMC_OLA,
|
|
276
|
+ TMC_S2GB,
|
|
277
|
+ TMC_S2GA,
|
|
278
|
+ TMC_DRV_OTPW,
|
|
279
|
+ TMC_OT,
|
|
280
|
+ TMC_STALLGUARD,
|
|
281
|
+ TMC_DRV_CS_ACTUAL,
|
|
282
|
+ TMC_FSACTIVE,
|
|
283
|
+ TMC_SG_RESULT,
|
|
284
|
+ TMC_DRV_STATUS_HEX,
|
|
285
|
+ TMC_T157,
|
|
286
|
+ TMC_T150,
|
|
287
|
+ TMC_T143,
|
|
288
|
+ TMC_T120,
|
|
289
|
+ TMC_STEALTH,
|
|
290
|
+ TMC_S2VSB,
|
|
291
|
+ TMC_S2VSA
|
|
292
|
+ };
|
|
293
|
+ static void drv_status_print_hex(const char name[], const uint32_t drv_status) {
|
|
294
|
+ SERIAL_ECHO(name);
|
|
295
|
+ SERIAL_ECHOPGM(" = 0x");
|
|
296
|
+ for (int B = 24; B >= 8; B -= 8){
|
|
297
|
+ SERIAL_PRINT((drv_status >> (B + 4)) & 0xF, HEX);
|
|
298
|
+ SERIAL_PRINT((drv_status >> B) & 0xF, HEX);
|
|
299
|
+ SERIAL_CHAR(':');
|
|
300
|
+ }
|
|
301
|
+ SERIAL_PRINT((drv_status >> 4) & 0xF, HEX);
|
|
302
|
+ SERIAL_PRINT(drv_status & 0xF, HEX);
|
|
303
|
+ SERIAL_EOL();
|
|
304
|
+ }
|
|
305
|
+
|
|
306
|
+ #if ENABLED(HAVE_TMC2130)
|
|
307
|
+ static void tmc_status(TMC2130Stepper &st, const TMC_debug_enum i) {
|
|
308
|
+ switch(i) {
|
|
309
|
+ case TMC_PWM_SCALE: SERIAL_PRINT(st.PWM_SCALE(), DEC); break;
|
|
310
|
+ case TMC_TSTEP: SERIAL_ECHO(st.TSTEP()); break;
|
|
311
|
+ case TMC_SGT: SERIAL_PRINT(st.sgt(), DEC); break;
|
|
312
|
+ case TMC_STEALTHCHOP: serialprintPGM(st.stealthChop() ? PSTR("true") : PSTR("false")); break;
|
|
313
|
+ default: break;
|
|
314
|
+ }
|
|
315
|
+ }
|
|
316
|
+ static void tmc_parse_drv_status(TMC2130Stepper &st, const TMC_drv_status_enum i) {
|
|
317
|
+ switch(i) {
|
|
318
|
+ case TMC_STALLGUARD: if (st.stallguard()) SERIAL_CHAR('X'); break;
|
|
319
|
+ case TMC_SG_RESULT: SERIAL_PRINT(st.sg_result(), DEC); break;
|
|
320
|
+ case TMC_FSACTIVE: if (st.fsactive()) SERIAL_CHAR('X'); break;
|
|
321
|
+ default: break;
|
|
322
|
+ }
|
|
323
|
+ }
|
|
324
|
+ #endif
|
|
325
|
+ #if ENABLED(HAVE_TMC2208)
|
|
326
|
+ static void tmc_status(TMC2208Stepper &st, const TMC_debug_enum i) {
|
|
327
|
+ switch(i) {
|
|
328
|
+ case TMC_TSTEP: { uint32_t data = 0; st.TSTEP(&data); MYSERIAL0.print(data); break; }
|
|
329
|
+ case TMC_PWM_SCALE: SERIAL_PRINT(st.pwm_scale_sum(), DEC); break;
|
|
330
|
+ case TMC_STEALTHCHOP: serialprintPGM(st.stealth() ? PSTR("true") : PSTR("false")); break;
|
|
331
|
+ case TMC_S2VSA: if (st.s2vsa()) SERIAL_CHAR('X'); break;
|
|
332
|
+ case TMC_S2VSB: if (st.s2vsb()) SERIAL_CHAR('X'); break;
|
|
333
|
+ default: break;
|
|
334
|
+ }
|
|
335
|
+ }
|
|
336
|
+ static void tmc_parse_drv_status(TMC2208Stepper &st, const TMC_drv_status_enum i) {
|
|
337
|
+ switch(i) {
|
|
338
|
+ case TMC_T157: if (st.t157()) SERIAL_CHAR('X'); break;
|
|
339
|
+ case TMC_T150: if (st.t150()) SERIAL_CHAR('X'); break;
|
|
340
|
+ case TMC_T143: if (st.t143()) SERIAL_CHAR('X'); break;
|
|
341
|
+ case TMC_T120: if (st.t120()) SERIAL_CHAR('X'); break;
|
|
342
|
+ default: break;
|
|
343
|
+ }
|
|
344
|
+ }
|
|
345
|
+ #endif
|
|
346
|
+
|
|
347
|
+ template <typename TMC>
|
|
348
|
+ static void tmc_status(TMC &st, TMC_AxisEnum axis, const TMC_debug_enum i, const float spmm) {
|
|
349
|
+ SERIAL_ECHO('\t');
|
|
350
|
+ switch(i) {
|
|
351
|
+ case TMC_CODES: SERIAL_ECHO(extended_axis_codes[axis]); break;
|
|
352
|
+ case TMC_ENABLED: serialprintPGM(st.isEnabled() ? PSTR("true") : PSTR("false")); break;
|
|
353
|
+ case TMC_CURRENT: SERIAL_ECHO(st.getCurrent()); break;
|
|
354
|
+ case TMC_RMS_CURRENT: MYSERIAL0.print(st.rms_current()); break;
|
|
355
|
+ case TMC_MAX_CURRENT: SERIAL_PRINT((float)st.rms_current() * 1.41, 0); break;
|
|
356
|
+ case TMC_IRUN:
|
|
357
|
+ SERIAL_PRINT(st.irun(), DEC);
|
|
358
|
+ SERIAL_ECHOPGM("/31");
|
|
359
|
+ break;
|
|
360
|
+ case TMC_IHOLD:
|
|
361
|
+ SERIAL_PRINT(st.ihold(), DEC);
|
|
362
|
+ SERIAL_ECHOPGM("/31");
|
|
363
|
+ break;
|
|
364
|
+ case TMC_CS_ACTUAL:
|
|
365
|
+ SERIAL_PRINT(st.cs_actual(), DEC);
|
|
366
|
+ SERIAL_ECHOPGM("/31");
|
|
367
|
+ break;
|
|
368
|
+
|
|
369
|
+ case TMC_VSENSE: serialprintPGM(st.vsense() ? PSTR("1=.18") : PSTR("0=.325")); break;
|
|
370
|
+
|
|
371
|
+ case TMC_MICROSTEPS: SERIAL_ECHO(st.microsteps()); break;
|
|
372
|
+ case TMC_TPWMTHRS: {
|
|
373
|
+ uint32_t tpwmthrs_val = st.TPWMTHRS();
|
|
374
|
+ SERIAL_ECHO(tpwmthrs_val);
|
|
375
|
+ }
|
|
376
|
+ break;
|
|
377
|
+ case TMC_TPWMTHRS_MMS: {
|
|
378
|
+ uint32_t tpwmthrs_val = st.TPWMTHRS();
|
|
379
|
+ tpwmthrs_val ? SERIAL_ECHO(12650000UL * st.microsteps() / (256 * tpwmthrs_val * spmm)) : SERIAL_CHAR('-');
|
|
380
|
+ }
|
|
381
|
+ break;
|
|
382
|
+ case TMC_OTPW: serialprintPGM(st.otpw() ? PSTR("true") : PSTR("false")); break;
|
|
383
|
+ case TMC_OTPW_TRIGGERED: serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false")); break;
|
|
384
|
+ case TMC_TOFF: SERIAL_PRINT(st.toff(), DEC); break;
|
|
385
|
+ case TMC_TBL: SERIAL_PRINT(st.blank_time(), DEC); break;
|
|
386
|
+ case TMC_HEND: SERIAL_PRINT(st.hysterisis_end(), DEC); break;
|
|
387
|
+ case TMC_HSTRT: SERIAL_PRINT(st.hysterisis_start(), DEC); break;
|
|
388
|
+ default: tmc_status(st, i); break;
|
|
389
|
+ }
|
|
390
|
+ }
|
|
391
|
+
|
|
392
|
+ template <typename TMC>
|
|
393
|
+ static void tmc_parse_drv_status(TMC &st, TMC_AxisEnum axis, const TMC_drv_status_enum i) {
|
|
394
|
+ SERIAL_CHAR('\t');
|
|
395
|
+ switch(i) {
|
|
396
|
+ case TMC_DRV_CODES: SERIAL_ECHO(extended_axis_codes[axis]); break;
|
|
397
|
+ case TMC_STST: if (st.stst()) SERIAL_CHAR('X'); break;
|
|
398
|
+ case TMC_OLB: if (st.olb()) SERIAL_CHAR('X'); break;
|
|
399
|
+ case TMC_OLA: if (st.ola()) SERIAL_CHAR('X'); break;
|
|
400
|
+ case TMC_S2GB: if (st.s2gb()) SERIAL_CHAR('X'); break;
|
|
401
|
+ case TMC_S2GA: if (st.s2ga()) SERIAL_CHAR('X'); break;
|
|
402
|
+ case TMC_DRV_OTPW: if (st.otpw()) SERIAL_CHAR('X'); break;
|
|
403
|
+ case TMC_OT: if (st.ot()) SERIAL_CHAR('X'); break;
|
|
404
|
+ case TMC_DRV_CS_ACTUAL: SERIAL_PRINT(st.cs_actual(), DEC); break;
|
|
405
|
+ case TMC_DRV_STATUS_HEX:drv_status_print_hex(extended_axis_codes[axis], st.DRV_STATUS()); break;
|
|
406
|
+ default: tmc_parse_drv_status(st, i); break;
|
|
407
|
+ }
|
|
408
|
+ }
|
|
409
|
+
|
|
410
|
+ static void tmc_debug_loop(const TMC_debug_enum i) {
|
|
411
|
+ #if X_IS_TRINAMIC
|
|
412
|
+ tmc_status(stepperX, TMC_X, i, planner.axis_steps_per_mm[X_AXIS]);
|
|
413
|
+ #endif
|
|
414
|
+ #if X2_IS_TRINAMIC
|
|
415
|
+ tmc_status(stepperX2, TMC_X2, i, planner.axis_steps_per_mm[X_AXIS]);
|
|
416
|
+ #endif
|
|
417
|
+
|
|
418
|
+ #if Y_IS_TRINAMIC
|
|
419
|
+ tmc_status(stepperY, TMC_Y, i, planner.axis_steps_per_mm[Y_AXIS]);
|
|
420
|
+ #endif
|
|
421
|
+ #if Y2_IS_TRINAMIC
|
|
422
|
+ tmc_status(stepperY2, TMC_Y2, i, planner.axis_steps_per_mm[Y_AXIS]);
|
|
423
|
+ #endif
|
|
424
|
+
|
|
425
|
+ #if Z_IS_TRINAMIC
|
|
426
|
+ tmc_status(stepperZ, TMC_Z, i, planner.axis_steps_per_mm[Z_AXIS]);
|
|
427
|
+ #endif
|
|
428
|
+ #if Z2_IS_TRINAMIC
|
|
429
|
+ tmc_status(stepperZ2, TMC_Z2, i, planner.axis_steps_per_mm[Z_AXIS]);
|
|
430
|
+ #endif
|
|
431
|
+
|
|
432
|
+ #if E0_IS_TRINAMIC
|
|
433
|
+ tmc_status(stepperE0, TMC_E0, i, planner.axis_steps_per_mm[E_AXIS]);
|
|
434
|
+ #endif
|
|
435
|
+ #if E1_IS_TRINAMIC
|
|
436
|
+ tmc_status(stepperE1, TMC_E1, i, planner.axis_steps_per_mm[E_AXIS+1]);
|
|
437
|
+ #endif
|
|
438
|
+ #if E2_IS_TRINAMIC
|
|
439
|
+ tmc_status(stepperE2, TMC_E2, i, planner.axis_steps_per_mm[E_AXIS+2]);
|
|
440
|
+ #endif
|
|
441
|
+ #if E3_IS_TRINAMIC
|
|
442
|
+ tmc_status(stepperE3, TMC_E3, i, planner.axis_steps_per_mm[E_AXIS+3]);
|
|
443
|
+ #endif
|
|
444
|
+ #if E4_IS_TRINAMIC
|
|
445
|
+ tmc_status(stepperE4, TMC_E4, i, planner.axis_steps_per_mm[E_AXIS+4]);
|
|
446
|
+ #endif
|
|
447
|
+
|
|
448
|
+ SERIAL_EOL();
|
|
449
|
+ }
|
|
450
|
+
|
|
451
|
+ static void drv_status_loop(const TMC_drv_status_enum i) {
|
|
452
|
+ #if X_IS_TRINAMIC
|
|
453
|
+ tmc_parse_drv_status(stepperX, TMC_X, i);
|
|
454
|
+ #endif
|
|
455
|
+ #if X2_IS_TRINAMIC
|
|
456
|
+ tmc_parse_drv_status(stepperX2, TMC_X2, i);
|
|
457
|
+ #endif
|
|
458
|
+
|
|
459
|
+ #if Y_IS_TRINAMIC
|
|
460
|
+ tmc_parse_drv_status(stepperY, TMC_Y, i);
|
|
461
|
+ #endif
|
|
462
|
+ #if Y2_IS_TRINAMIC
|
|
463
|
+ tmc_parse_drv_status(stepperY2, TMC_Y2, i);
|
|
464
|
+ #endif
|
|
465
|
+
|
|
466
|
+ #if Z_IS_TRINAMIC
|
|
467
|
+ tmc_parse_drv_status(stepperZ, TMC_Z, i);
|
|
468
|
+ #endif
|
|
469
|
+ #if Z2_IS_TRINAMIC
|
|
470
|
+ tmc_parse_drv_status(stepperZ2, TMC_Z2, i);
|
|
471
|
+ #endif
|
|
472
|
+
|
|
473
|
+ #if E0_IS_TRINAMIC
|
|
474
|
+ tmc_parse_drv_status(stepperE0, TMC_E0, i);
|
|
475
|
+ #endif
|
|
476
|
+ #if E1_IS_TRINAMIC
|
|
477
|
+ tmc_parse_drv_status(stepperE1, TMC_E1, i);
|
|
478
|
+ #endif
|
|
479
|
+ #if E2_IS_TRINAMIC
|
|
480
|
+ tmc_parse_drv_status(stepperE2, TMC_E2, i);
|
|
481
|
+ #endif
|
|
482
|
+ #if E3_IS_TRINAMIC
|
|
483
|
+ tmc_parse_drv_status(stepperE3, TMC_E3, i);
|
|
484
|
+ #endif
|
|
485
|
+ #if E4_IS_TRINAMIC
|
|
486
|
+ tmc_parse_drv_status(stepperE4, TMC_E4, i);
|
|
487
|
+ #endif
|
|
488
|
+
|
|
489
|
+ SERIAL_EOL();
|
|
490
|
+ }
|
|
491
|
+
|
|
492
|
+ /**
|
|
493
|
+ * M122 report functions
|
|
494
|
+ */
|
|
495
|
+ void tmc_set_report_status(const bool status) {
|
|
496
|
+ if ((report_tmc_status = status))
|
|
497
|
+ SERIAL_ECHOLNPGM("axis:pwm_scale |status_response|");
|
|
498
|
+ }
|
|
499
|
+
|
|
500
|
+ void tmc_report_all() {
|
|
501
|
+ #define TMC_REPORT(LABEL, ITEM) do{ SERIAL_ECHOPGM(LABEL); tmc_debug_loop(ITEM); }while(0)
|
|
502
|
+ #define DRV_REPORT(LABEL, ITEM) do{ SERIAL_ECHOPGM(LABEL); drv_status_loop(ITEM); }while(0)
|
|
503
|
+ TMC_REPORT("\t", TMC_CODES);
|
|
504
|
+ TMC_REPORT("Enabled\t", TMC_ENABLED);
|
|
505
|
+ TMC_REPORT("Set current", TMC_CURRENT);
|
|
506
|
+ TMC_REPORT("RMS current", TMC_RMS_CURRENT);
|
|
507
|
+ TMC_REPORT("MAX current", TMC_MAX_CURRENT);
|
|
508
|
+ TMC_REPORT("Run current", TMC_IRUN);
|
|
509
|
+ TMC_REPORT("Hold current", TMC_IHOLD);
|
|
510
|
+ TMC_REPORT("CS actual\t", TMC_CS_ACTUAL);
|
|
511
|
+ TMC_REPORT("PWM scale", TMC_PWM_SCALE);
|
|
512
|
+ TMC_REPORT("vsense\t", TMC_VSENSE);
|
|
513
|
+ TMC_REPORT("stealthChop", TMC_STEALTHCHOP);
|
|
514
|
+ TMC_REPORT("msteps\t", TMC_MICROSTEPS);
|
|
515
|
+ TMC_REPORT("tstep\t", TMC_TSTEP);
|
|
516
|
+ TMC_REPORT("pwm\nthreshold\t", TMC_TPWMTHRS);
|
|
517
|
+ TMC_REPORT("[mm/s]\t", TMC_TPWMTHRS_MMS);
|
|
518
|
+ TMC_REPORT("OT prewarn", TMC_OTPW);
|
|
519
|
+ TMC_REPORT("OT prewarn has\n"
|
|
520
|
+ "been triggered", TMC_OTPW_TRIGGERED);
|
|
521
|
+ TMC_REPORT("off time\t", TMC_TOFF);
|
|
522
|
+ TMC_REPORT("blank time", TMC_TBL);
|
|
523
|
+ TMC_REPORT("hysterisis\n-end\t", TMC_HEND);
|
|
524
|
+ TMC_REPORT("-start\t", TMC_HSTRT);
|
|
525
|
+ TMC_REPORT("Stallguard thrs", TMC_SGT);
|
|
526
|
+
|
|
527
|
+ DRV_REPORT("DRVSTATUS", TMC_DRV_CODES);
|
|
528
|
+ #if ENABLED(HAVE_TMC2130)
|
|
529
|
+ DRV_REPORT("stallguard\t", TMC_STALLGUARD);
|
|
530
|
+ DRV_REPORT("sg_result\t", TMC_SG_RESULT);
|
|
531
|
+ DRV_REPORT("fsactive\t", TMC_FSACTIVE);
|
|
532
|
+ #endif
|
|
533
|
+ DRV_REPORT("stst\t", TMC_STST);
|
|
534
|
+ DRV_REPORT("olb\t", TMC_OLB);
|
|
535
|
+ DRV_REPORT("ola\t", TMC_OLA);
|
|
536
|
+ DRV_REPORT("s2gb\t", TMC_S2GB);
|
|
537
|
+ DRV_REPORT("s2ga\t", TMC_S2GA);
|
|
538
|
+ DRV_REPORT("otpw\t", TMC_DRV_OTPW);
|
|
539
|
+ DRV_REPORT("ot\t", TMC_OT);
|
|
540
|
+ #if ENABLED(HAVE_TMC2208)
|
|
541
|
+ DRV_REPORT("157C\t", TMC_T157);
|
|
542
|
+ DRV_REPORT("150C\t", TMC_T150);
|
|
543
|
+ DRV_REPORT("143C\t", TMC_T143);
|
|
544
|
+ DRV_REPORT("120C\t", TMC_T120);
|
|
545
|
+ DRV_REPORT("s2vsa\t", TMC_S2VSA);
|
|
546
|
+ DRV_REPORT("s2vsb\t", TMC_S2VSB);
|
|
547
|
+ #endif
|
|
548
|
+ DRV_REPORT("Driver registers:", TMC_DRV_STATUS_HEX);
|
|
549
|
+ SERIAL_EOL();
|
|
550
|
+ }
|
|
551
|
+
|
|
552
|
+#endif // TMC_DEBUG
|
|
553
|
+
|
|
554
|
+#if ENABLED(SENSORLESS_HOMING)
|
|
555
|
+
|
|
556
|
+ void tmc_sensorless_homing(TMC2130Stepper &st, bool enable/*=true*/) {
|
|
557
|
+ #if ENABLED(STEALTHCHOP)
|
|
558
|
+ st.coolstep_min_speed(enable ? 1024UL * 1024UL - 1UL : 0);
|
|
559
|
+ st.stealthChop(!enable);
|
|
560
|
+ #endif
|
|
561
|
+ st.diag1_stall(enable ? 1 : 0);
|
|
562
|
+ }
|
|
563
|
+
|
|
564
|
+#endif // SENSORLESS_HOMING
|
|
565
|
+
|
219
|
566
|
#endif // HAS_TRINAMIC
|