Skip to content

Commit 202ec4b

Browse files
thinkyheaddbuezasz1996xm
authored
✨ Trinamic TMC2240 (SPI) (MarlinFirmware#25974)
Co-Authored-By: David Buezas <david.buezas@gmail.com> Co-Authored-By: z1996xm <102506464+z1996xm@users.noreply.github.com>
1 parent 1258657 commit 202ec4b

File tree

11 files changed

+335
-81
lines changed

11 files changed

+335
-81
lines changed

Marlin/Configuration.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@
148148
* Options: A4988, A5984, DRV8825, LV8729, TB6560, TB6600, TMC2100,
149149
* TMC2130, TMC2130_STANDALONE, TMC2160, TMC2160_STANDALONE,
150150
* TMC2208, TMC2208_STANDALONE, TMC2209, TMC2209_STANDALONE,
151-
* TMC2660, TMC2660_STANDALONE, TMC5130, TMC5130_STANDALONE,
152-
* TMC5160, TMC5160_STANDALONE
153-
* :['A4988', 'A5984', 'DRV8825', 'LV8729', 'TB6560', 'TB6600', 'TMC2100', 'TMC2130', 'TMC2130_STANDALONE', 'TMC2160', 'TMC2160_STANDALONE', 'TMC2208', 'TMC2208_STANDALONE', 'TMC2209', 'TMC2209_STANDALONE', 'TMC2660', 'TMC2660_STANDALONE', 'TMC5130', 'TMC5130_STANDALONE', 'TMC5160', 'TMC5160_STANDALONE']
151+
* TMC2240, TMC2240_STANDALONE, TMC2660, TMC2660_STANDALONE,
152+
* TMC5130, TMC5130_STANDALONE, TMC5160, TMC5160_STANDALONE
153+
* :['A4988', 'A5984', 'DRV8825', 'LV8729', 'TB6560', 'TB6600', 'TMC2100', 'TMC2130', 'TMC2130_STANDALONE', 'TMC2160', 'TMC2160_STANDALONE', 'TMC2208', 'TMC2208_STANDALONE', 'TMC2209', 'TMC2209_STANDALONE', 'TMC2240', 'TMC2240_STANDALONE', 'TMC2660', 'TMC2660_STANDALONE', 'TMC5130', 'TMC5130_STANDALONE', 'TMC5160', 'TMC5160_STANDALONE']
154154
*/
155155
#define X_DRIVER_TYPE A4988
156156
#define Y_DRIVER_TYPE A4988

Marlin/Configuration_adv.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,6 +3027,15 @@
30273027
*/
30283028
#define INTERPOLATE true
30293029

3030+
#if HAS_DRIVER(TMC2240)
3031+
#define TMC2240_CURRENT_RANGE 1 // RMS: { 0:'690mA', 1:'1410mA', 2:'2120mA', 3:'2110mA' }
3032+
// PEAK:{ 0:'1A', 1:'2A', 2:'3A', 3:'3A' }
3033+
// Determines max current. Lower is more internal current resolution. Higher runs cooler.
3034+
#define TMC2240_Rref 12000 // ('rref', 12000, minval=12000, maxval=60000)
3035+
#define TMC2240_SLOPE_CONTROL 0 // :{ 0:'100V/us', 1:'200V/us', 2:'400V/us', 3:'800V/us' }
3036+
// Lower is more silent. Higher runs cooler.
3037+
#endif
3038+
30303039
#if AXIS_IS_TMC_CONFIG(X)
30313040
#define X_CURRENT 800 // (mA) RMS current. Multiply by 1.414 for peak current.
30323041
#define X_CURRENT_HOME X_CURRENT // (mA) RMS current for homing. (Typically lower than *_CURRENT.)
@@ -3335,7 +3344,7 @@
33353344
// @section tmc/stealthchop
33363345

33373346
/**
3338-
* TMC2130, TMC2160, TMC2208, TMC2209, TMC5130 and TMC5160 only
3347+
* TMC2130, TMC2160, TMC2208, TMC2209, TMC2240, TMC5130 and TMC5160 only
33393348
* Use Trinamic's ultra quiet stepping mode.
33403349
* When disabled, Marlin will use spreadCycle stepping mode.
33413350
*/
@@ -3414,7 +3423,7 @@
34143423
// @section tmc/hybrid
34153424

34163425
/**
3417-
* TMC2130, TMC2160, TMC2208, TMC2209, TMC5130 and TMC5160 only
3426+
* TMC2130, TMC2160, TMC2208, TMC2209, TMC2240, TMC5130 and TMC5160 only
34183427
* The driver will switch to spreadCycle when stepper speed is over HYBRID_THRESHOLD.
34193428
* This mode allows for faster movements at the expense of higher noise levels.
34203429
* STEALTHCHOP_(XY|Z|E) must be enabled to use HYBRID_THRESHOLD.
@@ -3448,16 +3457,16 @@
34483457
/**
34493458
* Use StallGuard to home / probe X, Y, Z.
34503459
*
3451-
* TMC2130, TMC2160, TMC2209, TMC2660, TMC5130, and TMC5160 only
3460+
* TMC2130, TMC2160, TMC2209, TMC2240, TMC2660, TMC5130, and TMC5160 only
34523461
* Connect the stepper driver's DIAG1 pin to the X/Y endstop pin.
34533462
* X, Y, and Z homing will always be done in spreadCycle mode.
34543463
*
34553464
* X/Y/Z_STALL_SENSITIVITY is the default stall threshold.
34563465
* Use M914 X Y Z to set the stall threshold at runtime:
34573466
*
3458-
* Sensitivity TMC2209 Others
3459-
* HIGHEST 255 -64 (Too sensitive => False positive)
3460-
* LOWEST 0 63 (Too insensitive => No trigger)
3467+
* Sensitivity TMC2209/2240 Others
3468+
* HIGHEST 255 -64 (Too sensitive => False positive)
3469+
* LOWEST 0 63 (Too insensitive => No trigger)
34613470
*
34623471
* It is recommended to set HOMING_BUMP_MM to { 0, 0, 0 }.
34633472
*
@@ -3474,7 +3483,7 @@
34743483
//#define SENSORLESS_HOMING // StallGuard capable drivers only
34753484

34763485
#if ANY(SENSORLESS_HOMING, SENSORLESS_PROBING)
3477-
// TMC2209: 0...255. TMC2130: -64...63
3486+
// TMC2209/2240: 0...255. TMC2130: -64...63
34783487
#define X_STALL_SENSITIVITY 8
34793488
#define X2_STALL_SENSITIVITY X_STALL_SENSITIVITY
34803489
#define Y_STALL_SENSITIVITY 8

Marlin/src/core/drivers.h

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#define _TMC2208_STANDALONE 0x2208B
4242
#define _TMC2209 0x2209A
4343
#define _TMC2209_STANDALONE 0x2209B
44+
#define _TMC2240 0x2240A
45+
#define _TMC2240_STANDALONE 0x2240B
4446
#define _TMC2660 0x2660A
4547
#define _TMC2660_STANDALONE 0x2660B
4648
#define _TMC5130 0x5130A
@@ -96,7 +98,7 @@
9698
// Does not match standalone configurations
9799
#if ( HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) \
98100
|| HAS_DRIVER(TMC2208) || HAS_DRIVER(TMC2209) \
99-
|| HAS_DRIVER(TMC2660) \
101+
|| HAS_DRIVER(TMC2240) || HAS_DRIVER(TMC2660) \
100102
|| HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160) )
101103
#define HAS_TRINAMIC_CONFIG 1
102104
#endif
@@ -106,31 +108,39 @@
106108
#if ( HAS_DRIVER(TMC2100) \
107109
|| HAS_DRIVER(TMC2130_STANDALONE) || HAS_DRIVER(TMC2160_STANDALONE) \
108110
|| HAS_DRIVER(TMC2208_STANDALONE) || HAS_DRIVER(TMC2209_STANDALONE) \
109-
|| HAS_DRIVER(TMC2660_STANDALONE) || HAS_DRIVER(TMC5130_STANDALONE) \
110-
|| HAS_DRIVER(TMC5160_STANDALONE) )
111+
|| HAS_DRIVER(TMC2240_STANDALONE) || HAS_DRIVER(TMC2660_STANDALONE) \
112+
|| HAS_DRIVER(TMC5130_STANDALONE) || HAS_DRIVER(TMC5160_STANDALONE) )
111113
#define HAS_TRINAMIC_STANDALONE 1
112114
#endif
113115

114-
#if HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160)
116+
#if HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) || HAS_DRIVER(TMC5130) || HAS_DRIVER(TMC5160) || HAS_DRIVER(TMC2240)
115117
#define HAS_TMCX1X0 1
116118
#endif
117-
118119
#if HAS_DRIVER(TMC2208) || HAS_DRIVER(TMC2209)
119120
#define HAS_TMC220x 1
120121
#endif
122+
//#if HAS_TMC_220x || HAS_DRIVER(TMC2240)
123+
// #define HAS_TMC22xx 1
124+
//#endif
125+
//#if HAS_TMCX1X0 || HAS_TMC220x
126+
// #define HAS_TMC_CS_ACTUAL 1
127+
//#endif
128+
//#if HAS_TMCX1X0 || HAS_DRIVER(TMC2209)
129+
// #define HAS_TMC_SG_RESULT 1
130+
//#endif
121131

122132
#define AXIS_IS_TMC(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \
123133
|| AXIS_DRIVER_TYPE(A,TMC2208) || AXIS_DRIVER_TYPE(A,TMC2209) \
124-
|| AXIS_DRIVER_TYPE(A,TMC2660) \
134+
|| AXIS_DRIVER_TYPE(A,TMC2240) || AXIS_DRIVER_TYPE(A,TMC2660) \
125135
|| AXIS_DRIVER_TYPE(A,TMC5130) || AXIS_DRIVER_TYPE(A,TMC5160) )
126136

127137
#define AXIS_IS_TMC_CONFIG AXIS_IS_TMC
128138

129139
// Test for a driver that uses SPI - this allows checking whether a _CS_ pin
130140
// is considered sensitive
131141
#define AXIS_HAS_SPI(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \
132-
|| AXIS_DRIVER_TYPE(A,TMC2660) || AXIS_DRIVER_TYPE(A,TMC5130) \
133-
|| AXIS_DRIVER_TYPE(A,TMC5160) )
142+
|| AXIS_DRIVER_TYPE(A,TMC2240) || AXIS_DRIVER_TYPE(A,TMC2660) \
143+
|| AXIS_DRIVER_TYPE(A,TMC5130) || AXIS_DRIVER_TYPE(A,TMC5160) )
134144

135145
#define AXIS_HAS_UART(A) ( AXIS_DRIVER_TYPE(A,TMC2208) || AXIS_DRIVER_TYPE(A,TMC2209) )
136146

@@ -140,19 +150,21 @@
140150
#define AXIS_HAS_SW_SERIAL(A) ( AXIS_HAS_UART(A) && !defined(A##_HARDWARE_SERIAL) )
141151

142152
#define AXIS_HAS_STALLGUARD(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \
143-
|| AXIS_DRIVER_TYPE(A,TMC2209) \
153+
|| AXIS_DRIVER_TYPE(A,TMC2209) || AXIS_DRIVER_TYPE(A,TMC2240) \
144154
|| AXIS_DRIVER_TYPE(A,TMC2660) \
145155
|| AXIS_DRIVER_TYPE(A,TMC5130) || AXIS_DRIVER_TYPE(A,TMC5160) )
146156

147157
#define AXIS_HAS_STEALTHCHOP(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \
148158
|| AXIS_DRIVER_TYPE(A,TMC2208) || AXIS_DRIVER_TYPE(A,TMC2209) \
159+
|| AXIS_DRIVER_TYPE(A,TMC2240) \
149160
|| AXIS_DRIVER_TYPE(A,TMC5130) || AXIS_DRIVER_TYPE(A,TMC5160) )
150161

151162
#define AXIS_HAS_SG_RESULT(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \
152-
|| AXIS_DRIVER_TYPE(A,TMC2208) || AXIS_DRIVER_TYPE(A,TMC2209) )
163+
|| AXIS_DRIVER_TYPE(A,TMC2208) || AXIS_DRIVER_TYPE(A,TMC2209) \
164+
|| AXIS_DRIVER_TYPE(A,TMC2240) )
153165

154166
#define AXIS_HAS_COOLSTEP(A) ( AXIS_DRIVER_TYPE(A,TMC2130) \
155-
|| AXIS_DRIVER_TYPE(A,TMC2209) \
167+
|| AXIS_DRIVER_TYPE(A,TMC2209) || AXIS_DRIVER_TYPE(A,TMC2240) \
156168
|| AXIS_DRIVER_TYPE(A,TMC5130) || AXIS_DRIVER_TYPE(A,TMC5160) )
157169

158170
#define _OR_EAH(N,T) || AXIS_HAS_##T(E##N)

Marlin/src/feature/tmc_util.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,67 @@
142142

143143
#endif // HAS_TMCX1X0
144144

145+
#if HAS_DRIVER(TMC2240)
146+
147+
#if ENABLED(TMC_DEBUG)
148+
static uint32_t get_pwm_scale(TMC2240Stepper &st) { return st.PWM_SCALE(); }
149+
#endif
150+
151+
static TMC_driver_data get_driver_data(TMC2240Stepper &st) {
152+
constexpr uint8_t OT_bp = 25, OTPW_bp = 26;
153+
constexpr uint32_t S2G_bm = 0x18000000;
154+
#if ENABLED(TMC_DEBUG)
155+
constexpr uint16_t SG_RESULT_bm = 0x3FF; // 0:9
156+
constexpr uint8_t STEALTH_bp = 14;
157+
constexpr uint32_t CS_ACTUAL_bm = 0x1F0000; // 16:20
158+
constexpr uint8_t STALL_GUARD_bp = 24;
159+
constexpr uint8_t STST_bp = 31;
160+
#endif
161+
TMC_driver_data data;
162+
const auto ds = data.drv_status = st.DRV_STATUS();
163+
#ifdef __AVR__
164+
165+
// 8-bit optimization saves up to 70 bytes of PROGMEM per axis
166+
uint8_t spart;
167+
#if ENABLED(TMC_DEBUG)
168+
data.sg_result = ds & SG_RESULT_bm;
169+
spart = ds >> 8;
170+
data.is_stealth = TEST(spart, STEALTH_bp - 8);
171+
spart = ds >> 16;
172+
data.cs_actual = spart & (CS_ACTUAL_bm >> 16);
173+
#endif
174+
spart = ds >> 24;
175+
data.is_ot = TEST(spart, OT_bp - 24);
176+
data.is_otpw = TEST(spart, OTPW_bp - 24);
177+
data.is_s2g = !!(spart & (S2G_bm >> 24));
178+
#if ENABLED(TMC_DEBUG)
179+
data.is_stall = TEST(spart, STALL_GUARD_bp - 24);
180+
data.is_standstill = TEST(spart, STST_bp - 24);
181+
data.sg_result_reasonable = !data.is_standstill; // sg_result has no reasonable meaning while standstill
182+
#endif
183+
184+
#else // !__AVR__
185+
186+
data.is_ot = TEST(ds, OT_bp);
187+
data.is_otpw = TEST(ds, OTPW_bp);
188+
data.is_s2g = !!(ds & S2G_bm);
189+
#if ENABLED(TMC_DEBUG)
190+
constexpr uint8_t CS_ACTUAL_sb = 16;
191+
data.sg_result = ds & SG_RESULT_bm;
192+
data.is_stealth = TEST(ds, STEALTH_bp);
193+
data.cs_actual = (ds & CS_ACTUAL_bm) >> CS_ACTUAL_sb;
194+
data.is_stall = TEST(ds, STALL_GUARD_bp);
195+
data.is_standstill = TEST(ds, STST_bp);
196+
data.sg_result_reasonable = !data.is_standstill; // sg_result has no reasonable meaning while standstill
197+
#endif
198+
199+
#endif // !__AVR__
200+
201+
return data;
202+
}
203+
204+
#endif // TMC2240
205+
145206
#if HAS_TMC220x
146207

147208
#if ENABLED(TMC_DEBUG)
@@ -1025,6 +1086,21 @@
10251086
st.TCOOLTHRS(0);
10261087
}
10271088

1089+
bool tmc_enable_stallguard(TMC2240Stepper &st) {
1090+
const bool stealthchop_was_enabled = st.en_pwm_mode();
1091+
1092+
st.TCOOLTHRS(0xFFFFF);
1093+
st.en_pwm_mode(false);
1094+
st.diag0_stall(true);
1095+
1096+
return stealthchop_was_enabled;
1097+
}
1098+
void tmc_disable_stallguard(TMC2240Stepper &st, const bool restore_stealth) {
1099+
st.TCOOLTHRS(0);
1100+
st.en_pwm_mode(restore_stealth);
1101+
st.diag0_stall(false);
1102+
}
1103+
10281104
bool tmc_enable_stallguard(TMC2660Stepper) {
10291105
// TODO
10301106
return false;

Marlin/src/feature/tmc_util.h

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class TMCMarlin : public TMC, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
9595
TMC(CS, RS, pinMOSI, pinMISO, pinSCK)
9696
{}
9797
TMCMarlin(const uint16_t CS, const float RS, const uint16_t pinMOSI, const uint16_t pinMISO, const uint16_t pinSCK, const uint8_t axis_chain_index) :
98-
TMC(CS, RS, pinMOSI, pinMISO, pinSCK, axis_chain_index)
98+
TMC(CS, RS, pinMOSI, pinMISO, pinSCK, axis_chain_index)
9999
{}
100100
uint16_t rms_current() { return TMC::rms_current(); }
101101
void rms_current(uint16_t mA) {
@@ -124,7 +124,7 @@ class TMCMarlin : public TMC, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
124124

125125
#if ENABLED(HYBRID_THRESHOLD)
126126
uint32_t get_pwm_thrs() {
127-
return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
127+
return _tmc_thrs(this->microsteps(), TMC::TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
128128
}
129129
void set_pwm_thrs(const uint32_t thrs) {
130130
TMC::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
@@ -197,7 +197,7 @@ class TMCMarlin<TMC2208Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC220
197197

198198
#if ENABLED(HYBRID_THRESHOLD)
199199
uint32_t get_pwm_thrs() {
200-
return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
200+
return _tmc_thrs(this->microsteps(), TMC2208Stepper::TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
201201
}
202202
void set_pwm_thrs(const uint32_t thrs) {
203203
TMC2208Stepper::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
@@ -249,13 +249,14 @@ class TMCMarlin<TMC2209Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC220
249249

250250
#if ENABLED(HYBRID_THRESHOLD)
251251
uint32_t get_pwm_thrs() {
252-
return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
252+
return _tmc_thrs(this->microsteps(), TMC2209Stepper::TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
253253
}
254254
void set_pwm_thrs(const uint32_t thrs) {
255255
TMC2209Stepper::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
256256
TERN_(HAS_MARLINUI_MENU, this->stored.hybrid_thrs = thrs);
257257
}
258258
#endif
259+
259260
#if USE_SENSORLESS
260261
int16_t homing_threshold() { return TMC2209Stepper::SGTHRS(); }
261262
void homing_threshold(int16_t sgt_val) {
@@ -278,6 +279,74 @@ class TMCMarlin<TMC2209Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC220
278279
sgt_max = 255;
279280
};
280281

282+
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
283+
class TMCMarlin<TMC2240Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC2240Stepper, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
284+
public:
285+
TMCMarlin(const uint16_t cs_pin, const uint8_t axis_chain_index) :
286+
TMC2240Stepper(cs_pin, axis_chain_index)
287+
{}
288+
TMCMarlin(const uint16_t CS, const uint16_t pinMOSI, const uint16_t pinMISO, const uint16_t pinSCK, const uint8_t axis_chain_index) :
289+
TMC2240Stepper(CS, pinMOSI, pinMISO, pinSCK, axis_chain_index )
290+
{}
291+
292+
//uint8_t get_address() { return slave_address; }
293+
uint16_t get_microstep_counter() { return microsteps(); }
294+
295+
uint16_t rms_current() { return TMC2240Stepper::rms_current(); }
296+
void rms_current(const uint16_t mA) {
297+
this->val_mA = mA;
298+
TMC2240Stepper::rms_current(mA);
299+
}
300+
void rms_current(const uint16_t mA, const float mult) {
301+
this->val_mA = mA;
302+
TMC2240Stepper::rms_current(mA, mult);
303+
}
304+
305+
#if HAS_STEALTHCHOP
306+
bool get_stealthChop() { return this->en_pwm_mode(); }
307+
bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; }
308+
void refresh_stepping_mode() { this->en_pwm_mode(this->stored.stealthChop_enabled); }
309+
void set_stealthChop(const bool stch) { this->stored.stealthChop_enabled = stch; refresh_stepping_mode(); }
310+
bool toggle_stepping_mode() { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); }
311+
#endif
312+
313+
void set_chopper_times(const chopper_timing_t &ct) {
314+
TMC2240Stepper::toff(ct.toff);
315+
TMC2240Stepper::hysteresis_end(ct.hend);
316+
TMC2240Stepper::hysteresis_start(ct.hstrt);
317+
}
318+
319+
#if ENABLED(HYBRID_THRESHOLD)
320+
uint32_t get_pwm_thrs() {
321+
return _tmc_thrs(this->microsteps(), TMC2240Stepper::TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
322+
}
323+
void set_pwm_thrs(const uint32_t thrs) {
324+
TMC2240Stepper::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
325+
TERN_(HAS_MARLINUI_MENU, this->stored.hybrid_thrs = thrs);
326+
}
327+
#endif
328+
329+
#if USE_SENSORLESS
330+
int16_t homing_threshold() { return TMC2240Stepper::sgt(); }
331+
void homing_threshold(int16_t sgt_val) {
332+
sgt_val = (int16_t)constrain(sgt_val, sgt_min, sgt_max);
333+
TMC2240Stepper::sgt(sgt_val);
334+
TERN_(HAS_MARLINUI_MENU, this->stored.homing_thrs = sgt_val);
335+
}
336+
#endif
337+
338+
void refresh_stepper_current() { rms_current(this->val_mA); }
339+
#if ENABLED(HYBRID_THRESHOLD)
340+
void refresh_hybrid_thrs() { set_pwm_thrs(this->stored.hybrid_thrs); }
341+
#endif
342+
#if USE_SENSORLESS
343+
void refresh_homing_thrs() { homing_threshold(this->stored.homing_thrs); }
344+
#endif
345+
346+
static constexpr int8_t sgt_min = -64,
347+
sgt_max = 63;
348+
};
349+
281350
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
282351
class TMCMarlin<TMC2660Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC2660Stepper, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
283352
public:

Marlin/src/gcode/feature/trinamic/M911-M914.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232

3333
#if ENABLED(MONITOR_DRIVER_STATUS)
3434

35-
#define M91x_USE(ST) (AXIS_DRIVER_TYPE(ST, TMC2130) || AXIS_DRIVER_TYPE(ST, TMC2160) || AXIS_DRIVER_TYPE(ST, TMC2208) || AXIS_DRIVER_TYPE(ST, TMC2209) || AXIS_DRIVER_TYPE(ST, TMC2660) || AXIS_DRIVER_TYPE(ST, TMC5130) || AXIS_DRIVER_TYPE(ST, TMC5160))
35+
#define M91x_USE(ST) (AXIS_DRIVER_TYPE(ST, TMC2130) || AXIS_DRIVER_TYPE(ST, TMC2160) \
36+
|| AXIS_DRIVER_TYPE(ST, TMC2208) || AXIS_DRIVER_TYPE(ST, TMC2209) || AXIS_DRIVER_TYPE(ST, TMC2240) \
37+
|| AXIS_DRIVER_TYPE(ST, TMC2660) || AXIS_DRIVER_TYPE(ST, TMC5130) || AXIS_DRIVER_TYPE(ST, TMC5160))
3638
#define M91x_USE_E(N) (E_STEPPERS > N && M91x_USE(E##N))
3739

3840
#if HAS_X_AXIS && (M91x_USE(X) || M91x_USE(X2))
@@ -68,7 +70,7 @@
6870
#endif
6971

7072
#if !M91x_SOME_X && !M91x_SOME_Y && !M91x_SOME_Z && !M91x_USE_I && !M91x_USE_J && !M91x_USE_K && !M91x_USE_U && !M91x_USE_V && !M91x_USE_W && !M91x_SOME_E
71-
#error "MONITOR_DRIVER_STATUS requires at least one TMC2130, 2160, 2208, 2209, 2660, 5130, or 5160."
73+
#error "MONITOR_DRIVER_STATUS requires at least one TMC2130, 2160, 2208, 2209, 2240, 2660, 5130, or 5160."
7274
#endif
7375

7476
template<typename TMC>

0 commit comments

Comments
 (0)