Skip to content

Commit eb254ef

Browse files
sjasonsmiththinkyhead
authored andcommitted
Fix TMC_HOME_PHASE divide by zero (MarlinFirmware#20368)
1 parent 3327568 commit eb254ef

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Marlin/src/module/motion.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -1466,26 +1466,28 @@ void set_axis_never_homed(const AxisEnum axis) {
14661466
effectorBackoutDir, // Direction in which the effector mm coordinates move away from endstop.
14671467
stepperBackoutDir; // Direction in which the TMC µstep count(phase) move away from endstop.
14681468

1469+
#define PHASE_PER_MICROSTEP(N) (256 / _MAX(1, N##_MICROSTEPS))
1470+
14691471
switch (axis) {
14701472
#ifdef X_MICROSTEPS
14711473
case X_AXIS:
1472-
phasePerUStep = 256 / (X_MICROSTEPS);
1474+
phasePerUStep = PHASE_PER_MICROSTEP(X);
14731475
phaseCurrent = stepperX.get_microstep_counter();
14741476
effectorBackoutDir = -X_HOME_DIR;
14751477
stepperBackoutDir = INVERT_X_DIR ? effectorBackoutDir : -effectorBackoutDir;
14761478
break;
14771479
#endif
14781480
#ifdef Y_MICROSTEPS
14791481
case Y_AXIS:
1480-
phasePerUStep = 256 / (Y_MICROSTEPS);
1482+
phasePerUStep = PHASE_PER_MICROSTEP(Y);
14811483
phaseCurrent = stepperY.get_microstep_counter();
14821484
effectorBackoutDir = -Y_HOME_DIR;
14831485
stepperBackoutDir = INVERT_Y_DIR ? effectorBackoutDir : -effectorBackoutDir;
14841486
break;
14851487
#endif
14861488
#ifdef Z_MICROSTEPS
14871489
case Z_AXIS:
1488-
phasePerUStep = 256 / (Z_MICROSTEPS);
1490+
phasePerUStep = PHASE_PER_MICROSTEP(Z);
14891491
phaseCurrent = stepperZ.get_microstep_counter();
14901492
effectorBackoutDir = -Z_HOME_DIR;
14911493
stepperBackoutDir = INVERT_Z_DIR ? effectorBackoutDir : -effectorBackoutDir;

0 commit comments

Comments
 (0)