Browse Source

Merge pull request #10102 from thinkyhead/bf2_eeprom_M913

[2.0.x] More complete Trinamic driver options
Scott Lahteine 7 years ago
parent
commit
8dfaf1539e
No account linked to committer's email address

+ 5
- 0
Marlin/src/feature/power.cpp View File

@@ -88,6 +88,11 @@ void Power::check() {
88 88
 void Power::power_on() {
89 89
   lastPowerOn = millis();
90 90
   PSU_PIN_ON();
91
+
92
+  #if HAS_TRINAMIC
93
+    delay(100); // Wait for power to settle
94
+    restore_stepper_drivers();
95
+  #endif
91 96
 }
92 97
 
93 98
 void Power::power_off() {

+ 1
- 0
Marlin/src/feature/tmc_util.cpp View File

@@ -331,6 +331,7 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) {
331 331
       }
332 332
     }
333 333
   #endif
334
+
334 335
   #if ENABLED(HAVE_TMC2208)
335 336
     static void tmc_status(TMC2208Stepper &st, const TMC_debug_enum i) {
336 337
       switch (i) {

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

@@ -35,7 +35,7 @@
35 35
 
36 36
 extern bool report_tmc_status;
37 37
 
38
-enum TMC_AxisEnum : char { TMC_X, TMC_X2, TMC_Y, TMC_Y2, TMC_Z, TMC_Z2, TMC_E0, TMC_E1, TMC_E2, TMC_E3, TMC_E4 };
38
+enum TMC_AxisEnum : char { TMC_X, TMC_Y, TMC_Z, TMC_X2, TMC_Y2, TMC_Z2, TMC_E0, TMC_E1, TMC_E2, TMC_E3, TMC_E4 };
39 39
 
40 40
 constexpr uint32_t _tmc_thrs(const uint16_t msteps, const int32_t thrs, const uint32_t spmm) {
41 41
   return 12650000UL * msteps / (256 * thrs * spmm);
@@ -55,7 +55,6 @@ void tmc_get_current(TMC &st, const TMC_AxisEnum axis) {
55 55
 template<typename TMC>
56 56
 void tmc_set_current(TMC &st, const TMC_AxisEnum axis, const int mA) {
57 57
   st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
58
-  tmc_get_current(st, axis);
59 58
 }
60 59
 template<typename TMC>
61 60
 void tmc_report_otpw(TMC &st, const TMC_AxisEnum axis) {
@@ -73,7 +72,6 @@ void tmc_get_pwmthrs(TMC &st, const TMC_AxisEnum axis, const uint16_t spmm) {
73 72
 template<typename TMC>
74 73
 void tmc_set_pwmthrs(TMC &st, const TMC_AxisEnum axis, const int32_t thrs, const uint32_t spmm) {
75 74
   st.TPWMTHRS(_tmc_thrs(st.microsteps(), thrs, spmm));
76
-  tmc_get_pwmthrs(st, axis, spmm);
77 75
 }
78 76
 template<typename TMC>
79 77
 void tmc_get_sgt(TMC &st, const TMC_AxisEnum axis) {
@@ -82,7 +80,6 @@ void tmc_get_sgt(TMC &st, const TMC_AxisEnum axis) {
82 80
 template<typename TMC>
83 81
 void tmc_set_sgt(TMC &st, const TMC_AxisEnum axis, const int8_t sgt_val) {
84 82
   st.sgt(sgt_val);
85
-  tmc_get_sgt(st, axis);
86 83
 }
87 84
 
88 85
 void monitor_tmc_driver();

+ 3
- 8
Marlin/src/gcode/control/M80_M81.cpp View File

@@ -76,14 +76,9 @@
76 76
       OUT_WRITE(SUICIDE_PIN, HIGH);
77 77
     #endif
78 78
 
79
-    #if ENABLED(HAVE_TMC2130)
80
-      delay(100);
81
-      tmc2130_init(); // Settings only stick when the driver has power
82
-    #endif
83
-
84
-    #if ENABLED(HAVE_TMC2208)
85
-      delay(100);
86
-      tmc2208_init();
79
+    #if DISABLED(AUTO_POWER_CONTROL)
80
+      delay(100); // Wait for power to settle
81
+      restore_stepper_drivers();
87 82
     #endif
88 83
 
89 84
     #if ENABLED(ULTIPANEL)

+ 96
- 38
Marlin/src/gcode/feature/trinamic/M906.cpp View File

@@ -33,46 +33,104 @@
33 33
  * Report driver currents when no axis specified
34 34
  */
35 35
 void GcodeSuite::M906() {
36
-  uint16_t values[XYZE];
37
-  LOOP_XYZE(i) values[i] = parser.intval(axis_codes[i]);
36
+  #define TMC_SAY_CURRENT(Q) tmc_get_current(stepper##Q, TMC_##Q)
37
+  #define TMC_SET_CURRENT(Q) tmc_set_current(stepper##Q, TMC_##Q, value)
38 38
 
39
-  #define TMC_SET_GET_CURRENT(P,Q) do { \
40
-    if (values[P##_AXIS]) tmc_set_current(stepper##Q, TMC_##Q, values[P##_AXIS]); \
41
-    else tmc_get_current(stepper##Q, TMC_##Q); } while(0)
39
+  bool report = true;
40
+  const uint8_t index = parser.byteval('I');
41
+  LOOP_XYZE(i) if (uint16_t value = parser.intval(axis_codes[i])) {
42
+    report = false;
43
+    switch (i) {
44
+      case X_AXIS:
45
+        #if X_IS_TRINAMIC
46
+          if (index == 0) TMC_SET_CURRENT(X);
47
+        #endif
48
+        #if X2_IS_TRINAMIC
49
+          if (index == 1) TMC_SET_CURRENT(X2);
50
+        #endif
51
+        break;
52
+      case Y_AXIS:
53
+        #if Y_IS_TRINAMIC
54
+          if (index == 0) TMC_SET_CURRENT(Y);
55
+        #endif
56
+        #if Y2_IS_TRINAMIC
57
+          if (index == 1) TMC_SET_CURRENT(Y2);
58
+        #endif
59
+        break;
60
+      case Z_AXIS:
61
+        #if Z_IS_TRINAMIC
62
+          if (index == 0) TMC_SET_CURRENT(Z);
63
+        #endif
64
+        #if Z2_IS_TRINAMIC
65
+          if (index == 1) TMC_SET_CURRENT(Z2);
66
+        #endif
67
+        break;
68
+      case E_AXIS: {
69
+        if (get_target_extruder_from_command()) return;
70
+        switch (target_extruder) {
71
+          #if E0_IS_TRINAMIC
72
+            case 0: TMC_SET_CURRENT(E0); break;
73
+          #endif
74
+          #if E1_IS_TRINAMIC
75
+            case 1: TMC_SET_CURRENT(E1); break;
76
+          #endif
77
+          #if E2_IS_TRINAMIC
78
+            case 2: TMC_SET_CURRENT(E2); break;
79
+          #endif
80
+          #if E3_IS_TRINAMIC
81
+            case 3: TMC_SET_CURRENT(E3); break;
82
+          #endif
83
+          #if E4_IS_TRINAMIC
84
+            case 4: TMC_SET_CURRENT(E4); break;
85
+          #endif
86
+        }
87
+      } break;
88
+    }
89
+  }
42 90
 
43
-  #if X_IS_TRINAMIC
44
-    TMC_SET_GET_CURRENT(X,X);
45
-  #endif
46
-  #if X2_IS_TRINAMIC
47
-    TMC_SET_GET_CURRENT(X,X2);
48
-  #endif
49
-  #if Y_IS_TRINAMIC
50
-    TMC_SET_GET_CURRENT(Y,Y);
51
-  #endif
52
-  #if Y2_IS_TRINAMIC
53
-    TMC_SET_GET_CURRENT(Y,Y2);
54
-  #endif
55
-  #if Z_IS_TRINAMIC
56
-    TMC_SET_GET_CURRENT(Z,Z);
57
-  #endif
58
-  #if Z2_IS_TRINAMIC
59
-    TMC_SET_GET_CURRENT(Z,Z2);
60
-  #endif
61
-  #if E0_IS_TRINAMIC
62
-    TMC_SET_GET_CURRENT(E,E0);
63
-  #endif
64
-  #if E1_IS_TRINAMIC
65
-    TMC_SET_GET_CURRENT(E,E1);
66
-  #endif
67
-  #if E2_IS_TRINAMIC
68
-    TMC_SET_GET_CURRENT(E,E2);
69
-  #endif
70
-  #if E3_IS_TRINAMIC
71
-    TMC_SET_GET_CURRENT(E,E3);
72
-  #endif
73
-  #if E4_IS_TRINAMIC
74
-    TMC_SET_GET_CURRENT(E,E4);
75
-  #endif
91
+  if (report) LOOP_XYZE(i) switch (i) {
92
+    case X_AXIS:
93
+      #if X_IS_TRINAMIC
94
+        TMC_SAY_CURRENT(X);
95
+      #endif
96
+      #if X2_IS_TRINAMIC
97
+        TMC_SAY_CURRENT(X2);
98
+      #endif
99
+      break;
100
+    case Y_AXIS:
101
+      #if Y_IS_TRINAMIC
102
+        TMC_SAY_CURRENT(Y);
103
+      #endif
104
+      #if Y2_IS_TRINAMIC
105
+        TMC_SAY_CURRENT(Y2);
106
+      #endif
107
+      break;
108
+    case Z_AXIS:
109
+      #if Z_IS_TRINAMIC
110
+        TMC_SAY_CURRENT(Z);
111
+      #endif
112
+      #if Z2_IS_TRINAMIC
113
+        TMC_SAY_CURRENT(Z2);
114
+      #endif
115
+      break;
116
+    case E_AXIS:
117
+      #if E0_IS_TRINAMIC
118
+        TMC_SAY_CURRENT(E0);
119
+      #endif
120
+      #if E1_IS_TRINAMIC
121
+        TMC_SAY_CURRENT(E1);
122
+      #endif
123
+      #if E2_IS_TRINAMIC
124
+        TMC_SAY_CURRENT(E2);
125
+      #endif
126
+      #if E3_IS_TRINAMIC
127
+        TMC_SAY_CURRENT(E3);
128
+      #endif
129
+      #if E4_IS_TRINAMIC
130
+        TMC_SAY_CURRENT(E4);
131
+      #endif
132
+      break;
133
+  }
76 134
 }
77 135
 
78 136
 #endif // HAS_TRINAMIC

+ 160
- 66
Marlin/src/gcode/feature/trinamic/M911-M915.cpp View File

@@ -80,46 +80,106 @@ void GcodeSuite::M912() {
80 80
  */
81 81
 #if ENABLED(HYBRID_THRESHOLD)
82 82
   void GcodeSuite::M913() {
83
-    uint16_t values[XYZE];
84
-    LOOP_XYZE(i) values[i] = parser.intval(axis_codes[i]);
83
+    #define TMC_SAY_PWMTHRS(P,Q) tmc_get_pwmthrs(stepper##Q, TMC_##Q, planner.axis_steps_per_mm[P##_AXIS])
84
+    #define TMC_SET_PWMTHRS(P,Q) tmc_set_pwmthrs(stepper##Q, TMC_##Q, value, planner.axis_steps_per_mm[P##_AXIS])
85
+    #define TMC_SAY_PWMTHRS_E(E) do{ const uint8_t extruder = E; tmc_get_pwmthrs(stepperE##E, TMC_E##E, planner.axis_steps_per_mm[E_AXIS_N]); }while(0)
86
+    #define TMC_SET_PWMTHRS_E(E) do{ const uint8_t extruder = E; tmc_set_pwmthrs(stepperE##E, TMC_E##E, value, planner.axis_steps_per_mm[E_AXIS_N]); }while(0)
85 87
 
86
-    #define TMC_SET_GET_PWMTHRS(P,Q) do { \
87
-      if (values[P##_AXIS]) tmc_set_pwmthrs(stepper##Q, TMC_##Q, values[P##_AXIS], planner.axis_steps_per_mm[P##_AXIS]); \
88
-      else tmc_get_pwmthrs(stepper##Q, TMC_##Q, planner.axis_steps_per_mm[P##_AXIS]); } while(0)
88
+    bool report = true;
89
+    const uint8_t index = parser.byteval('I');
90
+    LOOP_XYZE(i) if (int32_t value = parser.longval(axis_codes[i])) {
91
+      report = false;
92
+      switch (i) {
93
+        case X_AXIS:
94
+          #if X_IS_TRINAMIC
95
+            if (index == 0) TMC_SET_PWMTHRS(X,X);
96
+          #endif
97
+          #if X2_IS_TRINAMIC
98
+            if (index == 1) TMC_SET_PWMTHRS(X,X2);
99
+          #endif
100
+          break;
101
+        case Y_AXIS:
102
+          #if Y_IS_TRINAMIC
103
+            if (index == 0) TMC_SET_PWMTHRS(Y,Y);
104
+          #endif
105
+          #if Y2_IS_TRINAMIC
106
+            if (index == 1) TMC_SET_PWMTHRS(Y,Y2);
107
+          #endif
108
+          break;
109
+        case Z_AXIS:
110
+          #if Z_IS_TRINAMIC
111
+            if (index == 0) TMC_SET_PWMTHRS(Z,Z);
112
+          #endif
113
+          #if Z2_IS_TRINAMIC
114
+            if (index == 1) TMC_SET_PWMTHRS(Z,Z2);
115
+          #endif
116
+          break;
117
+        case E_AXIS: {
118
+          if (get_target_extruder_from_command()) return;
119
+          switch (target_extruder) {
120
+            #if E0_IS_TRINAMIC
121
+              case 0: TMC_SET_PWMTHRS_E(0); break;
122
+            #endif
123
+            #if E_STEPPERS > 1 && E1_IS_TRINAMIC
124
+              case 1: TMC_SET_PWMTHRS_E(1); break;
125
+            #endif
126
+            #if E_STEPPERS > 2 && E2_IS_TRINAMIC
127
+              case 2: TMC_SET_PWMTHRS_E(2); break;
128
+            #endif
129
+            #if E_STEPPERS > 3 && E3_IS_TRINAMIC
130
+              case 3: TMC_SET_PWMTHRS_E(3); break;
131
+            #endif
132
+            #if E_STEPPERS > 4 && E4_IS_TRINAMIC
133
+              case 4: TMC_SET_PWMTHRS_E(4); break;
134
+            #endif
135
+          }
136
+        } break;
137
+      }
138
+    }
89 139
 
90
-    #if X_IS_TRINAMIC
91
-      TMC_SET_GET_PWMTHRS(X,X);
92
-    #endif
93
-    #if X2_IS_TRINAMIC
94
-      TMC_SET_GET_PWMTHRS(X,X2);
95
-    #endif
96
-    #if Y_IS_TRINAMIC
97
-      TMC_SET_GET_PWMTHRS(Y,Y);
98
-    #endif
99
-    #if Y2_IS_TRINAMIC
100
-      TMC_SET_GET_PWMTHRS(Y,Y2);
101
-    #endif
102
-    #if Z_IS_TRINAMIC
103
-      TMC_SET_GET_PWMTHRS(Z,Z);
104
-    #endif
105
-    #if Z2_IS_TRINAMIC
106
-      TMC_SET_GET_PWMTHRS(Z,Z2);
107
-    #endif
108
-    #if E0_IS_TRINAMIC
109
-      TMC_SET_GET_PWMTHRS(E,E0);
110
-    #endif
111
-    #if E1_IS_TRINAMIC
112
-      TMC_SET_GET_PWMTHRS(E,E1);
113
-    #endif
114
-    #if E2_IS_TRINAMIC
115
-      TMC_SET_GET_PWMTHRS(E,E2);
116
-    #endif
117
-    #if E3_IS_TRINAMIC
118
-      TMC_SET_GET_PWMTHRS(E,E3);
119
-    #endif
120
-    #if E4_IS_TRINAMIC
121
-      TMC_SET_GET_PWMTHRS(E,E4);
122
-    #endif
140
+    if (report) LOOP_XYZE(i) switch (i) {
141
+      case X_AXIS:
142
+        #if X_IS_TRINAMIC
143
+          TMC_SAY_PWMTHRS(X,X);
144
+        #endif
145
+        #if X2_IS_TRINAMIC
146
+          TMC_SAY_PWMTHRS(X,X2);
147
+        #endif
148
+        break;
149
+      case Y_AXIS:
150
+        #if Y_IS_TRINAMIC
151
+          TMC_SAY_PWMTHRS(Y,Y);
152
+        #endif
153
+        #if Y2_IS_TRINAMIC
154
+          TMC_SAY_PWMTHRS(Y,Y2);
155
+        #endif
156
+        break;
157
+      case Z_AXIS:
158
+        #if Z_IS_TRINAMIC
159
+          TMC_SAY_PWMTHRS(Z,Z);
160
+        #endif
161
+        #if Z2_IS_TRINAMIC
162
+          TMC_SAY_PWMTHRS(Z,Z2);
163
+        #endif
164
+        break;
165
+      case E_AXIS:
166
+        #if E0_IS_TRINAMIC
167
+          TMC_SAY_PWMTHRS_E(0);
168
+        #endif
169
+        #if E_STEPPERS > 1 && E1_IS_TRINAMIC
170
+          TMC_SAY_PWMTHRS_E(1);
171
+        #endif
172
+        #if E_STEPPERS > 2 && E2_IS_TRINAMIC
173
+          TMC_SAY_PWMTHRS_E(2);
174
+        #endif
175
+        #if E_STEPPERS > 3 && E3_IS_TRINAMIC
176
+          TMC_SAY_PWMTHRS_E(3);
177
+        #endif
178
+        #if E_STEPPERS > 4 && E4_IS_TRINAMIC
179
+          TMC_SAY_PWMTHRS_E(4);
180
+        #endif
181
+        break;
182
+    }
123 183
   }
124 184
 #endif // HYBRID_THRESHOLD
125 185
 
@@ -128,34 +188,68 @@ void GcodeSuite::M912() {
128 188
  */
129 189
 #if ENABLED(SENSORLESS_HOMING)
130 190
   void GcodeSuite::M914() {
131
-    #define TMC_SET_GET_SGT(P,Q) do { \
132
-      if (parser.seen(axis_codes[P##_AXIS])) tmc_set_sgt(stepper##Q, TMC_##Q, parser.value_int()); \
133
-      else tmc_get_sgt(stepper##Q, TMC_##Q); } while(0)
134
-
135
-    #ifdef X_HOMING_SENSITIVITY
136
-      #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
137
-        TMC_SET_GET_SGT(X,X);
138
-      #endif
139
-      #if ENABLED(X2_IS_TMC2130)
140
-        TMC_SET_GET_SGT(X,X2);
141
-      #endif
142
-    #endif
143
-    #ifdef Y_HOMING_SENSITIVITY
144
-      #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)
145
-        TMC_SET_GET_SGT(Y,Y);
146
-      #endif
147
-      #if ENABLED(Y2_IS_TMC2130)
148
-        TMC_SET_GET_SGT(Y,Y2);
149
-      #endif
150
-    #endif
151
-    #ifdef Z_HOMING_SENSITIVITY
152
-      #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS)
153
-        TMC_SET_GET_SGT(Z,Z);
154
-      #endif
155
-      #if ENABLED(Z2_IS_TMC2130)
156
-        TMC_SET_GET_SGT(Z,Z2);
157
-      #endif
158
-    #endif
191
+    #define TMC_SAY_SGT(Q) tmc_get_sgt(stepper##Q, TMC_##Q)
192
+    #define TMC_SET_SGT(Q) tmc_set_sgt(stepper##Q, TMC_##Q, value)
193
+
194
+    bool report = true;
195
+    const uint8_t index = parser.byteval('I');
196
+    LOOP_XYZ(i) if (parser.seen(axis_codes[i])) {
197
+      const int8_t value = (int8_t)constrain(parser.value_int(), -63, 64);
198
+      report = false;
199
+      switch (i) {
200
+        case X_AXIS:
201
+          #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
202
+            if (index == 0) TMC_SET_SGT(X);
203
+          #endif
204
+          #if ENABLED(X2_IS_TMC2130)
205
+            if (index == 1) TMC_SET_SGT(X2);
206
+          #endif
207
+          break;
208
+        case Y_AXIS:
209
+          #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)
210
+            if (index == 0) TMC_SET_SGT(Y);
211
+          #endif
212
+          #if ENABLED(Y2_IS_TMC2130)
213
+            if (index == 1) TMC_SET_SGT(Y2);
214
+          #endif
215
+          break;
216
+        case Z_AXIS:
217
+          #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS)
218
+            if (index == 0) TMC_SET_SGT(Z);
219
+          #endif
220
+          #if ENABLED(Z2_IS_TMC2130)
221
+            if (index == 1) TMC_SET_SGT(Z2);
222
+          #endif
223
+          break;
224
+      }
225
+    }
226
+
227
+    if (report) LOOP_XYZ(i) switch (i) {
228
+      case X_AXIS:
229
+        #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
230
+          TMC_SAY_SGT(X);
231
+        #endif
232
+        #if ENABLED(X2_IS_TMC2130)
233
+          TMC_SAY_SGT(X2);
234
+        #endif
235
+        break;
236
+      case Y_AXIS:
237
+        #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)
238
+          TMC_SAY_SGT(Y);
239
+        #endif
240
+        #if ENABLED(Y2_IS_TMC2130)
241
+          TMC_SAY_SGT(Y2);
242
+        #endif
243
+        break;
244
+      case Z_AXIS:
245
+        #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS)
246
+          TMC_SAY_SGT(Z);
247
+        #endif
248
+        #if ENABLED(Z2_IS_TMC2130)
249
+          TMC_SAY_SGT(Z2);
250
+        #endif
251
+        break;
252
+    }
159 253
   }
160 254
 #endif // SENSORLESS_HOMING
161 255
 

+ 314
- 162
Marlin/src/module/configuration_store.cpp View File

@@ -37,7 +37,7 @@
37 37
  */
38 38
 
39 39
 // Change EEPROM version if the structure changes
40
-#define EEPROM_VERSION "V52"
40
+#define EEPROM_VERSION "V53"
41 41
 #define EEPROM_OFFSET 100
42 42
 
43 43
 // Check the integrity of data offsets.
@@ -74,8 +74,10 @@
74 74
   #include "../module/probe.h"
75 75
 #endif
76 76
 
77
-#if ENABLED(HAVE_TMC2130)
77
+#if HAS_TRINAMIC
78 78
   #include "stepper_indirection.h"
79
+  #include "../feature/tmc_util.h"
80
+  #define TMC_GET_PWMTHRS(P,Q) _tmc_thrs(stepper##Q.microsteps(), stepper##Q.TPWMTHRS(), planner.axis_steps_per_mm[P##_AXIS])
79 81
 #endif
80 82
 
81 83
 #if ENABLED(FWRETRACT)
@@ -230,7 +232,9 @@ typedef struct SettingsDataStruct {
230 232
   //
231 233
   // HAS_TRINAMIC
232 234
   //
233
-  uint16_t tmc_stepper_current[11];                     // M906 X Y Z X2 Y2 Z2 E0 E1 E2 E3 E4
235
+  #define TMC_AXES (MAX_EXTRUDERS + 6)
236
+  uint16_t tmc_stepper_current[TMC_AXES];               // M906 X Y Z X2 Y2 Z2 E0 E1 E2 E3 E4
237
+  uint32_t tmc_hybrid_threshold[TMC_AXES];              // M913 X Y Z X2 Y2 Z2 E0 E1 E2 E3 E4
234 238
   int16_t tmc_sgt[XYZ];                                 // M914 X Y Z
235 239
 
236 240
   //
@@ -658,7 +662,7 @@ void MarlinSettings::postprocess() {
658 662
 
659 663
     _FIELD_TEST(tmc_stepper_current);
660 664
 
661
-    uint16_t currents[11] = {
665
+    uint16_t tmc_stepper_current[TMC_AXES] = {
662 666
       #if HAS_TRINAMIC
663 667
         #if X_IS_TRINAMIC
664 668
           stepperX.getCurrent(),
@@ -719,24 +723,95 @@ void MarlinSettings::postprocess() {
719 723
         0
720 724
       #endif
721 725
     };
722
-    EEPROM_WRITE(currents);
726
+    EEPROM_WRITE(tmc_stepper_current);
727
+
728
+    //
729
+    // Save TMC2130 or TMC2208 Hybrid Threshold, and placeholder values
730
+    //
731
+
732
+    _FIELD_TEST(tmc_hybrid_threshold);
733
+
734
+    uint32_t tmc_hybrid_threshold[TMC_AXES] = {
735
+      #if HAS_TRINAMIC
736
+        #if X_IS_TRINAMIC
737
+          TMC_GET_PWMTHRS(X, X),
738
+        #else
739
+          X_HYBRID_THRESHOLD,
740
+        #endif
741
+        #if Y_IS_TRINAMIC
742
+          TMC_GET_PWMTHRS(Y, Y),
743
+        #else
744
+          Y_HYBRID_THRESHOLD,
745
+        #endif
746
+        #if Z_IS_TRINAMIC
747
+          TMC_GET_PWMTHRS(Z, Z),
748
+        #else
749
+          Z_HYBRID_THRESHOLD,
750
+        #endif
751
+        #if X2_IS_TRINAMIC
752
+          TMC_GET_PWMTHRS(X, X2),
753
+        #else
754
+          X2_HYBRID_THRESHOLD,
755
+        #endif
756
+        #if Y2_IS_TRINAMIC
757
+          TMC_GET_PWMTHRS(Y, Y2),
758
+        #else
759
+          Y2_HYBRID_THRESHOLD,
760
+        #endif
761
+        #if Z2_IS_TRINAMIC
762
+          TMC_GET_PWMTHRS(Z, Z2),
763
+        #else
764
+          Z2_HYBRID_THRESHOLD,
765
+        #endif
766
+        #if E0_IS_TRINAMIC
767
+          TMC_GET_PWMTHRS(E, E0),
768
+        #else
769
+          E0_HYBRID_THRESHOLD,
770
+        #endif
771
+        #if E1_IS_TRINAMIC
772
+          TMC_GET_PWMTHRS(E, E1),
773
+        #else
774
+          E1_HYBRID_THRESHOLD,
775
+        #endif
776
+        #if E2_IS_TRINAMIC
777
+          TMC_GET_PWMTHRS(E, E2),
778
+        #else
779
+          E2_HYBRID_THRESHOLD,
780
+        #endif
781
+        #if E3_IS_TRINAMIC
782
+          TMC_GET_PWMTHRS(E, E3),
783
+        #else
784
+          E3_HYBRID_THRESHOLD,
785
+        #endif
786
+        #if E4_IS_TRINAMIC
787
+          TMC_GET_PWMTHRS(E, E4)
788
+        #else
789
+          E4_HYBRID_THRESHOLD
790
+        #endif
791
+      #else
792
+        100, 100, 3,          // X, Y, Z
793
+        100, 100, 3,          // X2, Y2, Z2
794
+        30, 30, 30, 30, 30    // E0, E1, E2, E3, E4
795
+      #endif
796
+    };
797
+    EEPROM_WRITE(tmc_hybrid_threshold);
723 798
 
724 799
     //
725 800
     // TMC2130 Sensorless homing threshold
726 801
     //
727
-    int16_t thrs[XYZ] = {
802
+    int16_t tmc_sgt[XYZ] = {
728 803
       #if ENABLED(SENSORLESS_HOMING)
729
-        #if ENABLED(X_IS_TMC2130) && defined(X_HOMING_SENSITIVITY)
804
+        #if defined(X_HOMING_SENSITIVITY) && (ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS))
730 805
           stepperX.sgt(),
731 806
         #else
732 807
           0,
733 808
         #endif
734
-        #if ENABLED(Y_IS_TMC2130) && defined(Y_HOMING_SENSITIVITY)
809
+        #if defined(Y_HOMING_SENSITIVITY) && (ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS))
735 810
           stepperY.sgt(),
736 811
         #else
737 812
           0
738 813
         #endif
739
-        #if ENABLED(Z_IS_TMC2130) && defined(Z_HOMING_SENSITIVITY)
814
+        #if defined(Z_HOMING_SENSITIVITY) && (ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS))
740 815
           stepperZ.sgt()
741 816
         #else
742 817
           0
@@ -745,7 +820,7 @@ void MarlinSettings::postprocess() {
745 820
         0
746 821
       #endif
747 822
     };
748
-    EEPROM_WRITE(thrs);
823
+    EEPROM_WRITE(tmc_sgt);
749 824
 
750 825
     //
751 826
     // Linear Advance
@@ -794,7 +869,7 @@ void MarlinSettings::postprocess() {
794 869
       EEPROM_WRITE(planner.yz_skew_factor);
795 870
     #else
796 871
       dummy = 0.0f;
797
-      for (uint8_t q = XYZ; q--;) EEPROM_WRITE(dummy);
872
+      for (uint8_t q = 3; q--;) EEPROM_WRITE(dummy);
798 873
     #endif
799 874
 
800 875
     //
@@ -1197,54 +1272,101 @@ void MarlinSettings::postprocess() {
1197 1272
 
1198 1273
       #endif
1199 1274
 
1275
+      if (!validating) reset_stepper_drivers();
1276
+
1200 1277
       //
1201
-      // TMC2130 Stepper Current
1278
+      // TMC2130 Stepper Settings
1202 1279
       //
1203 1280
 
1204 1281
       _FIELD_TEST(tmc_stepper_current);
1205 1282
 
1206 1283
       #if HAS_TRINAMIC
1207
-        #define SET_CURR(N,Q) stepper##Q.setCurrent(currents[N] ? currents[N] : Q##_CURRENT, R_SENSE, HOLD_MULTIPLIER)
1208
-        uint16_t currents[11];
1284
+
1285
+        #define SET_CURR(Q) stepper##Q.setCurrent(currents[TMC_##Q] ? currents[TMC_##Q] : Q##_CURRENT, R_SENSE, HOLD_MULTIPLIER)
1286
+        uint16_t currents[TMC_AXES];
1209 1287
         EEPROM_READ(currents);
1210 1288
         if (!validating) {
1211 1289
           #if X_IS_TRINAMIC
1212
-            SET_CURR(0, X);
1290
+            SET_CURR(X);
1213 1291
           #endif
1214 1292
           #if Y_IS_TRINAMIC
1215
-            SET_CURR(1, Y);
1293
+            SET_CURR(Y);
1216 1294
           #endif
1217 1295
           #if Z_IS_TRINAMIC
1218
-            SET_CURR(2, Z);
1296
+            SET_CURR(Z);
1219 1297
           #endif
1220 1298
           #if X2_IS_TRINAMIC
1221
-            SET_CURR(3, X2);
1299
+            SET_CURR(X2);
1222 1300
           #endif
1223 1301
           #if Y2_IS_TRINAMIC
1224
-            SET_CURR(4, Y2);
1302
+            SET_CURR(Y2);
1225 1303
           #endif
1226 1304
           #if Z2_IS_TRINAMIC
1227
-            SET_CURR(5, Z2);
1305
+            SET_CURR(Z2);
1228 1306
           #endif
1229 1307
           #if E0_IS_TRINAMIC
1230
-            SET_CURR(6, E0);
1308
+            SET_CURR(E0);
1231 1309
           #endif
1232 1310
           #if E1_IS_TRINAMIC
1233
-            SET_CURR(7, E1);
1311
+            SET_CURR(E1);
1234 1312
           #endif
1235 1313
           #if E2_IS_TRINAMIC
1236
-            SET_CURR(8, E2);
1314
+            SET_CURR(E2);
1237 1315
           #endif
1238 1316
           #if E3_IS_TRINAMIC
1239
-            SET_CURR(9, E3);
1317
+            SET_CURR(E3);
1240 1318
           #endif
1241 1319
           #if E4_IS_TRINAMIC
1242
-            SET_CURR(10, E4);
1320
+            SET_CURR(E4);
1243 1321
           #endif
1244 1322
         }
1245 1323
       #else
1246 1324
         uint16_t val;
1247
-        for (uint8_t q=11; q--;) EEPROM_READ(val);
1325
+        for (uint8_t q=TMC_AXES; q--;) EEPROM_READ(val);
1326
+      #endif
1327
+
1328
+      #if HAS_TRINAMIC
1329
+        #define TMC_SET_PWMTHRS(P,Q) tmc_set_pwmthrs(stepper##Q, TMC_##Q, tmc_hybrid_threshold[TMC_##Q], planner.axis_steps_per_mm[P##_AXIS])
1330
+        uint16_t tmc_hybrid_threshold[TMC_AXES];
1331
+        EEPROM_READ(tmc_hybrid_threshold);
1332
+        if (!validating) {
1333
+          #if X_IS_TRINAMIC
1334
+            TMC_SET_PWMTHRS(X, X);
1335
+          #endif
1336
+          #if Y_IS_TRINAMIC
1337
+            TMC_SET_PWMTHRS(Y, Y);
1338
+          #endif
1339
+          #if Z_IS_TRINAMIC
1340
+            TMC_SET_PWMTHRS(Z, Z);
1341
+          #endif
1342
+          #if X2_IS_TRINAMIC
1343
+            TMC_SET_PWMTHRS(X, X2);
1344
+          #endif
1345
+          #if Y2_IS_TRINAMIC
1346
+            TMC_SET_PWMTHRS(Y, Y2);
1347
+          #endif
1348
+          #if Z2_IS_TRINAMIC
1349
+            TMC_SET_PWMTHRS(Z, Z2);
1350
+          #endif
1351
+          #if E0_IS_TRINAMIC
1352
+            TMC_SET_PWMTHRS(E, E0);
1353
+          #endif
1354
+          #if E1_IS_TRINAMIC
1355
+            TMC_SET_PWMTHRS(E, E1);
1356
+          #endif
1357
+          #if E2_IS_TRINAMIC
1358
+            TMC_SET_PWMTHRS(E, E2);
1359
+          #endif
1360
+          #if E3_IS_TRINAMIC
1361
+            TMC_SET_PWMTHRS(E, E3);
1362
+          #endif
1363
+          #if E4_IS_TRINAMIC
1364
+            TMC_SET_PWMTHRS(E, E4);
1365
+          #endif
1366
+        }
1367
+      #else
1368
+        uint16_t thrs_val;
1369
+        for (uint8_t q=TMC_AXES; q--;) EEPROM_READ(thrs_val);
1248 1370
       #endif
1249 1371
 
1250 1372
       /*
@@ -1253,32 +1375,32 @@ void MarlinSettings::postprocess() {
1253 1375
        * Y and Y2 use the same value
1254 1376
        * Z and Z2 use the same value
1255 1377
        */
1256
-      int16_t thrs[XYZ];
1257
-      EEPROM_READ(thrs);
1378
+      int16_t tmc_sgt[XYZ];
1379
+      EEPROM_READ(tmc_sgt);
1258 1380
       #if ENABLED(SENSORLESS_HOMING)
1259 1381
         if (!validating) {
1260 1382
           #ifdef X_HOMING_SENSITIVITY
1261
-            #if ENABLED(X_IS_TMC2130)
1262
-              stepperX.sgt(thrs[0]);
1383
+            #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
1384
+              stepperX.sgt(tmc_sgt[0]);
1263 1385
             #endif
1264 1386
             #if ENABLED(X2_IS_TMC2130)
1265
-              stepperX2.sgt(thrs[0]);
1387
+              stepperX2.sgt(tmc_sgt[0]);
1266 1388
             #endif
1267 1389
           #endif
1268 1390
           #ifdef Y_HOMING_SENSITIVITY
1269
-            #if ENABLED(Y_IS_TMC2130)
1270
-              stepperY.sgt(thrs[1]);
1391
+            #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)
1392
+              stepperY.sgt(tmc_sgt[1]);
1271 1393
             #endif
1272 1394
             #if ENABLED(Y2_IS_TMC2130)
1273
-              stepperY2.sgt(thrs[1]);
1395
+              stepperY2.sgt(tmc_sgt[1]);
1274 1396
             #endif
1275 1397
           #endif
1276 1398
           #ifdef Z_HOMING_SENSITIVITY
1277
-            #if ENABLED(Z_IS_TMC2130)
1278
-              stepperZ.sgt(thrs[2]);
1399
+            #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS)
1400
+              stepperZ.sgt(tmc_sgt[2]);
1279 1401
             #endif
1280 1402
             #if ENABLED(Z2_IS_TMC2130)
1281
-              stepperZ2.sgt(thrs[2]);
1403
+              stepperZ2.sgt(tmc_sgt[2]);
1282 1404
             #endif
1283 1405
           #endif
1284 1406
         }
@@ -1338,7 +1460,7 @@ void MarlinSettings::postprocess() {
1338 1460
           EEPROM_READ(dummy);
1339 1461
         #endif
1340 1462
       #else
1341
-        for (uint8_t q = XYZ; q--;) EEPROM_READ(dummy);
1463
+        for (uint8_t q = 3; q--;) EEPROM_READ(dummy);
1342 1464
       #endif
1343 1465
 
1344 1466
       //
@@ -1731,66 +1853,7 @@ void MarlinSettings::reset(PORTARG_SOLO) {
1731 1853
     #endif
1732 1854
   );
1733 1855
 
1734
-  #if X_IS_TRINAMIC
1735
-    stepperX.setCurrent(X_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1736
-  #endif
1737
-  #if Y_IS_TRINAMIC
1738
-    stepperY.setCurrent(Y_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1739
-  #endif
1740
-  #if Z_IS_TRINAMIC
1741
-    stepperZ.setCurrent(Z_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1742
-  #endif
1743
-  #if X2_IS_TRINAMIC
1744
-    stepperX2.setCurrent(X2_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1745
-  #endif
1746
-  #if Y2_IS_TRINAMIC
1747
-    stepperY2.setCurrent(Y2_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1748
-  #endif
1749
-  #if Z2_IS_TRINAMIC
1750
-    stepperZ2.setCurrent(Z2_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1751
-  #endif
1752
-  #if E0_IS_TRINAMIC
1753
-    stepperE0.setCurrent(E0_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1754
-  #endif
1755
-  #if E1_IS_TRINAMIC
1756
-    stepperE1.setCurrent(E1_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1757
-  #endif
1758
-  #if E2_IS_TRINAMIC
1759
-    stepperE2.setCurrent(E2_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1760
-  #endif
1761
-  #if E3_IS_TRINAMIC
1762
-    stepperE3.setCurrent(E3_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1763
-  #endif
1764
-  #if E4_IS_TRINAMIC
1765
-    stepperE4.setCurrent(E4_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1766
-  #endif
1767
-
1768
-  #if ENABLED(SENSORLESS_HOMING)
1769
-    #ifdef X_HOMING_SENSITIVITY
1770
-      #if ENABLED(X_IS_TMC2130)
1771
-        stepperX.sgt(X_HOMING_SENSITIVITY);
1772
-      #endif
1773
-      #if ENABLED(X2_IS_TMC2130)
1774
-        stepperX2.sgt(X_HOMING_SENSITIVITY);
1775
-      #endif
1776
-    #endif
1777
-    #ifdef Y_HOMING_SENSITIVITY
1778
-      #if ENABLED(Y_IS_TMC2130)
1779
-        stepperY.sgt(Y_HOMING_SENSITIVITY);
1780
-      #endif
1781
-      #if ENABLED(Y2_IS_TMC2130)
1782
-        stepperY2.sgt(Y_HOMING_SENSITIVITY);
1783
-      #endif
1784
-    #endif
1785
-    #ifdef Z_HOMING_SENSITIVITY
1786
-      #if ENABLED(Z_IS_TMC2130)
1787
-        stepperZ.sgt(Z_HOMING_SENSITIVITY);
1788
-      #endif
1789
-      #if ENABLED(Z2_IS_TMC2130)
1790
-        stepperZ2.sgt(Z_HOMING_SENSITIVITY);
1791
-      #endif
1792
-    #endif
1793
-  #endif
1856
+  reset_stepper_drivers();
1794 1857
 
1795 1858
   #if ENABLED(LIN_ADVANCE)
1796 1859
     planner.extruder_advance_K = LIN_ADVANCE_K;
@@ -1829,6 +1892,18 @@ void MarlinSettings::reset(PORTARG_SOLO) {
1829 1892
 
1830 1893
   #define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START_P(port); }while(0)
1831 1894
 
1895
+  #if HAS_TRINAMIC
1896
+    void say_M906() { SERIAL_ECHOPGM_P(port, "  M906 "); }
1897
+    void say_M913() { SERIAL_ECHOPGM_P(port, "  M913 "); }
1898
+    #if ENABLED(SENSORLESS_HOMING)
1899
+      void say_M914() { SERIAL_ECHOPGM_P(port, "  M914 "); }
1900
+    #endif
1901
+  #endif
1902
+
1903
+  #if ENABLED(ADVANCED_PAUSE_FEATURE)
1904
+    void say_M603() { SERIAL_ECHOPGM_P(port, "  M603 "); }
1905
+  #endif
1906
+
1832 1907
   /**
1833 1908
    * M503 - Report current settings in RAM
1834 1909
    *
@@ -1849,7 +1924,7 @@ void MarlinSettings::reset(PORTARG_SOLO) {
1849 1924
       SERIAL_ECHOPGM_P(port, "  G2");
1850 1925
       SERIAL_CHAR_P(port, parser.linear_unit_factor == 1.0 ? '1' : '0');
1851 1926
       SERIAL_ECHOPGM_P(port, " ; Units in ");
1852
-      serialprintPGM(parser.linear_unit_factor == 1.0 ? PSTR("mm\n") : PSTR("inches\n"));
1927
+      serialprintPGM_P(port, parser.linear_unit_factor == 1.0 ? PSTR("mm\n") : PSTR("inches\n"));
1853 1928
     #else
1854 1929
       #define LINEAR_UNIT(N) (N)
1855 1930
       #define VOLUMETRIC_UNIT(N) (N)
@@ -2076,7 +2151,7 @@ void MarlinSettings::reset(PORTARG_SOLO) {
2076 2151
               SERIAL_ECHOPAIR_P(port, "  G29 S3 X", (int)px + 1);
2077 2152
               SERIAL_ECHOPAIR_P(port, " Y", (int)py + 1);
2078 2153
               SERIAL_ECHOPGM_P(port, " Z");
2079
-              SERIAL_PROTOCOL_F_P(port, LINEAR_UNIT(mbl.z_values[px][py]), 5);
2154
+              SERIAL_ECHO_F_P(port, LINEAR_UNIT(mbl.z_values[px][py]), 5);
2080 2155
               SERIAL_EOL_P(port);
2081 2156
             }
2082 2157
           }
@@ -2103,7 +2178,7 @@ void MarlinSettings::reset(PORTARG_SOLO) {
2103 2178
               SERIAL_ECHOPAIR_P(port, "  G29 W I", (int)px + 1);
2104 2179
               SERIAL_ECHOPAIR_P(port, " J", (int)py + 1);
2105 2180
               SERIAL_ECHOPGM_P(port, " Z");
2106
-              SERIAL_PROTOCOL_F_P(port, LINEAR_UNIT(z_values[px][py]), 5);
2181
+              SERIAL_ECHO_F_P(port, LINEAR_UNIT(z_values[px][py]), 5);
2107 2182
               SERIAL_EOL_P(port);
2108 2183
             }
2109 2184
           }
@@ -2289,95 +2364,166 @@ void MarlinSettings::reset(PORTARG_SOLO) {
2289 2364
         SERIAL_ECHOPGM_P(port, " K");
2290 2365
         SERIAL_ECHO_F_P(port, LINEAR_UNIT(planner.yz_skew_factor), 6);
2291 2366
         SERIAL_EOL_P(port);
2292
-       #else
2367
+      #else
2293 2368
         SERIAL_ECHOPGM_P(port, "  M852 S");
2294 2369
         SERIAL_ECHO_F_P(port, LINEAR_UNIT(planner.xy_skew_factor), 6);
2295 2370
         SERIAL_EOL_P(port);
2296 2371
       #endif
2297 2372
     #endif
2298 2373
 
2299
-    /**
2300
-     * TMC2130 stepper driver current
2301
-     */
2302 2374
     #if HAS_TRINAMIC
2375
+
2376
+      /**
2377
+       * TMC2130 / TMC2208 / TRAMS stepper driver current
2378
+       */
2303 2379
       if (!forReplay) {
2304 2380
         CONFIG_ECHO_START;
2305 2381
         SERIAL_ECHOLNPGM_P(port, "Stepper driver current:");
2306 2382
       }
2307 2383
       CONFIG_ECHO_START;
2308
-      SERIAL_ECHOPGM_P(port, "  M906");
2309
-      #if ENABLED(X_IS_TMC2130) || ENABLED(X_IS_TMC2208)
2310
-        SERIAL_ECHOPAIR_P(port, " X ", stepperX.getCurrent());
2384
+      #if X_IS_TRINAMIC
2385
+        say_M906();
2386
+        SERIAL_ECHOLNPAIR_P(port, "X", stepperX.getCurrent());
2311 2387
       #endif
2312
-      #if ENABLED(Y_IS_TMC2130) || ENABLED(Y_IS_TMC2208)
2313
-        SERIAL_ECHOPAIR_P(port, " Y ", stepperY.getCurrent());
2388
+      #if X2_IS_TRINAMIC
2389
+        say_M906();
2390
+        SERIAL_ECHOLNPAIR_P(port, "I1 X", stepperX2.getCurrent());
2314 2391
       #endif
2315
-      #if ENABLED(Z_IS_TMC2130) || ENABLED(Z_IS_TMC2208)
2316
-        SERIAL_ECHOPAIR_P(port, " Z ", stepperZ.getCurrent());
2392
+      #if Y_IS_TRINAMIC
2393
+        say_M906();
2394
+        SERIAL_ECHOLNPAIR_P(port, "Y", stepperY.getCurrent());
2317 2395
       #endif
2318
-      #if ENABLED(X2_IS_TMC2130) || ENABLED(X2_IS_TMC2208)
2319
-        SERIAL_ECHOPAIR_P(port, " X2 ", stepperX2.getCurrent());
2396
+      #if Y2_IS_TRINAMIC
2397
+        say_M906();
2398
+        SERIAL_ECHOLNPAIR_P(port, "I1 Y", stepperY2.getCurrent());
2320 2399
       #endif
2321
-      #if ENABLED(Y2_IS_TMC2130) || ENABLED(Y2_IS_TMC2208)
2322
-        SERIAL_ECHOPAIR_P(port, " Y2 ", stepperY2.getCurrent());
2400
+      #if Z_IS_TRINAMIC
2401
+        say_M906();
2402
+        SERIAL_ECHOLNPAIR_P(port, "Z", stepperZ.getCurrent());
2323 2403
       #endif
2324
-      #if ENABLED(Z2_IS_TMC2130) || ENABLED(Z2_IS_TMC2208)
2325
-        SERIAL_ECHOPAIR_P(port, " Z2 ", stepperZ2.getCurrent());
2404
+      #if Z2_IS_TRINAMIC
2405
+        say_M906();
2406
+        SERIAL_ECHOLNPAIR_P(port, "I1 Z", stepperZ2.getCurrent());
2326 2407
       #endif
2327
-      #if ENABLED(E0_IS_TMC2130) || ENABLED(E0_IS_TMC2208)
2328
-        SERIAL_ECHOPAIR_P(port, " E0 ", stepperE0.getCurrent());
2408
+      #if E0_IS_TRINAMIC
2409
+        say_M906();
2410
+        SERIAL_ECHOLNPAIR_P(port, "T0 E", stepperE0.getCurrent());
2329 2411
       #endif
2330
-      #if ENABLED(E1_IS_TMC2130) || ENABLED(E1_IS_TMC2208)
2331
-        SERIAL_ECHOPAIR_P(port, " E1 ", stepperE1.getCurrent());
2412
+      #if E_STEPPERS > 1 && E1_IS_TRINAMIC
2413
+        say_M906();
2414
+        SERIAL_ECHOLNPAIR_P(port, "T1 E", stepperE1.getCurrent());
2332 2415
       #endif
2333
-      #if ENABLED(E2_IS_TMC2130) || ENABLED(E2_IS_TMC2208)
2334
-        SERIAL_ECHOPAIR_P(port, " E2 ", stepperE2.getCurrent());
2416
+      #if E_STEPPERS > 2 && E2_IS_TRINAMIC
2417
+        say_M906();
2418
+        SERIAL_ECHOLNPAIR_P(port, "T2 E", stepperE2.getCurrent());
2335 2419
       #endif
2336
-      #if ENABLED(E3_IS_TMC2130) || ENABLED(E3_IS_TMC2208)
2337
-        SERIAL_ECHOPAIR_P(port, " E3 ", stepperE3.getCurrent());
2420
+      #if E_STEPPERS > 3 && E3_IS_TRINAMIC
2421
+        say_M906();
2422
+        SERIAL_ECHOLNPAIR_P(port, "T3 E", stepperE3.getCurrent());
2338 2423
       #endif
2339
-      #if ENABLED(E4_IS_TMC2130) || ENABLED(E4_IS_TMC2208)
2340
-        SERIAL_ECHOPAIR_P(port, " E4 ", stepperE4.getCurrent());
2424
+      #if E_STEPPERS > 4 && E4_IS_TRINAMIC
2425
+        say_M906();
2426
+        SERIAL_ECHOLNPAIR_P(port, "T4 E", stepperE4.getCurrent());
2341 2427
       #endif
2342 2428
       SERIAL_EOL_P(port);
2343
-    #endif
2344 2429
 
2345
-    /**
2346
-     * TMC2130 Sensorless homing thresholds
2347
-     */
2348
-    #if ENABLED(SENSORLESS_HOMING)
2430
+      /**
2431
+       * TMC2130 / TMC2208 / TRAMS Hybrid Threshold
2432
+       */
2349 2433
       if (!forReplay) {
2350 2434
         CONFIG_ECHO_START;
2351
-        SERIAL_ECHOLNPGM_P(port, "Sensorless homing threshold:");
2435
+        SERIAL_ECHOLNPGM_P(port, "Hybrid Threshold:");
2352 2436
       }
2353 2437
       CONFIG_ECHO_START;
2354
-      SERIAL_ECHOPGM_P(port, "  M914");
2355
-      #ifdef X_HOMING_SENSITIVITY
2356
-        #if ENABLED(X_IS_TMC2130)
2357
-          SERIAL_ECHOPAIR_P(port, " X", stepperX.sgt());
2358
-        #endif
2359
-        #if ENABLED(X2_IS_TMC2130)
2360
-          SERIAL_ECHOPAIR_P(port, " X2 ", stepperX2.sgt());
2361
-        #endif
2438
+      #if X_IS_TRINAMIC
2439
+        say_M913();
2440
+        SERIAL_ECHOLNPAIR_P(port, "X", TMC_GET_PWMTHRS(X, X));
2362 2441
       #endif
2363
-      #ifdef Y_HOMING_SENSITIVITY
2364
-        #if ENABLED(Y_IS_TMC2130)
2365
-          SERIAL_ECHOPAIR_P(port, " Y", stepperY.sgt());
2366
-        #endif
2367
-        #if ENABLED(Y2_IS_TMC2130)
2368
-          SERIAL_ECHOPAIR_P(port, " Y2 ", stepperY2.sgt());
2369
-        #endif
2442
+      #if X2_IS_TRINAMIC
2443
+        say_M913();
2444
+        SERIAL_ECHOLNPAIR_P(port, "I1 X", TMC_GET_PWMTHRS(X, X2));
2445
+      #endif
2446
+      #if Y_IS_TRINAMIC
2447
+        say_M913();
2448
+        SERIAL_ECHOLNPAIR_P(port, "Y", TMC_GET_PWMTHRS(Y, Y));
2449
+      #endif
2450
+      #if Y2_IS_TRINAMIC
2451
+        say_M913();
2452
+        SERIAL_ECHOLNPAIR_P(port, "I1 Y", TMC_GET_PWMTHRS(Y, Y2));
2370 2453
       #endif
2371
-      #ifdef Z_HOMING_SENSITIVITY
2372
-        #if ENABLED(Z_IS_TMC2130)
2373
-          SERIAL_ECHOPAIR_P(port, " Z ", stepperZ.sgt());
2454
+      #if Z_IS_TRINAMIC
2455
+        say_M913();
2456
+        SERIAL_ECHOLNPAIR_P(port, "Z", TMC_GET_PWMTHRS(Z, Z));
2457
+      #endif
2458
+      #if Z2_IS_TRINAMIC
2459
+        say_M913();
2460
+        SERIAL_ECHOLNPAIR_P(port, "I1 Z", TMC_GET_PWMTHRS(Z, Z2));
2461
+      #endif
2462
+      #if E0_IS_TRINAMIC
2463
+        say_M913();
2464
+        SERIAL_ECHOLNPAIR_P(port, "T0 E", TMC_GET_PWMTHRS(E, E0));
2465
+      #endif
2466
+      #if E_STEPPERS > 1 && E1_IS_TRINAMIC
2467
+        say_M913();
2468
+        SERIAL_ECHOLNPAIR_P(port, "T1 E", TMC_GET_PWMTHRS(E, E1));
2469
+      #endif
2470
+      #if E_STEPPERS > 2 && E2_IS_TRINAMIC
2471
+        say_M913();
2472
+        SERIAL_ECHOLNPAIR_P(port, "T2 E", TMC_GET_PWMTHRS(E, E2));
2473
+      #endif
2474
+      #if E_STEPPERS > 3 && E3_IS_TRINAMIC
2475
+        say_M913();
2476
+        SERIAL_ECHOLNPAIR_P(port, "T3 E", TMC_GET_PWMTHRS(E, E3));
2477
+      #endif
2478
+      #if E_STEPPERS > 4 && E4_IS_TRINAMIC
2479
+        say_M913();
2480
+        SERIAL_ECHOLNPAIR_P(port, "T4 E", TMC_GET_PWMTHRS(E, E4));
2481
+      #endif
2482
+      SERIAL_EOL_P(port);
2483
+
2484
+      /**
2485
+       * TMC2130 Sensorless homing thresholds
2486
+       */
2487
+      #if ENABLED(SENSORLESS_HOMING)
2488
+        if (!forReplay) {
2489
+          CONFIG_ECHO_START;
2490
+          SERIAL_ECHOLNPGM_P(port, "Sensorless homing threshold:");
2491
+        }
2492
+        CONFIG_ECHO_START;
2493
+        #ifdef X_HOMING_SENSITIVITY
2494
+          #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
2495
+            say_M914();
2496
+            SERIAL_ECHOLNPAIR_P(port, "X", stepperX.sgt());
2497
+          #endif
2498
+          #if ENABLED(X2_IS_TMC2130)
2499
+            say_M914();
2500
+            SERIAL_ECHOLNPAIR_P(port, "I1 X", stepperX2.sgt());
2501
+          #endif
2374 2502
         #endif
2375
-        #if ENABLED(Z2_IS_TMC2130)
2376
-          SERIAL_ECHOPAIR_P(port, " Z2 ", stepperZ2.sgt());
2503
+        #ifdef Y_HOMING_SENSITIVITY
2504
+          #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)
2505
+            say_M914();
2506
+            SERIAL_ECHOLNPAIR_P(port, "Y", stepperY.sgt());
2507
+          #endif
2508
+          #if ENABLED(Y2_IS_TMC2130)
2509
+            say_M914();
2510
+            SERIAL_ECHOLNPAIR_P(port, "I1 Y", stepperY2.sgt());
2511
+          #endif
2512
+        #endif
2513
+        #ifdef Z_HOMING_SENSITIVITY
2514
+          #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS)
2515
+            say_M914();
2516
+            SERIAL_ECHOLNPAIR_P(port, "Z", stepperZ.sgt());
2517
+          #endif
2518
+          #if ENABLED(Z2_IS_TMC2130)
2519
+            say_M914();
2520
+            SERIAL_ECHOLNPAIR_P(port, "I1 Z", stepperZ2.sgt());
2521
+          #endif
2377 2522
         #endif
2523
+        SERIAL_EOL_P(port);
2378 2524
       #endif
2379
-      SERIAL_EOL_P(port);
2380
-    #endif
2525
+
2526
+    #endif // HAS_TRINAMIC
2381 2527
 
2382 2528
     /**
2383 2529
      * Linear Advance
@@ -2413,25 +2559,31 @@ void MarlinSettings::reset(PORTARG_SOLO) {
2413 2559
       }
2414 2560
       CONFIG_ECHO_START;
2415 2561
       #if EXTRUDERS == 1
2416
-        SERIAL_ECHOPAIR_P(port, "  M603 L", LINEAR_UNIT(filament_change_load_length[0]));
2562
+        say_M603();
2563
+        SERIAL_ECHOPAIR_P(port, "L", LINEAR_UNIT(filament_change_load_length[0]));
2417 2564
         SERIAL_ECHOLNPAIR_P(port, " U", LINEAR_UNIT(filament_change_unload_length[0]));
2418 2565
       #else
2419
-        SERIAL_ECHOPAIR_P(port, "  M603 T0 L", LINEAR_UNIT(filament_change_load_length[0]));
2566
+        say_M603();
2567
+        SERIAL_ECHOPAIR_P(port, "T0 L", LINEAR_UNIT(filament_change_load_length[0]));
2420 2568
         SERIAL_ECHOLNPAIR_P(port, " U", LINEAR_UNIT(filament_change_unload_length[0]));
2421 2569
         CONFIG_ECHO_START;
2422
-        SERIAL_ECHOPAIR_P(port, "  M603 T1 L", LINEAR_UNIT(filament_change_load_length[1]));
2570
+        say_M603();
2571
+        SERIAL_ECHOPAIR_P(port, "T1 L", LINEAR_UNIT(filament_change_load_length[1]));
2423 2572
         SERIAL_ECHOLNPAIR_P(port, " U", LINEAR_UNIT(filament_change_unload_length[1]));
2424 2573
         #if EXTRUDERS > 2
2425 2574
           CONFIG_ECHO_START;
2426
-          SERIAL_ECHOPAIR_P(port, "  M603 T2 L", LINEAR_UNIT(filament_change_load_length[2]));
2575
+          say_M603();
2576
+          SERIAL_ECHOPAIR_P(port, "T2 L", LINEAR_UNIT(filament_change_load_length[2]));
2427 2577
           SERIAL_ECHOLNPAIR_P(port, " U", LINEAR_UNIT(filament_change_unload_length[2]));
2428 2578
           #if EXTRUDERS > 3
2429 2579
             CONFIG_ECHO_START;
2430
-            SERIAL_ECHOPAIR_P(port, "  M603 T3 L", LINEAR_UNIT(filament_change_load_length[3]));
2580
+            say_M603();
2581
+            SERIAL_ECHOPAIR_P(port, "T3 L", LINEAR_UNIT(filament_change_load_length[3]));
2431 2582
             SERIAL_ECHOLNPAIR_P(port, " U", LINEAR_UNIT(filament_change_unload_length[3]));
2432 2583
             #if EXTRUDERS > 4
2433 2584
               CONFIG_ECHO_START;
2434
-              SERIAL_ECHOPAIR_P(port, "  M603 T4 L", LINEAR_UNIT(filament_change_load_length[4]));
2585
+              say_M603();
2586
+              SERIAL_ECHOPAIR_P(port, "T4 L", LINEAR_UNIT(filament_change_load_length[4]));
2435 2587
               SERIAL_ECHOLNPAIR_P(port, " U", LINEAR_UNIT(filament_change_unload_length[4]));
2436 2588
             #endif // EXTRUDERS > 4
2437 2589
           #endif // EXTRUDERS > 3

+ 0
- 25
Marlin/src/module/stepper.cpp View File

@@ -921,31 +921,6 @@ void Stepper::init() {
921 921
     microstep_init();
922 922
   #endif
923 923
 
924
-  // Init TMC Steppers
925
-  #if ENABLED(HAVE_TMC26X)
926
-    tmc26x_init();
927
-  #endif
928
-
929
-  // Init TMC2130 Steppers
930
-  #if ENABLED(HAVE_TMC2130)
931
-    tmc2130_init();
932
-  #endif
933
-
934
-  // Init TMC2208 Steppers
935
-  #if ENABLED(HAVE_TMC2208)
936
-    tmc2208_init();
937
-  #endif
938
-
939
-  // TRAMS, TMC2130 and TMC2208 advanced settings
940
-  #if HAS_TRINAMIC
941
-    TMC_ADV()
942
-  #endif
943
-
944
-  // Init L6470 Steppers
945
-  #if ENABLED(HAVE_L6470DRIVER)
946
-    L6470_init();
947
-  #endif
948
-
949 924
   // Init Dir Pins
950 925
   #if HAS_X_DIR
951 926
     X_DIR_INIT;

+ 125
- 76
Marlin/src/module/stepper_indirection.cpp View File

@@ -47,83 +47,82 @@
47 47
     #include <TMC26XStepper.h>
48 48
   #endif
49 49
 
50
-  #define _TMC_DEFINE(ST) TMC26XStepper stepper##ST(200, ST##_ENABLE_PIN, ST##_STEP_PIN, ST##_DIR_PIN, ST##_MAX_CURRENT, ST##_SENSE_RESISTOR)
50
+  #define _TMC26X_DEFINE(ST) TMC26XStepper stepper##ST(200, ST##_ENABLE_PIN, ST##_STEP_PIN, ST##_DIR_PIN, ST##_MAX_CURRENT, ST##_SENSE_RESISTOR)
51 51
 
52 52
   #if ENABLED(X_IS_TMC26X)
53
-    _TMC_DEFINE(X);
53
+    _TMC26X_DEFINE(X);
54 54
   #endif
55 55
   #if ENABLED(X2_IS_TMC26X)
56
-    _TMC_DEFINE(X2);
56
+    _TMC26X_DEFINE(X2);
57 57
   #endif
58 58
   #if ENABLED(Y_IS_TMC26X)
59
-    _TMC_DEFINE(Y);
59
+    _TMC26X_DEFINE(Y);
60 60
   #endif
61 61
   #if ENABLED(Y2_IS_TMC26X)
62
-    _TMC_DEFINE(Y2);
62
+    _TMC26X_DEFINE(Y2);
63 63
   #endif
64 64
   #if ENABLED(Z_IS_TMC26X)
65
-    _TMC_DEFINE(Z);
65
+    _TMC26X_DEFINE(Z);
66 66
   #endif
67 67
   #if ENABLED(Z2_IS_TMC26X)
68
-    _TMC_DEFINE(Z2);
68
+    _TMC26X_DEFINE(Z2);
69 69
   #endif
70 70
   #if ENABLED(E0_IS_TMC26X)
71
-    _TMC_DEFINE(E0);
71
+    _TMC26X_DEFINE(E0);
72 72
   #endif
73 73
   #if ENABLED(E1_IS_TMC26X)
74
-    _TMC_DEFINE(E1);
74
+    _TMC26X_DEFINE(E1);
75 75
   #endif
76 76
   #if ENABLED(E2_IS_TMC26X)
77
-    _TMC_DEFINE(E2);
77
+    _TMC26X_DEFINE(E2);
78 78
   #endif
79 79
   #if ENABLED(E3_IS_TMC26X)
80
-    _TMC_DEFINE(E3);
80
+    _TMC26X_DEFINE(E3);
81 81
   #endif
82 82
   #if ENABLED(E4_IS_TMC26X)
83
-    _TMC_DEFINE(E4);
83
+    _TMC26X_DEFINE(E4);
84 84
   #endif
85 85
 
86
-  #define _TMC_INIT(A) do{ \
86
+  #define _TMC26X_INIT(A) do{ \
87 87
     stepper##A.setMicrosteps(A##_MICROSTEPS); \
88 88
     stepper##A.start(); \
89 89
   }while(0)
90 90
 
91
-  void tmc26x_init() {
91
+  void tmc26x_init_to_defaults() {
92 92
     #if ENABLED(X_IS_TMC26X)
93
-      _TMC_INIT(X);
93
+      _TMC26X_INIT(X);
94 94
     #endif
95 95
     #if ENABLED(X2_IS_TMC26X)
96
-      _TMC_INIT(X2);
96
+      _TMC26X_INIT(X2);
97 97
     #endif
98 98
     #if ENABLED(Y_IS_TMC26X)
99
-      _TMC_INIT(Y);
99
+      _TMC26X_INIT(Y);
100 100
     #endif
101 101
     #if ENABLED(Y2_IS_TMC26X)
102
-      _TMC_INIT(Y2);
102
+      _TMC26X_INIT(Y2);
103 103
     #endif
104 104
     #if ENABLED(Z_IS_TMC26X)
105
-      _TMC_INIT(Z);
105
+      _TMC26X_INIT(Z);
106 106
     #endif
107 107
     #if ENABLED(Z2_IS_TMC26X)
108
-      _TMC_INIT(Z2);
108
+      _TMC26X_INIT(Z2);
109 109
     #endif
110 110
     #if ENABLED(E0_IS_TMC26X)
111
-      _TMC_INIT(E0);
111
+      _TMC26X_INIT(E0);
112 112
     #endif
113 113
     #if ENABLED(E1_IS_TMC26X)
114
-      _TMC_INIT(E1);
114
+      _TMC26X_INIT(E1);
115 115
     #endif
116 116
     #if ENABLED(E2_IS_TMC26X)
117
-      _TMC_INIT(E2);
117
+      _TMC26X_INIT(E2);
118 118
     #endif
119 119
     #if ENABLED(E3_IS_TMC26X)
120
-      _TMC_INIT(E3);
120
+      _TMC26X_INIT(E3);
121 121
     #endif
122 122
     #if ENABLED(E4_IS_TMC26X)
123
-      _TMC_INIT(E4);
123
+      _TMC26X_INIT(E4);
124 124
     #endif
125 125
   }
126
-
127 126
 #endif // HAVE_TMC26X
128 127
 
129 128
 //
@@ -180,9 +179,9 @@
180 179
   // Use internal reference voltage for current calculations. This is the default.
181 180
   // Following values from Trinamic's spreadsheet with values for a NEMA17 (42BYGHW609)
182 181
   // https://www.trinamic.com/products/integrated-circuits/details/tmc2130/
183
-  void tmc2130_init(TMC2130Stepper &st, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
182
+  void tmc2130_init(TMC2130Stepper &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
184 183
     st.begin();
185
-    st.setCurrent(st.getCurrent(), R_SENSE, HOLD_MULTIPLIER);
184
+    st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
186 185
     st.microsteps(microsteps);
187 186
     st.blank_time(24);
188 187
     st.off_time(5); // Only enables the driver if used with stealthChop
@@ -209,9 +208,9 @@
209 208
     st.GSTAT(); // Clear GSTAT
210 209
   }
211 210
 
212
-  #define _TMC2130_INIT(ST, SPMM) tmc2130_init(stepper##ST, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, SPMM)
211
+  #define _TMC2130_INIT(ST, SPMM) tmc2130_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, SPMM)
213 212
 
214
-  void tmc2130_init() {
213
+  void tmc2130_init_to_defaults() {
215 214
     #if ENABLED(X_IS_TMC2130)
216 215
       _TMC2130_INIT( X, planner.axis_steps_per_mm[X_AXIS]);
217 216
     #endif
@@ -234,34 +233,45 @@
234 233
       _TMC2130_INIT(E0, planner.axis_steps_per_mm[E_AXIS]);
235 234
     #endif
236 235
     #if ENABLED(E1_IS_TMC2130)
237
-      _TMC2130_INIT(E1, planner.axis_steps_per_mm[E_AXIS
238
-        #if ENABLED(DISTINCT_E_FACTORS)
239
-          + 1
240
-        #endif
241
-      ]);
236
+      { constexpr int extruder = 1; _TMC2130_INIT(E1, planner.axis_steps_per_mm[E_AXIS_N]); }
242 237
     #endif
243 238
     #if ENABLED(E2_IS_TMC2130)
244
-      _TMC2130_INIT(E2, planner.axis_steps_per_mm[E_AXIS
245
-        #if ENABLED(DISTINCT_E_FACTORS)
246
-          + 2
247
-        #endif
248
-      ]);
239
+      { constexpr int extruder = 2; _TMC2130_INIT(E2, planner.axis_steps_per_mm[E_AXIS_N]); }
249 240
     #endif
250 241
     #if ENABLED(E3_IS_TMC2130)
251
-      _TMC2130_INIT(E3, planner.axis_steps_per_mm[E_AXIS
252
-        #if ENABLED(DISTINCT_E_FACTORS)
253
-          + 3
254
-        #endif
255
-      ]);
242
+      { constexpr int extruder = 3; _TMC2130_INIT(E3, planner.axis_steps_per_mm[E_AXIS_N]); }
256 243
     #endif
257 244
     #if ENABLED(E4_IS_TMC2130)
258
-      _TMC2130_INIT(E4, planner.axis_steps_per_mm[E_AXIS
259
-        #if ENABLED(DISTINCT_E_FACTORS)
260
-          + 4
261
-        #endif
262
-      ]);
245
+      { constexpr int extruder = 4; _TMC2130_INIT(E4, planner.axis_steps_per_mm[E_AXIS_N]); }
263 246
     #endif
264 247
 
248
+    #if ENABLED(SENSORLESS_HOMING)
249
+      #define TMC_INIT_SGT(P,Q) stepper##Q.sgt(P##_HOMING_SENSITIVITY);
250
+      #ifdef X_HOMING_SENSITIVITY
251
+        #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
252
+          stepperX.sgt(X_HOMING_SENSITIVITY);
253
+        #endif
254
+        #if ENABLED(X2_IS_TMC2130)
255
+          stepperX2.sgt(X_HOMING_SENSITIVITY);
256
+        #endif
257
+      #endif
258
+      #ifdef Y_HOMING_SENSITIVITY
259
+        #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)
260
+          stepperY.sgt(Y_HOMING_SENSITIVITY);
261
+        #endif
262
+        #if ENABLED(Y2_IS_TMC2130)
263
+          stepperY2.sgt(Y_HOMING_SENSITIVITY);
264
+        #endif
265
+      #endif
266
+      #ifdef Z_HOMING_SENSITIVITY
267
+        #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS)
268
+          stepperZ.sgt(Z_HOMING_SENSITIVITY);
269
+        #endif
270
+        #if ENABLED(Z2_IS_TMC2130)
271
+          stepperZ2.sgt(Z_HOMING_SENSITIVITY);
272
+        #endif
273
+      #endif
274
+    #endif
265 275
   }
266 276
 #endif // HAVE_TMC2130
267 277
 
@@ -396,11 +406,11 @@
396 406
 
397 407
   // Use internal reference voltage for current calculations. This is the default.
398 408
   // Following values from Trinamic's spreadsheet with values for a NEMA17 (42BYGHW609)
399
-  void tmc2208_init(TMC2208Stepper &st, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
409
+  void tmc2208_init(TMC2208Stepper &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
400 410
     st.pdn_disable(true); // Use UART
401 411
     st.mstep_reg_select(true); // Select microsteps with UART
402 412
     st.I_scale_analog(false);
403
-    st.rms_current(st.getCurrent(), HOLD_MULTIPLIER, R_SENSE);
413
+    st.rms_current(mA, HOLD_MULTIPLIER, R_SENSE);
404 414
     st.microsteps(microsteps);
405 415
     st.blank_time(24);
406 416
     st.toff(5);
@@ -430,9 +440,9 @@
430 440
     delay(200);
431 441
   }
432 442
 
433
-  #define _TMC2208_INIT(ST, SPMM) tmc2208_init(stepper##ST, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, SPMM)
443
+  #define _TMC2208_INIT(ST, SPMM) tmc2208_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, SPMM)
434 444
 
435
-  void tmc2208_init() {
445
+  void tmc2208_init_to_defaults() {
436 446
     #if ENABLED(X_IS_TMC2208)
437 447
       _TMC2208_INIT(X, planner.axis_steps_per_mm[X_AXIS]);
438 448
     #endif
@@ -455,36 +465,76 @@
455 465
       _TMC2208_INIT(E0, planner.axis_steps_per_mm[E_AXIS]);
456 466
     #endif
457 467
     #if ENABLED(E1_IS_TMC2208)
458
-      _TMC2208_INIT(E1, planner.axis_steps_per_mm[E_AXIS
459
-        #if ENABLED(DISTINCT_E_FACTORS)
460
-          + 1
461
-        #endif
462
-      ]);
468
+      { constexpr int extruder = 1; _TMC2208_INIT(E1, planner.axis_steps_per_mm[E_AXIS_N]); }
463 469
     #endif
464 470
     #if ENABLED(E2_IS_TMC2208)
465
-      _TMC2208_INIT(E2, planner.axis_steps_per_mm[E_AXIS
466
-        #if ENABLED(DISTINCT_E_FACTORS)
467
-          + 2
468
-        #endif
469
-      ]);
471
+      { constexpr int extruder = 2; _TMC2208_INIT(E2, planner.axis_steps_per_mm[E_AXIS_N]); }
470 472
     #endif
471 473
     #if ENABLED(E3_IS_TMC2208)
472
-      _TMC2208_INIT(E3, planner.axis_steps_per_mm[E_AXIS
473
-        #if ENABLED(DISTINCT_E_FACTORS)
474
-          + 3
475
-        #endif
476
-      ]);
474
+      { constexpr int extruder = 3; _TMC2208_INIT(E3, planner.axis_steps_per_mm[E_AXIS_N]); }
477 475
     #endif
478 476
     #if ENABLED(E4_IS_TMC2208)
479
-      _TMC2208_INIT(E4, planner.axis_steps_per_mm[E_AXIS
480
-        #if ENABLED(DISTINCT_E_FACTORS)
481
-          + 4
482
-        #endif
483
-      ]);
477
+      { constexpr int extruder = 4; _TMC2208_INIT(E4, planner.axis_steps_per_mm[E_AXIS_N]); }
484 478
     #endif
485 479
   }
486 480
 #endif // HAVE_TMC2208
487 481
 
482
+void restore_stepper_drivers() {
483
+  #if X_IS_TRINAMIC
484
+    stepperX.push();
485
+  #endif
486
+  #if X2_IS_TRINAMIC
487
+    stepperX2.push();
488
+  #endif
489
+  #if Y_IS_TRINAMIC
490
+    stepperY.push();
491
+  #endif
492
+  #if Y2_IS_TRINAMIC
493
+    stepperY2.push();
494
+  #endif
495
+  #if Z_IS_TRINAMIC
496
+    stepperZ.push();
497
+  #endif
498
+  #if Z2_IS_TRINAMIC
499
+    stepperZ2.push();
500
+  #endif
501
+  #if E0_IS_TRINAMIC
502
+    stepperE0.push();
503
+  #endif
504
+  #if E1_IS_TRINAMIC
505
+    stepperE1.push();
506
+  #endif
507
+  #if E2_IS_TRINAMIC
508
+    stepperE2.push();
509
+  #endif
510
+  #if E3_IS_TRINAMIC
511
+    stepperE3.push();
512
+  #endif
513
+  #if E4_IS_TRINAMIC
514
+    stepperE4.push();
515
+  #endif
516
+}
517
+
518
+void reset_stepper_drivers() {
519
+  #if ENABLED(HAVE_TMC26X)
520
+    tmc26x_init_to_defaults();
521
+  #endif
522
+  #if ENABLED(HAVE_TMC2130)
523
+    delay(100);
524
+    tmc2130_init_to_defaults();
525
+  #endif
526
+  #if ENABLED(HAVE_TMC2208)
527
+    delay(100);
528
+    tmc2208_init_to_defaults();
529
+  #endif
530
+  #ifdef TMC_ADV
531
+    TMC_ADV()
532
+  #endif
533
+  #if ENABLED(HAVE_L6470DRIVER)
534
+    L6470_init_to_defaults();
535
+  #endif
536
+}
537
+
488 538
 //
489 539
 // L6470 Driver objects and inits
490 540
 //
@@ -538,7 +588,7 @@
538 588
     stepper##A.setStallCurrent(A##_STALLCURRENT); \
539 589
   }while(0)
540 590
 
541
-  void L6470_init() {
591
+  void L6470_init_to_defaults() {
542 592
     #if ENABLED(X_IS_L6470)
543 593
       _L6470_INIT(X);
544 594
     #endif
@@ -575,4 +625,3 @@
575 625
   }
576 626
 
577 627
 #endif // HAVE_L6470DRIVER
578
-

+ 40
- 37
Marlin/src/module/stepper_indirection.h View File

@@ -54,29 +54,32 @@
54 54
   #else
55 55
     #include <TMC26XStepper.h>
56 56
   #endif
57
-  void tmc26x_init();
57
+  void tmc26x_init_to_defaults();
58 58
 #endif
59 59
 
60 60
 #if ENABLED(HAVE_TMC2130)
61 61
   #include <TMC2130Stepper.h>
62
-  void tmc2130_init();
62
+  void tmc2130_init_to_defaults();
63 63
 #endif
64 64
 
65 65
 #if ENABLED(HAVE_TMC2208)
66 66
   #include <TMC2208Stepper.h>
67 67
   void tmc2208_serial_begin();
68
-  void tmc2208_init();
68
+  void tmc2208_init_to_defaults();
69 69
 #endif
70 70
 
71 71
 // L6470 has STEP on normal pins, but DIR/ENABLE via SPI
72 72
 #if ENABLED(HAVE_L6470DRIVER)
73 73
   #include <SPI.h>
74 74
   #include <L6470.h>
75
-  void L6470_init();
75
+  void L6470_init_to_defaults();
76 76
 #endif
77 77
 
78
+void restore_stepper_drivers();  // Called by PSU_ON
79
+void reset_stepper_drivers();    // Called by settings.load / settings.reset
80
+
78 81
 // X Stepper
79
-#if ENABLED(HAVE_L6470DRIVER) && ENABLED(X_IS_L6470)
82
+#if ENABLED(X_IS_L6470)
80 83
   extern L6470 stepperX;
81 84
   #define X_ENABLE_INIT NOOP
82 85
   #define X_ENABLE_WRITE(STATE) do{ if (STATE) stepperX.Step_Clock(stepperX.getStatus() & STATUS_HIZ); else stepperX.softFree(); }while(0)
@@ -91,9 +94,9 @@
91 94
     #define X_ENABLE_WRITE(STATE) stepperX.setEnabled(STATE)
92 95
     #define X_ENABLE_READ stepperX.isEnabled()
93 96
   #else
94
-    #if ENABLED(HAVE_TMC2130) && ENABLED(X_IS_TMC2130)
97
+    #if ENABLED(X_IS_TMC2130)
95 98
       extern TMC2130Stepper stepperX;
96
-    #elif ENABLED(HAVE_TMC2208) && ENABLED(X_IS_TMC2208)
99
+    #elif ENABLED(X_IS_TMC2208)
97 100
       extern TMC2208Stepper stepperX;
98 101
     #endif
99 102
     #define X_ENABLE_INIT SET_OUTPUT(X_ENABLE_PIN)
@@ -109,7 +112,7 @@
109 112
 #define X_STEP_READ READ(X_STEP_PIN)
110 113
 
111 114
 // Y Stepper
112
-#if ENABLED(HAVE_L6470DRIVER) && ENABLED(Y_IS_L6470)
115
+#if ENABLED(Y_IS_L6470)
113 116
   extern L6470 stepperY;
114 117
   #define Y_ENABLE_INIT NOOP
115 118
   #define Y_ENABLE_WRITE(STATE) do{ if (STATE) stepperY.Step_Clock(stepperY.getStatus() & STATUS_HIZ); else stepperY.softFree(); }while(0)
@@ -124,9 +127,9 @@
124 127
     #define Y_ENABLE_WRITE(STATE) stepperY.setEnabled(STATE)
125 128
     #define Y_ENABLE_READ stepperY.isEnabled()
126 129
   #else
127
-    #if ENABLED(HAVE_TMC2130) && ENABLED(Y_IS_TMC2130)
130
+    #if ENABLED(Y_IS_TMC2130)
128 131
       extern TMC2130Stepper stepperY;
129
-    #elif ENABLED(HAVE_TMC2208) && ENABLED(Y_IS_TMC2208)
132
+    #elif ENABLED(Y_IS_TMC2208)
130 133
       extern TMC2208Stepper stepperY;
131 134
     #endif
132 135
     #define Y_ENABLE_INIT SET_OUTPUT(Y_ENABLE_PIN)
@@ -142,7 +145,7 @@
142 145
 #define Y_STEP_READ READ(Y_STEP_PIN)
143 146
 
144 147
 // Z Stepper
145
-#if ENABLED(HAVE_L6470DRIVER) && ENABLED(Z_IS_L6470)
148
+#if ENABLED(Z_IS_L6470)
146 149
   extern L6470 stepperZ;
147 150
   #define Z_ENABLE_INIT NOOP
148 151
   #define Z_ENABLE_WRITE(STATE) do{ if (STATE) stepperZ.Step_Clock(stepperZ.getStatus() & STATUS_HIZ); else stepperZ.softFree(); }while(0)
@@ -157,9 +160,9 @@
157 160
     #define Z_ENABLE_WRITE(STATE) stepperZ.setEnabled(STATE)
158 161
     #define Z_ENABLE_READ stepperZ.isEnabled()
159 162
   #else
160
-    #if ENABLED(HAVE_TMC2130) && ENABLED(Z_IS_TMC2130)
163
+    #if ENABLED(Z_IS_TMC2130)
161 164
       extern TMC2130Stepper stepperZ;
162
-    #elif ENABLED(HAVE_TMC2208) && ENABLED(Z_IS_TMC2208)
165
+    #elif ENABLED(Z_IS_TMC2208)
163 166
       extern TMC2208Stepper stepperZ;
164 167
     #endif
165 168
     #define Z_ENABLE_INIT SET_OUTPUT(Z_ENABLE_PIN)
@@ -176,7 +179,7 @@
176 179
 
177 180
 // X2 Stepper
178 181
 #if HAS_X2_ENABLE
179
-  #if ENABLED(HAVE_L6470DRIVER) && ENABLED(X2_IS_L6470)
182
+  #if ENABLED(X2_IS_L6470)
180 183
     extern L6470 stepperX2;
181 184
     #define X2_ENABLE_INIT NOOP
182 185
     #define X2_ENABLE_WRITE(STATE) do{ if (STATE) stepperX2.Step_Clock(stepperX2.getStatus() & STATUS_HIZ); else stepperX2.softFree(); }while(0)
@@ -191,9 +194,9 @@
191 194
       #define X2_ENABLE_WRITE(STATE) stepperX2.setEnabled(STATE)
192 195
       #define X2_ENABLE_READ stepperX2.isEnabled()
193 196
     #else
194
-      #if ENABLED(HAVE_TMC2130) && ENABLED(X2_IS_TMC2130)
197
+      #if ENABLED(X2_IS_TMC2130)
195 198
         extern TMC2130Stepper stepperX2;
196
-      #elif ENABLED(HAVE_TMC2208) && ENABLED(X2_IS_TMC2208)
199
+      #elif ENABLED(X2_IS_TMC2208)
197 200
         extern TMC2208Stepper stepperX2;
198 201
       #endif
199 202
       #define X2_ENABLE_INIT SET_OUTPUT(X2_ENABLE_PIN)
@@ -211,7 +214,7 @@
211 214
 
212 215
 // Y2 Stepper
213 216
 #if HAS_Y2_ENABLE
214
-  #if ENABLED(HAVE_L6470DRIVER) && ENABLED(Y2_IS_L6470)
217
+  #if ENABLED(Y2_IS_L6470)
215 218
     extern L6470 stepperY2;
216 219
     #define Y2_ENABLE_INIT NOOP
217 220
     #define Y2_ENABLE_WRITE(STATE) do{ if (STATE) stepperY2.Step_Clock(stepperY2.getStatus() & STATUS_HIZ); else stepperY2.softFree(); }while(0)
@@ -226,9 +229,9 @@
226 229
       #define Y2_ENABLE_WRITE(STATE) stepperY2.setEnabled(STATE)
227 230
       #define Y2_ENABLE_READ stepperY2.isEnabled()
228 231
     #else
229
-      #if ENABLED(HAVE_TMC2130) && ENABLED(Y2_IS_TMC2130)
232
+      #if ENABLED(Y2_IS_TMC2130)
230 233
         extern TMC2130Stepper stepperY2;
231
-      #elif ENABLED(HAVE_TMC2208) && ENABLED(Y2_IS_TMC2208)
234
+      #elif ENABLED(Y2_IS_TMC2208)
232 235
         extern TMC2208Stepper stepperY2;
233 236
       #endif
234 237
       #define Y2_ENABLE_INIT SET_OUTPUT(Y2_ENABLE_PIN)
@@ -246,7 +249,7 @@
246 249
 
247 250
 // Z2 Stepper
248 251
 #if HAS_Z2_ENABLE
249
-  #if ENABLED(HAVE_L6470DRIVER) && ENABLED(Z2_IS_L6470)
252
+  #if ENABLED(Z2_IS_L6470)
250 253
     extern L6470 stepperZ2;
251 254
     #define Z2_ENABLE_INIT NOOP
252 255
     #define Z2_ENABLE_WRITE(STATE) do{ if (STATE) stepperZ2.Step_Clock(stepperZ2.getStatus() & STATUS_HIZ); else stepperZ2.softFree(); }while(0)
@@ -261,9 +264,9 @@
261 264
       #define Z2_ENABLE_WRITE(STATE) stepperZ2.setEnabled(STATE)
262 265
       #define Z2_ENABLE_READ stepperZ2.isEnabled()
263 266
     #else
264
-      #if ENABLED(HAVE_TMC2130) && ENABLED(Z2_IS_TMC2130)
267
+      #if ENABLED(Z2_IS_TMC2130)
265 268
         extern TMC2130Stepper stepperZ2;
266
-      #elif ENABLED(HAVE_TMC2208) && ENABLED(Z2_IS_TMC2208)
269
+      #elif ENABLED(Z2_IS_TMC2208)
267 270
         extern TMC2208Stepper stepperZ2;
268 271
       #endif
269 272
       #define Z2_ENABLE_INIT SET_OUTPUT(Z2_ENABLE_PIN)
@@ -280,7 +283,7 @@
280 283
 #endif
281 284
 
282 285
 // E0 Stepper
283
-#if ENABLED(HAVE_L6470DRIVER) && ENABLED(E0_IS_L6470)
286
+#if ENABLED(E0_IS_L6470)
284 287
   extern L6470 stepperE0;
285 288
   #define E0_ENABLE_INIT NOOP
286 289
   #define E0_ENABLE_WRITE(STATE) do{ if (STATE) stepperE0.Step_Clock(stepperE0.getStatus() & STATUS_HIZ); else stepperE0.softFree(); }while(0)
@@ -295,9 +298,9 @@
295 298
     #define E0_ENABLE_WRITE(STATE) stepperE0.setEnabled(STATE)
296 299
     #define E0_ENABLE_READ stepperE0.isEnabled()
297 300
   #else
298
-    #if ENABLED(HAVE_TMC2130) && ENABLED(E0_IS_TMC2130)
301
+    #if ENABLED(E0_IS_TMC2130)
299 302
       extern TMC2130Stepper stepperE0;
300
-    #elif ENABLED(HAVE_TMC2208) && ENABLED(E0_IS_TMC2208)
303
+    #elif ENABLED(E0_IS_TMC2208)
301 304
       extern TMC2208Stepper stepperE0;
302 305
     #endif
303 306
     #define E0_ENABLE_INIT SET_OUTPUT(E0_ENABLE_PIN)
@@ -313,7 +316,7 @@
313 316
 #define E0_STEP_READ READ(E0_STEP_PIN)
314 317
 
315 318
 // E1 Stepper
316
-#if ENABLED(HAVE_L6470DRIVER) && ENABLED(E1_IS_L6470)
319
+#if ENABLED(E1_IS_L6470)
317 320
   extern L6470 stepperE1;
318 321
   #define E1_ENABLE_INIT NOOP
319 322
   #define E1_ENABLE_WRITE(STATE) do{ if (STATE) stepperE1.Step_Clock(stepperE1.getStatus() & STATUS_HIZ); else stepperE1.softFree(); }while(0)
@@ -328,9 +331,9 @@
328 331
     #define E1_ENABLE_WRITE(STATE) stepperE1.setEnabled(STATE)
329 332
     #define E1_ENABLE_READ stepperE1.isEnabled()
330 333
   #else
331
-    #if ENABLED(HAVE_TMC2130) && ENABLED(E1_IS_TMC2130)
334
+    #if ENABLED(E1_IS_TMC2130)
332 335
       extern TMC2130Stepper stepperE1;
333
-    #elif ENABLED(HAVE_TMC2208) && ENABLED(E1_IS_TMC2208)
336
+    #elif ENABLED(E1_IS_TMC2208)
334 337
       extern TMC2208Stepper stepperE1;
335 338
     #endif
336 339
     #define E1_ENABLE_INIT SET_OUTPUT(E1_ENABLE_PIN)
@@ -346,7 +349,7 @@
346 349
 #define E1_STEP_READ READ(E1_STEP_PIN)
347 350
 
348 351
 // E2 Stepper
349
-#if ENABLED(HAVE_L6470DRIVER) && ENABLED(E2_IS_L6470)
352
+#if ENABLED(E2_IS_L6470)
350 353
   extern L6470 stepperE2;
351 354
   #define E2_ENABLE_INIT NOOP
352 355
   #define E2_ENABLE_WRITE(STATE) do{ if (STATE) stepperE2.Step_Clock(stepperE2.getStatus() & STATUS_HIZ); else stepperE2.softFree(); }while(0)
@@ -361,9 +364,9 @@
361 364
     #define E2_ENABLE_WRITE(STATE) stepperE2.setEnabled(STATE)
362 365
     #define E2_ENABLE_READ stepperE2.isEnabled()
363 366
   #else
364
-    #if ENABLED(HAVE_TMC2130) && ENABLED(E2_IS_TMC2130)
367
+    #if ENABLED(E2_IS_TMC2130)
365 368
       extern TMC2130Stepper stepperE2;
366
-    #elif ENABLED(HAVE_TMC2208) && ENABLED(E2_IS_TMC2208)
369
+    #elif ENABLED(E2_IS_TMC2208)
367 370
       extern TMC2208Stepper stepperE2;
368 371
     #endif
369 372
     #define E2_ENABLE_INIT SET_OUTPUT(E2_ENABLE_PIN)
@@ -379,7 +382,7 @@
379 382
 #define E2_STEP_READ READ(E2_STEP_PIN)
380 383
 
381 384
 // E3 Stepper
382
-#if ENABLED(HAVE_L6470DRIVER) && ENABLED(E3_IS_L6470)
385
+#if ENABLED(E3_IS_L6470)
383 386
   extern L6470 stepperE3;
384 387
   #define E3_ENABLE_INIT NOOP
385 388
   #define E3_ENABLE_WRITE(STATE) do{ if (STATE) stepperE3.Step_Clock(stepperE3.getStatus() & STATUS_HIZ); else stepperE3.softFree(); }while(0)
@@ -394,9 +397,9 @@
394 397
     #define E3_ENABLE_WRITE(STATE) stepperE3.setEnabled(STATE)
395 398
     #define E3_ENABLE_READ stepperE3.isEnabled()
396 399
   #else
397
-    #if ENABLED(HAVE_TMC2130) && ENABLED(E3_IS_TMC2130)
400
+    #if ENABLED(E3_IS_TMC2130)
398 401
       extern TMC2130Stepper stepperE3;
399
-    #elif ENABLED(HAVE_TMC2208) && ENABLED(E3_IS_TMC2208)
402
+    #elif ENABLED(E3_IS_TMC2208)
400 403
       extern TMC2208Stepper stepperE3;
401 404
     #endif
402 405
     #define E3_ENABLE_INIT SET_OUTPUT(E3_ENABLE_PIN)
@@ -412,7 +415,7 @@
412 415
 #define E3_STEP_READ READ(E3_STEP_PIN)
413 416
 
414 417
 // E4 Stepper
415
-#if ENABLED(HAVE_L6470DRIVER) && ENABLED(E4_IS_L6470)
418
+#if ENABLED(E4_IS_L6470)
416 419
   extern L6470 stepperE4;
417 420
   #define E4_ENABLE_INIT NOOP
418 421
   #define E4_ENABLE_WRITE(STATE) do{ if (STATE) stepperE4.Step_Clock(stepperE4.getStatus() & STATUS_HIZ); else stepperE4.softFree(); }while(0)
@@ -427,9 +430,9 @@
427 430
     #define E4_ENABLE_WRITE(STATE) stepperE4.setEnabled(STATE)
428 431
     #define E4_ENABLE_READ stepperE4.isEnabled()
429 432
   #else
430
-    #if ENABLED(HAVE_TMC2130) && ENABLED(E4_IS_TMC2130)
433
+    #if ENABLED(E4_IS_TMC2130)
431 434
       extern TMC2130Stepper stepperE4;
432
-    #elif ENABLED(HAVE_TMC2208) && ENABLED(E4_IS_TMC2208)
435
+    #elif ENABLED(E4_IS_TMC2208)
433 436
       extern TMC2208Stepper stepperE4;
434 437
     #endif
435 438
     #define E4_ENABLE_INIT SET_OUTPUT(E4_ENABLE_PIN)

Loading…
Cancel
Save