Browse Source

TMC_DEBUG optimization and improvements (#13135)

LinFor 6 years ago
parent
commit
ba39186364

+ 221
- 113
Marlin/src/feature/tmc_util.cpp View File

@@ -36,7 +36,7 @@
36 36
   #include "../module/planner.h"
37 37
   #include "../libs/hex_print_routines.h"
38 38
   #if ENABLED(MONITOR_DRIVER_STATUS)
39
-    static bool report_tmc_status; // = false;
39
+    static uint16_t report_tmc_status_interval; // = 0
40 40
   #endif
41 41
 #endif
42 42
 
@@ -55,87 +55,159 @@
55 55
 
56 56
   struct TMC_driver_data {
57 57
     uint32_t drv_status;
58
-    bool is_otpw,
59
-         is_ot,
60
-         is_s2ga,
61
-         is_s2gb,
62
-         is_error;
58
+    bool is_otpw:1,
59
+         is_ot:1,
60
+         is_s2g:1,
61
+         is_error:1
62
+         #if ENABLED(TMC_DEBUG)
63
+           , is_stall:1
64
+           , is_stealth:1
65
+           , is_standstill:1
66
+          #if HAS_STALLGUARD
67
+           , sg_result_reasonable:1
68
+          #endif
69
+         #endif
70
+      ;
71
+    #if ENABLED(TMC_DEBUG)
72
+      #if HAS_TMCX1X0 || HAS_DRIVER(TMC2208)
73
+        uint8_t cs_actual;
74
+      #endif
75
+      #if HAS_STALLGUARD
76
+        uint16_t sg_result;
77
+      #endif
78
+    #endif
63 79
   };
64
-  #if HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160)
80
+
81
+  #if HAS_TMCX1X0
82
+
65 83
     #if ENABLED(TMC_DEBUG)
66 84
       static uint32_t get_pwm_scale(TMC2130Stepper &st) { return st.PWM_SCALE(); }
67
-      static uint8_t get_status_response(TMC2130Stepper &st, uint32_t) { return st.status_response & 0xF; }
68 85
     #endif
86
+
69 87
     static TMC_driver_data get_driver_data(TMC2130Stepper &st) {
70
-      constexpr uint32_t OTPW_bm = 0x4000000UL;
71
-      constexpr uint8_t OTPW_bp = 26;
72
-      constexpr uint32_t OT_bm = 0x2000000UL;
73
-      constexpr uint8_t OT_bp = 25;
74
-      constexpr uint8_t S2GA_bp = 27;
75
-      constexpr uint8_t S2GB_bp = 28;
88
+      constexpr uint16_t SG_RESULT_bm = 0x3FF; // 0:9
89
+      constexpr uint8_t STEALTH_bp = 14, CS_ACTUAL_sb = 16;
90
+      constexpr uint32_t CS_ACTUAL_bm = 0x1F0000; // 16:20
91
+      constexpr uint8_t STALL_GUARD_bp = 24, OT_bp = 25, OTPW_bp = 26;
92
+      constexpr uint32_t S2G_bm = 0x18000000;
93
+      constexpr uint8_t STST_bp = 31;
76 94
       TMC_driver_data data;
77 95
       data.drv_status = st.DRV_STATUS();
78
-      data.is_otpw = (data.drv_status & OTPW_bm) >> OTPW_bp;
79
-      data.is_ot = (data.drv_status & OT_bm) >> OT_bp;
80
-      data.is_s2ga = (data.drv_status >> S2GA_bp) & 0b1;
81
-      data.is_s2gb = (data.drv_status >> S2GB_bp) & 0b1;
96
+      #ifdef __AVR__
97
+        // 8-bit optimization saves up to 70 bytes of PROGMEM per axis
98
+        uint8_t spart;
99
+        #if ENABLED(TMC_DEBUG)
100
+          data.sg_result = data.drv_status & SG_RESULT_bm;
101
+          spart = data.drv_status >> 8;
102
+          data.is_stealth = !!(spart & _BV(STEALTH_bp - 8));
103
+          spart = data.drv_status >> 16;
104
+          data.cs_actual = spart & (CS_ACTUAL_bm >> 16);
105
+        #endif
106
+        spart = data.drv_status >> 24;
107
+        data.is_ot = !!(spart & _BV(OT_bp - 24));
108
+        data.is_otpw = !!(spart & _BV(OTPW_bp - 24));
109
+        data.is_s2g = !!(spart & (S2G_bm >> 24));
110
+        #if ENABLED(TMC_DEBUG)
111
+          data.is_stall = !!(spart & _BV(STALL_GUARD_bp - 24));
112
+          data.is_standstill = !!(spart & _BV(STST_bp - 24));
113
+          data.sg_result_reasonable = !data.is_standstill; // sg_result has no reasonable meaning while standstill
114
+        #endif
115
+
116
+      #else // !__AVR__
117
+
118
+        data.is_ot = !!(data.drv_status & _BV(OT_bp));
119
+        data.is_otpw = !!(data.drv_status & _BV(OTPW_bp));
120
+        data.is_s2g = !!(data.drv_status & S2G_bm);
121
+        #if ENABLED(TMC_DEBUG)
122
+          data.sg_result = data.drv_status & SG_RESULT_bm;
123
+          data.is_stealth = !!(data.drv_status & _BV(STEALTH_bp));
124
+          data.cs_actual = (data.drv_status & CS_ACTUAL_bm) >> CS_ACTUAL_sb;
125
+          data.is_stall = !!(data.drv_status & _BV(STALL_GUARD_bp));
126
+          data.is_standstill = !!(data.drv_status & _BV(STST_bp));
127
+          data.sg_result_reasonable = !data.is_standstill; // sg_result has no reasonable meaning while standstill
128
+        #endif
129
+
130
+      #endif // !__AVR__
131
+
82 132
       return data;
83 133
     }
84
-  #endif
134
+
135
+  #endif // HAS_TMCX1X0
136
+
85 137
   #if HAS_DRIVER(TMC2208)
138
+
86 139
     #if ENABLED(TMC_DEBUG)
87 140
       static uint32_t get_pwm_scale(TMC2208Stepper &st) { return st.pwm_scale_sum(); }
88
-      static uint8_t get_status_response(TMC2208Stepper &st, uint32_t drv_status) {
89
-        uint8_t gstat = st.GSTAT();
90
-        uint8_t response = 0;
91
-        response |= (drv_status >> (31 - 3)) & 0b1000;
92
-        response |= gstat & 0b11;
93
-        return response;
94
-      }
95 141
     #endif
142
+
96 143
     static TMC_driver_data get_driver_data(TMC2208Stepper &st) {
97
-      constexpr uint32_t OTPW_bm = 0b1ul;
98
-      constexpr uint8_t OTPW_bp = 0;
99
-      constexpr uint32_t OT_bm = 0b10ul;
100
-      constexpr uint8_t OT_bp = 1;
101
-      constexpr uint8_t S2GA_bp = 2;
102
-      constexpr uint8_t S2GB_bp = 3;
144
+      constexpr uint8_t OTPW_bp = 0, OT_bp = 1;
145
+      constexpr uint8_t S2G_bm = 0b11110; // 2..5
146
+      constexpr uint8_t CS_ACTUAL_sb = 16;
147
+      constexpr uint32_t CS_ACTUAL_bm = 0x1F0000; // 16:20
148
+      constexpr uint8_t STEALTH_bp = 30, STST_bp = 31;
103 149
       TMC_driver_data data;
104 150
       data.drv_status = st.DRV_STATUS();
105
-      data.is_otpw = (data.drv_status & OTPW_bm) >> OTPW_bp;
106
-      data.is_ot = (data.drv_status & OT_bm) >> OT_bp;
107
-      data.is_s2ga = (data.drv_status >> S2GA_bp) & 0b1;
108
-      data.is_s2gb = (data.drv_status >> S2GB_bp) & 0b1;
151
+      data.is_otpw = !!(data.drv_status & _BV(OTPW_bp));
152
+      data.is_ot = !!(data.drv_status & _BV(OT_bp));
153
+      data.is_s2g = !!(data.drv_status & S2G_bm);
154
+      #if ENABLED(TMC_DEBUG)
155
+        #ifdef __AVR__
156
+          // 8-bit optimization saves up to 12 bytes of PROGMEM per axis
157
+          uint8_t spart = data.drv_status >> 16;
158
+          data.cs_actual = spart & (CS_ACTUAL_bm >> 16);
159
+          spart = data.drv_status >> 24;
160
+          data.is_stealth = !!(spart & _BV(STEALTH_bp - 24));
161
+          data.is_standstill = !!(spart & _BV(STST_bp - 24));
162
+        #else
163
+          data.cs_actual = (data.drv_status & CS_ACTUAL_bm) >> CS_ACTUAL_sb;
164
+          data.is_stealth = !!(data.drv_status & _BV(STEALTH_bp));
165
+          data.is_standstill = !!(data.drv_status & _BV(STST_bp));
166
+        #endif
167
+        #if HAS_STALLGUARD
168
+          data.sg_result_reasonable = false;
169
+        #endif
170
+      #endif
109 171
       return data;
110 172
     }
111
-  #endif
173
+
174
+  #endif // TMC2208
175
+
112 176
   #if HAS_DRIVER(TMC2660)
177
+
113 178
     #if ENABLED(TMC_DEBUG)
114 179
       static uint32_t get_pwm_scale(TMC2660Stepper) { return 0; }
115
-      static uint8_t get_status_response(TMC2660Stepper, uint32_t drv_status) {
116
-        return drv_status & 0xFF;
117
-      }
118 180
     #endif
181
+
119 182
     static TMC_driver_data get_driver_data(TMC2660Stepper &st) {
120
-      constexpr uint32_t OTPW_bm = 0x4UL;
121
-      constexpr uint8_t OTPW_bp = 2;
122
-      constexpr uint32_t OT_bm = 0x2UL;
123
-      constexpr uint8_t OT_bp = 1;
183
+      constexpr uint8_t STALL_GUARD_bp = 0;
184
+      constexpr uint8_t OT_bp = 1, OTPW_bp = 2;
185
+      constexpr uint8_t S2G_bm = 0b11000;
186
+      constexpr uint8_t STST_bp = 7, SG_RESULT_sp = 10;
187
+      constexpr uint32_t SG_RESULT_bm = 0xFFC00; // 10:19
124 188
       TMC_driver_data data;
125 189
       data.drv_status = st.DRVSTATUS();
126
-      data.is_otpw = (data.drv_status & OTPW_bm) >> OTPW_bp;
127
-      data.is_ot = (data.drv_status & OT_bm) >> OT_bp;
190
+      uint8_t spart = data.drv_status & 0xFF;
191
+      data.is_otpw = !!(spart & _BV(OTPW_bp));
192
+      data.is_ot = !!(spart & _BV(OT_bp));
193
+      data.is_s2g = !!(data.drv_status & S2G_bm);
194
+      #if ENABLED(TMC_DEBUG)
195
+        data.is_stall = !!(spart & _BV(STALL_GUARD_bp));
196
+        data.is_standstill = !!(spart & _BV(STST_bp));
197
+        data.sg_result = (data.drv_status & SG_RESULT_bm) >> SG_RESULT_sp;
198
+        data.sg_result_reasonable = true;
199
+      #endif
128 200
       return data;
129 201
     }
130
-  #endif
202
+
203
+  #endif // TMC2660
131 204
 
132 205
   #if ENABLED(STOP_ON_ERROR)
133 206
     void report_driver_error(const TMC_driver_data &data) {
134 207
       SERIAL_ECHOPGM(" driver error detected: 0x");
135 208
       SERIAL_PRINTLN(data.drv_status, HEX);
136 209
       if (data.is_ot) SERIAL_ECHOLNPGM("overtemperature");
137
-      if (data.is_s2ga) SERIAL_ECHOLNPGM("short to ground (coil A)");
138
-      if (data.is_s2gb) SERIAL_ECHOLNPGM("short to ground (coil B)");
210
+      if (data.is_s2g) SERIAL_ECHOLNPGM("coil short circuit");
139 211
       #if ENABLED(TMC_DEBUG)
140 212
         tmc_report_all(true, true, true, true);
141 213
       #endif
@@ -162,61 +234,79 @@
162 234
   void report_polled_driver_data(TMC &st, const TMC_driver_data &data) {
163 235
     const uint32_t pwm_scale = get_pwm_scale(st);
164 236
     st.printLabel();
165
-    SERIAL_ECHOPAIR(":", pwm_scale);
166
-    SERIAL_ECHOPGM(" |0b"); SERIAL_PRINT(get_status_response(st, data.drv_status), BIN);
167
-    SERIAL_ECHOPGM("| ");
168
-    if (st.error_count) SERIAL_CHAR('E');
169
-    else if (data.is_ot) SERIAL_CHAR('O');
170
-    else if (data.is_otpw) SERIAL_CHAR('W');
171
-    else if (st.otpw_count > 0) SERIAL_PRINT(st.otpw_count, DEC);
172
-    else if (st.flag_otpw) SERIAL_CHAR('F');
237
+    SERIAL_CHAR(':'); SERIAL_PRINT(pwm_scale, DEC);
238
+    #if ENABLED(TMC_DEBUG)
239
+      #if HAS_TMCX1X0 || HAS_DRIVER(TMC2208)
240
+        SERIAL_CHAR('/'); SERIAL_PRINT(data.cs_actual, DEC);
241
+      #endif
242
+      #if HAS_STALLGUARD
243
+        SERIAL_CHAR('/');
244
+        if (data.sg_result_reasonable)
245
+          SERIAL_ECHO(data.sg_result);
246
+        else
247
+          SERIAL_CHAR('-');
248
+      #endif
249
+    #endif
250
+    SERIAL_CHAR('|');
251
+    if (st.error_count)       SERIAL_CHAR('E'); // Error
252
+    if (data.is_ot)           SERIAL_CHAR('O'); // Over-temperature
253
+    if (data.is_otpw)         SERIAL_CHAR('W'); // over-temperature pre-Warning
254
+    #if ENABLED(TMC_DEBUG)
255
+      if (data.is_stall)      SERIAL_CHAR('G'); // stallGuard
256
+      if (data.is_stealth)    SERIAL_CHAR('T'); // stealthChop
257
+      if (data.is_standstill) SERIAL_CHAR('I'); // standstIll
258
+    #endif
259
+    if (st.flag_otpw)         SERIAL_CHAR('F'); // otpw Flag
260
+    SERIAL_CHAR('|');
261
+    if (st.otpw_count > 0) SERIAL_PRINT(st.otpw_count, DEC);
173 262
     SERIAL_CHAR('\t');
174 263
   }
175 264
 
176 265
   template<typename TMC>
177
-  void monitor_tmc_driver(TMC &st) {
266
+  void monitor_tmc_driver(TMC &st, const bool need_update_error_counters, const bool need_debug_reporting) {
178 267
     TMC_driver_data data = get_driver_data(st);
179
-    if ((data.drv_status == 0xFFFFFFFF) || (data.drv_status == 0x0)) return;
268
+    if (data.drv_status == 0xFFFFFFFF || data.drv_status == 0x0) return;
180 269
 
181
-    if (data.is_ot /* | data.s2ga | data.s2gb*/) st.error_count++;
182
-    else if (st.error_count > 0) st.error_count--;
270
+    if (need_update_error_counters) {
271
+      if (data.is_ot /* | data.s2ga | data.s2gb*/) st.error_count++;
272
+      else if (st.error_count > 0) st.error_count--;
183 273
 
184
-    #if ENABLED(STOP_ON_ERROR)
185
-      if (st.error_count >= 10) {
186
-        SERIAL_EOL();
187
-        st.printLabel();
188
-        report_driver_error(data);
189
-      }
190
-    #endif
274
+      #if ENABLED(STOP_ON_ERROR)
275
+        if (st.error_count >= 10) {
276
+          SERIAL_EOL();
277
+          st.printLabel();
278
+          report_driver_error(data);
279
+        }
280
+      #endif
191 281
 
192
-    // Report if a warning was triggered
193
-    if (data.is_otpw && st.otpw_count == 0) {
194
-      report_driver_otpw(st);
195
-    }
196
-    #if CURRENT_STEP_DOWN > 0
197
-      // Decrease current if is_otpw is true and driver is enabled and there's been more than 4 warnings
198
-      if (data.is_otpw && st.otpw_count > 4) {
199
-        uint16_t I_rms = st.getMilliamps();
200
-        if (st.isEnabled() && I_rms > 100) {
201
-          st.rms_current(I_rms - (CURRENT_STEP_DOWN));
202
-          #if ENABLED(REPORT_CURRENT_CHANGE)
203
-            st.printLabel();
204
-            SERIAL_ECHOLNPAIR(" current decreased to ", st.getMilliamps());
205
-          #endif
282
+      // Report if a warning was triggered
283
+      if (data.is_otpw && st.otpw_count == 0)
284
+        report_driver_otpw(st);
285
+
286
+      #if CURRENT_STEP_DOWN > 0
287
+        // Decrease current if is_otpw is true and driver is enabled and there's been more than 4 warnings
288
+        if (data.is_otpw && st.otpw_count > 4) {
289
+          uint16_t I_rms = st.getMilliamps();
290
+          if (st.isEnabled() && I_rms > 100) {
291
+            st.rms_current(I_rms - (CURRENT_STEP_DOWN));
292
+            #if ENABLED(REPORT_CURRENT_CHANGE)
293
+              st.printLabel();
294
+              SERIAL_ECHOLNPAIR(" current decreased to ", st.getMilliamps());
295
+            #endif
296
+          }
206 297
         }
207
-      }
208
-    #endif
298
+      #endif
209 299
 
210
-    if (data.is_otpw) {
211
-      st.otpw_count++;
212
-      st.flag_otpw = true;
300
+      if (data.is_otpw) {
301
+        st.otpw_count++;
302
+        st.flag_otpw = true;
303
+      }
304
+      else if (st.otpw_count > 0) st.otpw_count = 0;
213 305
     }
214
-    else if (st.otpw_count > 0) st.otpw_count = 0;
215 306
 
216 307
     #if ENABLED(TMC_DEBUG)
217
-      if (report_tmc_status) {
308
+      if (need_debug_reporting)
218 309
         report_polled_driver_data(st, data);
219
-      }
220 310
     #endif
221 311
   }
222 312
 
@@ -225,50 +315,60 @@
225 315
   void monitor_tmc_driver() {
226 316
     static millis_t next_poll = 0;
227 317
     const millis_t ms = millis();
228
-    if (ELAPSED(ms, next_poll)) {
229
-      next_poll = ms + 500;
318
+    bool need_update_error_counters = ELAPSED(ms, next_poll);
319
+    bool need_debug_reporting = false;
320
+    if (need_update_error_counters)
321
+      next_poll = ms + MONITOR_DRIVER_STATUS_INTERVAL_MS;
322
+    #if ENABLED(TMC_DEBUG)
323
+      static millis_t next_debug_reporting = 0;
324
+      if (report_tmc_status_interval && ELAPSED(ms, next_debug_reporting)) {
325
+        need_debug_reporting = true;
326
+        next_debug_reporting = ms + report_tmc_status_interval;
327
+      }
328
+    #endif
329
+    if (need_update_error_counters || need_debug_reporting) {
230 330
       #if HAS_HW_COMMS(X)
231
-        monitor_tmc_driver(stepperX);
331
+        monitor_tmc_driver(stepperX, need_update_error_counters, need_debug_reporting);
232 332
       #endif
233 333
       #if HAS_HW_COMMS(Y)
234
-        monitor_tmc_driver(stepperY);
334
+        monitor_tmc_driver(stepperY, need_update_error_counters, need_debug_reporting);
235 335
       #endif
236 336
       #if HAS_HW_COMMS(Z)
237
-        monitor_tmc_driver(stepperZ);
337
+        monitor_tmc_driver(stepperZ, need_update_error_counters, need_debug_reporting);
238 338
       #endif
239 339
       #if HAS_HW_COMMS(X2)
240
-        monitor_tmc_driver(stepperX2);
340
+        monitor_tmc_driver(stepperX2, need_update_error_counters, need_debug_reporting);
241 341
       #endif
242 342
       #if HAS_HW_COMMS(Y2)
243
-        monitor_tmc_driver(stepperY2);
343
+        monitor_tmc_driver(stepperY2, need_update_error_counters, need_debug_reporting);
244 344
       #endif
245 345
       #if HAS_HW_COMMS(Z2)
246
-        monitor_tmc_driver(stepperZ2);
346
+        monitor_tmc_driver(stepperZ2, need_update_error_counters, need_debug_reporting);
247 347
       #endif
248 348
       #if HAS_HW_COMMS(Z3)
249
-        monitor_tmc_driver(stepperZ3);
349
+        monitor_tmc_driver(stepperZ3, need_update_error_counters, need_debug_reporting);
250 350
       #endif
251 351
       #if HAS_HW_COMMS(E0)
252
-        monitor_tmc_driver(stepperE0);
352
+        monitor_tmc_driver(stepperE0, need_update_error_counters, need_debug_reporting);
253 353
       #endif
254 354
       #if HAS_HW_COMMS(E1)
255
-        monitor_tmc_driver(stepperE1);
355
+        monitor_tmc_driver(stepperE1, need_update_error_counters, need_debug_reporting);
256 356
       #endif
257 357
       #if HAS_HW_COMMS(E2)
258
-        monitor_tmc_driver(stepperE2);
358
+        monitor_tmc_driver(stepperE2, need_update_error_counters, need_debug_reporting);
259 359
       #endif
260 360
       #if HAS_HW_COMMS(E3)
261
-        monitor_tmc_driver(stepperE3);
361
+        monitor_tmc_driver(stepperE3, need_update_error_counters, need_debug_reporting);
262 362
       #endif
263 363
       #if HAS_HW_COMMS(E4)
264
-        monitor_tmc_driver(stepperE4);
364
+        monitor_tmc_driver(stepperE4, need_update_error_counters, need_debug_reporting);
265 365
       #endif
266 366
       #if HAS_HW_COMMS(E5)
267
-        monitor_tmc_driver(stepperE5);
367
+        monitor_tmc_driver(stepperE5, need_update_error_counters, need_debug_reporting);
268 368
       #endif
269 369
 
270 370
       #if ENABLED(TMC_DEBUG)
271
-        if (report_tmc_status) SERIAL_EOL();
371
+        if (need_debug_reporting) SERIAL_EOL();
272 372
       #endif
273 373
     }
274 374
   }
@@ -278,12 +378,20 @@
278 378
 #if ENABLED(TMC_DEBUG)
279 379
 
280 380
   /**
281
-   * M122 S[1,0] Enable periodic status reports
381
+   * M122 [S<0|1>] [Pnnn] Enable periodic status reports
282 382
    */
283 383
   #if ENABLED(MONITOR_DRIVER_STATUS)
284
-    void tmc_set_report_status(const bool status) {
285
-      if ((report_tmc_status = status))
286
-        SERIAL_ECHOLNPGM("axis:pwm_scale |status_response|");
384
+    void tmc_set_report_interval(const uint16_t update_interval) {
385
+      if ((report_tmc_status_interval = update_interval))
386
+        SERIAL_ECHOLNPGM("axis:pwm_scale"
387
+          #if HAS_STEALTHCHOP
388
+            "/current_scale"
389
+          #endif
390
+          #if HAS_STALLGUARD
391
+            "/mech_load"
392
+          #endif
393
+          "|flags|warncount"
394
+        );
287 395
     }
288 396
   #endif
289 397
 
@@ -360,7 +468,7 @@
360 468
   template<class TMC>
361 469
   static void print_vsense(TMC &st) { serialprintPGM(st.vsense() ? PSTR("1=.18") : PSTR("0=.325")); }
362 470
 
363
-  #if HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160)
471
+  #if HAS_TMCX1X0
364 472
     static void tmc_status(TMC2130Stepper &st, const TMC_debug_enum i) {
365 473
       switch (i) {
366 474
         case TMC_PWM_SCALE: SERIAL_PRINT(st.PWM_SCALE(), DEC); break;
@@ -702,7 +810,7 @@
702 810
     TMC_REPORT("Stallguard thrs",    TMC_SGT);
703 811
 
704 812
     DRV_REPORT("DRVSTATUS",          TMC_DRV_CODES);
705
-    #if HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160)
813
+    #if HAS_TMCX1X0
706 814
       DRV_REPORT("stallguard\t",     TMC_STALLGUARD);
707 815
       DRV_REPORT("sg_result\t",      TMC_SG_RESULT);
708 816
       DRV_REPORT("fsactive\t",       TMC_FSACTIVE);
@@ -728,7 +836,7 @@
728 836
 
729 837
   #define PRINT_TMC_REGISTER(REG_CASE) case TMC_GET_##REG_CASE: print_hex_long(st.REG_CASE(), ':'); break
730 838
 
731
-  #if HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160)
839
+  #if HAS_TMCX1X0
732 840
     static void tmc_get_ic_registers(TMC2130Stepper &st, const TMC_get_registers_enum i) {
733 841
       switch (i) {
734 842
         PRINT_TMC_REGISTER(TCOOLTHRS);

+ 5
- 1
Marlin/src/feature/tmc_util.h View File

@@ -53,6 +53,10 @@
53 53
 #define CHOPPER_PRUSAMK3_24V { 4,  1, 4 }
54 54
 #define CHOPPER_MARLIN_119   { 5,  2, 3 }
55 55
 
56
+#if ENABLED(MONITOR_DRIVER_STATUS) && !defined(MONITOR_DRIVER_STATUS_INTERVAL_MS)
57
+  #define MONITOR_DRIVER_STATUS_INTERVAL_MS 500u
58
+#endif
59
+
56 60
 constexpr uint16_t _tmc_thrs(const uint16_t msteps, const int32_t thrs, const uint32_t spmm) {
57 61
   return 12650000UL * msteps / (256 * thrs * spmm);
58 62
 }
@@ -258,7 +262,7 @@ void test_tmc_connection(const bool test_x, const bool test_y, const bool test_z
258 262
 
259 263
 #if ENABLED(TMC_DEBUG)
260 264
   #if ENABLED(MONITOR_DRIVER_STATUS)
261
-    void tmc_set_report_status(const bool status);
265
+    void tmc_set_report_interval(const uint16_t update_interval);
262 266
   #endif
263 267
   void tmc_report_all(const bool print_x, const bool print_y, const bool print_z, const bool print_e);
264 268
   void tmc_get_registers(const bool print_x, const bool print_y, const bool print_z, const bool print_e);

+ 1
- 1
Marlin/src/gcode/feature/L6470/M122.cpp View File

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

+ 3
- 2
Marlin/src/gcode/feature/trinamic/M122.cpp View File

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

+ 1
- 1
Marlin/src/gcode/gcode.cpp View File

@@ -662,7 +662,7 @@ void GcodeSuite::process_parsed_command(
662 662
       #endif
663 663
 
664 664
       #if HAS_TRINAMIC
665
-        case 122: M122(); break;
665
+        case 122: M122(); break;                                  // M122: Report driver configuration and status
666 666
         case 906: M906(); break;                                  // M906: Set motor current in milliamps using axis codes X, Y, Z, E
667 667
         #if HAS_STEALTHCHOP
668 668
           case 569: M569(); break;                                // M569: Enable stealthChop on an axis.

+ 4
- 3
Marlin/src/inc/Conditionals_post.h View File

@@ -853,9 +853,10 @@
853 853
 
854 854
 // Trinamic Stepper Drivers
855 855
 #if HAS_TRINAMIC
856
-  #define TMC_HAS_SPI     (HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC2660) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160))
857
-  #define HAS_STALLGUARD  (HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC2660) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160))
858
-  #define HAS_STEALTHCHOP (HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC2208) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160))
856
+  #define HAS_TMCX1X0       (HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160))
857
+  #define TMC_HAS_SPI       (HAS_TMCX1X0 || HAS_DRIVER(TMC2660))
858
+  #define HAS_STALLGUARD    (HAS_TMCX1X0 || HAS_DRIVER(TMC2660))
859
+  #define HAS_STEALTHCHOP   (HAS_TMCX1X0 || HAS_DRIVER(TMC2208))
859 860
   #define AXIS_HAS_SPI(ST)         (AXIS_DRIVER_TYPE(ST, TMC2130) || AXIS_DRIVER_TYPE(ST, TMC2160) || AXIS_DRIVER_TYPE(ST, TMC2660))
860 861
   #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))
861 862
   #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))

+ 4
- 0
Marlin/src/module/stepper_indirection.cpp View File

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

Loading…
Cancel
Save