From 8f76e53c0eef351576be7fa2acbb964af031d7b3 Mon Sep 17 00:00:00 2001
From: Kevin O'Connor <kevin@koconnor.net>
Date: Sun, 25 Apr 2021 15:02:42 -0400
Subject: [PATCH] stepper: Remove min_stop_interval from mcu code

Now that the host never uses a min_stop_interval, remove it from the
mcu code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
---
 docs/Benchmarks.md   | 80 ++++++++++++++++++++++----------------------
 docs/G-Codes.md      | 16 ++++-----
 docs/MCU_Commands.md | 17 ++++------
 klippy/mcu.py        |  2 +-
 klippy/stepper.py    |  3 +-
 src/stepper.c        | 16 ++-------
 6 files changed, 58 insertions(+), 76 deletions(-)

diff --git a/docs/Benchmarks.md b/docs/Benchmarks.md
index ebec62f61..faf2ed1b3 100644
--- a/docs/Benchmarks.md
+++ b/docs/Benchmarks.md
@@ -92,9 +92,9 @@ The following configuration sequence is used on AVR chips:
 ```
 PINS arduino
 allocate_oids count=3
-config_stepper oid=0 step_pin=ar29 dir_pin=ar28 min_stop_interval=0 invert_step=0
-config_stepper oid=1 step_pin=ar27 dir_pin=ar26 min_stop_interval=0 invert_step=0
-config_stepper oid=2 step_pin=ar23 dir_pin=ar22 min_stop_interval=0 invert_step=0
+config_stepper oid=0 step_pin=ar29 dir_pin=ar28 invert_step=0
+config_stepper oid=1 step_pin=ar27 dir_pin=ar26 invert_step=0
+config_stepper oid=2 step_pin=ar23 dir_pin=ar22 invert_step=0
 finalize_config crc=0
 ```
 
@@ -114,9 +114,9 @@ results match tests on both a 16Mhz at90usb and a 16Mhz atmega2560).
 The following configuration sequence is used on the Due:
 ```
 allocate_oids count=3
-config_stepper oid=0 step_pin=PB27 dir_pin=PA21 min_stop_interval=0 invert_step=0
-config_stepper oid=1 step_pin=PB26 dir_pin=PC30 min_stop_interval=0 invert_step=0
-config_stepper oid=2 step_pin=PA21 dir_pin=PC30 min_stop_interval=0 invert_step=0
+config_stepper oid=0 step_pin=PB27 dir_pin=PA21 invert_step=0
+config_stepper oid=1 step_pin=PB26 dir_pin=PC30 invert_step=0
+config_stepper oid=2 step_pin=PA21 dir_pin=PC30 invert_step=0
 finalize_config crc=0
 ```
 
@@ -136,9 +136,9 @@ The test was last run on commit `8d4a5c16` with gcc version
 The following configuration sequence is used on the Duet Maestro:
 ```
 allocate_oids count=3
-config_stepper oid=0 step_pin=PC26 dir_pin=PC18 min_stop_interval=0 invert_step=0
-config_stepper oid=1 step_pin=PC26 dir_pin=PA8 min_stop_interval=0 invert_step=0
-config_stepper oid=2 step_pin=PC26 dir_pin=PB4 min_stop_interval=0 invert_step=0
+config_stepper oid=0 step_pin=PC26 dir_pin=PC18 invert_step=0
+config_stepper oid=1 step_pin=PC26 dir_pin=PA8 invert_step=0
+config_stepper oid=2 step_pin=PC26 dir_pin=PB4 invert_step=0
 finalize_config crc=0
 ```
 
@@ -158,10 +158,10 @@ The test was last run on commit `8d4a5c16` with gcc version
 The following configuration sequence is used on the Duet Wifi:
 ```
 allocate_oids count=4
-config_stepper oid=0 step_pin=PD6 dir_pin=PD11 min_stop_interval=0 invert_step=0
-config_stepper oid=1 step_pin=PD7 dir_pin=PD12 min_stop_interval=0 invert_step=0
-config_stepper oid=2 step_pin=PD8 dir_pin=PD13 min_stop_interval=0 invert_step=0
-config_stepper oid=3 step_pin=PD5 dir_pin=PA1 min_stop_interval=0 invert_step=0
+config_stepper oid=0 step_pin=PD6 dir_pin=PD11 invert_step=0
+config_stepper oid=1 step_pin=PD7 dir_pin=PD12 invert_step=0
+config_stepper oid=2 step_pin=PD8 dir_pin=PD13 invert_step=0
+config_stepper oid=3 step_pin=PD5 dir_pin=PA1 invert_step=0
 finalize_config crc=0
 
 ```
@@ -183,9 +183,9 @@ The following configuration sequence is used on the PRU:
 ```
 PINS beaglebone
 allocate_oids count=3
-config_stepper oid=0 step_pin=P8_13 dir_pin=P8_12 min_stop_interval=0 invert_step=0
-config_stepper oid=1 step_pin=P8_15 dir_pin=P8_14 min_stop_interval=0 invert_step=0
-config_stepper oid=2 step_pin=P8_19 dir_pin=P8_18 min_stop_interval=0 invert_step=0
+config_stepper oid=0 step_pin=P8_13 dir_pin=P8_12 invert_step=0
+config_stepper oid=1 step_pin=P8_15 dir_pin=P8_14 invert_step=0
+config_stepper oid=2 step_pin=P8_19 dir_pin=P8_18 invert_step=0
 finalize_config crc=0
 ```
 
@@ -203,9 +203,9 @@ The test was last run on commit `b161a69e` with gcc version `pru-gcc
 The following configuration sequence is used on the STM32F042:
 ```
 allocate_oids count=3
-config_stepper oid=0 step_pin=PA1 dir_pin=PA2 min_stop_interval=0 invert_step=0
-config_stepper oid=1 step_pin=PA3 dir_pin=PA2 min_stop_interval=0 invert_step=0
-config_stepper oid=2 step_pin=PB8 dir_pin=PA2 min_stop_interval=0 invert_step=0
+config_stepper oid=0 step_pin=PA1 dir_pin=PA2 invert_step=0
+config_stepper oid=1 step_pin=PA3 dir_pin=PA2 invert_step=0
+config_stepper oid=2 step_pin=PB8 dir_pin=PA2 invert_step=0
 finalize_config crc=0
 ```
 
@@ -223,9 +223,9 @@ The test was last run on commit `0b0c47c5` with gcc version
 The following configuration sequence is used on the STM32F103:
 ```
 allocate_oids count=3
-config_stepper oid=0 step_pin=PC13 dir_pin=PB5 min_stop_interval=0 invert_step=0
-config_stepper oid=1 step_pin=PB3 dir_pin=PB6 min_stop_interval=0 invert_step=0
-config_stepper oid=2 step_pin=PA4 dir_pin=PB7 min_stop_interval=0 invert_step=0
+config_stepper oid=0 step_pin=PC13 dir_pin=PB5 invert_step=0
+config_stepper oid=1 step_pin=PB3 dir_pin=PB6 invert_step=0
+config_stepper oid=2 step_pin=PA4 dir_pin=PB7 invert_step=0
 finalize_config crc=0
 ```
 
@@ -245,10 +245,10 @@ The test was last run on commit `8d4a5c16` with gcc version
 The following configuration sequence is used on the STM32F4:
 ```
 allocate_oids count=4
-config_stepper oid=0 step_pin=PA5 dir_pin=PB5 min_stop_interval=0 invert_step=0
-config_stepper oid=1 step_pin=PB2 dir_pin=PB6 min_stop_interval=0 invert_step=0
-config_stepper oid=2 step_pin=PB3 dir_pin=PB7 min_stop_interval=0 invert_step=0
-config_stepper oid=3 step_pin=PB3 dir_pin=PB8 min_stop_interval=0 invert_step=0
+config_stepper oid=0 step_pin=PA5 dir_pin=PB5 invert_step=0
+config_stepper oid=1 step_pin=PB2 dir_pin=PB6 invert_step=0
+config_stepper oid=2 step_pin=PB3 dir_pin=PB7 invert_step=0
+config_stepper oid=3 step_pin=PB3 dir_pin=PB8 invert_step=0
 finalize_config crc=0
 ```
 
@@ -280,9 +280,9 @@ using a 168Mhz clock).
 The following configuration sequence is used on the LPC176x:
 ```
 allocate_oids count=3
-config_stepper oid=0 step_pin=P1.20 dir_pin=P1.18 min_stop_interval=0 invert_step=0
-config_stepper oid=1 step_pin=P1.21 dir_pin=P1.18 min_stop_interval=0 invert_step=0
-config_stepper oid=2 step_pin=P1.23 dir_pin=P1.18 min_stop_interval=0 invert_step=0
+config_stepper oid=0 step_pin=P1.20 dir_pin=P1.18 invert_step=0
+config_stepper oid=1 step_pin=P1.21 dir_pin=P1.18 invert_step=0
+config_stepper oid=2 step_pin=P1.23 dir_pin=P1.18 invert_step=0
 finalize_config crc=0
 ```
 
@@ -311,9 +311,9 @@ results were obtained by overclocking an LPC1768 to 120Mhz.
 The following configuration sequence is used on the SAMD21:
 ```
 allocate_oids count=3
-config_stepper oid=0 step_pin=PA27 dir_pin=PA20 min_stop_interval=0 invert_step=0
-config_stepper oid=1 step_pin=PB3 dir_pin=PA21 min_stop_interval=0 invert_step=0
-config_stepper oid=2 step_pin=PA17 dir_pin=PA21 min_stop_interval=0 invert_step=0
+config_stepper oid=0 step_pin=PA27 dir_pin=PA20 invert_step=0
+config_stepper oid=1 step_pin=PB3 dir_pin=PA21 invert_step=0
+config_stepper oid=2 step_pin=PA17 dir_pin=PA21 invert_step=0
 finalize_config crc=0
 ```
 
@@ -334,11 +334,11 @@ micro-controller.
 The following configuration sequence is used on the SAMD51:
 ```
 allocate_oids count=5
-config_stepper oid=0 step_pin=PA22 dir_pin=PA20 min_stop_interval=0 invert_step=0
-config_stepper oid=1 step_pin=PA22 dir_pin=PA21 min_stop_interval=0 invert_step=0
-config_stepper oid=2 step_pin=PA22 dir_pin=PA19 min_stop_interval=0 invert_step=0
-config_stepper oid=3 step_pin=PA22 dir_pin=PA18 min_stop_interval=0 invert_step=0
-config_stepper oid=4 step_pin=PA23 dir_pin=PA17 min_stop_interval=0 invert_step=0
+config_stepper oid=0 step_pin=PA22 dir_pin=PA20 invert_step=0
+config_stepper oid=1 step_pin=PA22 dir_pin=PA21 invert_step=0
+config_stepper oid=2 step_pin=PA22 dir_pin=PA19 invert_step=0
+config_stepper oid=3 step_pin=PA22 dir_pin=PA18 invert_step=0
+config_stepper oid=4 step_pin=PA23 dir_pin=PA17 invert_step=0
 finalize_config crc=0
 ```
 
@@ -365,9 +365,9 @@ micro-controller.
 The following configuration sequence is used on a Raspberry Pi:
 ```
 allocate_oids count=3
-config_stepper oid=0 step_pin=gpio2 dir_pin=gpio3 min_stop_interval=0 invert_step=0
-config_stepper oid=1 step_pin=gpio4 dir_pin=gpio5 min_stop_interval=0 invert_step=0
-config_stepper oid=2 step_pin=gpio6 dir_pin=gpio7 min_stop_interval=0 invert_step=0
+config_stepper oid=0 step_pin=gpio2 dir_pin=gpio3 invert_step=0
+config_stepper oid=1 step_pin=gpio4 dir_pin=gpio5 invert_step=0
+config_stepper oid=2 step_pin=gpio6 dir_pin=gpio7 invert_step=0
 finalize_config crc=0
 ```
 
diff --git a/docs/G-Codes.md b/docs/G-Codes.md
index b8b96636e..2f012bf55 100644
--- a/docs/G-Codes.md
+++ b/docs/G-Codes.md
@@ -517,15 +517,13 @@ enabled:
   the given distance (in mm) at the given constant velocity (in
   mm/s). If ACCEL is specified and is greater than zero, then the
   given acceleration (in mm/s^2) will be used; otherwise no
-  acceleration is performed. If acceleration is not performed then it
-  can lead to the micro-controller reporting "No next step" errors
-  (avoid these errors by specifying an ACCEL value or use a very low
-  VELOCITY). No boundary checks are performed; no kinematic updates
-  are made; other parallel steppers on an axis will not be moved. Use
-  caution as an incorrect command could cause damage! Using this
-  command will almost certainly place the low-level kinematics in an
-  incorrect state; issue a G28 afterwards to reset the kinematics.
-  This command is intended for low-level diagnostics and debugging.
+  acceleration is performed. No boundary checks are performed; no
+  kinematic updates are made; other parallel steppers on an axis will
+  not be moved. Use caution as an incorrect command could cause
+  damage! Using this command will almost certainly place the low-level
+  kinematics in an incorrect state; issue a G28 afterwards to reset
+  the kinematics. This command is intended for low-level diagnostics
+  and debugging.
 - `SET_KINEMATIC_POSITION [X=<value>] [Y=<value>] [Z=<value>]`: Force
   the low-level kinematic code to believe the toolhead is at the given
   cartesian position. This is a diagnostic and debugging command; use
diff --git a/docs/MCU_Commands.md b/docs/MCU_Commands.md
index e599ccff8..1859f33a7 100644
--- a/docs/MCU_Commands.md
+++ b/docs/MCU_Commands.md
@@ -138,17 +138,12 @@ This section lists some commonly used config commands.
   sampled at regular interval using the query_analog_in command (see
   below).
 
-* `config_stepper oid=%c step_pin=%c dir_pin=%c min_stop_interval=%u
-  invert_step=%c` : This command creates an internal stepper
-  object. The 'step_pin' and 'dir_pin' parameters specify the step and
-  direction pins respectively; this command will configure them in
-  digital output mode. The 'invert_step' parameter specifies whether a
-  step occurs on a rising edge (invert_step=0) or falling edge
-  (invert_step=1). The 'min_stop_interval' implements a safety
-  feature - it is checked when the micro-controller finishes all moves
-  for a stepper - if it is non-zero it specifies the minimum number of
-  clock ticks since the last step. It is used as a check on the
-  maximum stepper velocity that a stepper may have before stopping.
+* `config_stepper oid=%c step_pin=%c dir_pin=%c invert_step=%c` : This
+  command creates an internal stepper object. The 'step_pin' and
+  'dir_pin' parameters specify the step and direction pins
+  respectively; this command will configure them in digital output
+  mode. The 'invert_step' parameter specifies whether a step occurs on
+  a rising edge (invert_step=0) or falling edge (invert_step=1).
 
 * `config_endstop oid=%c pin=%c pull_up=%c stepper_count=%c` : This
   command creates an internal "endstop" object. It is used to specify
diff --git a/klippy/mcu.py b/klippy/mcu.py
index 849f8deb2..fa35c2bff 100644
--- a/klippy/mcu.py
+++ b/klippy/mcu.py
@@ -824,7 +824,7 @@ class MCU:
         return False, '%s: %s' % (self._name, stats)
 
 Common_MCU_errors = {
-    ("Timer too close", "No next step"): """
+    ("Timer too close",): """
 This often indicates the host computer is overloaded. Check
 for other processes consuming excessive CPU time, high swap
 usage, disk errors, overheating, unstable voltage, or
diff --git a/klippy/stepper.py b/klippy/stepper.py
index a110843db..ab981e969 100644
--- a/klippy/stepper.py
+++ b/klippy/stepper.py
@@ -61,8 +61,7 @@ class MCU_stepper:
         self.set_stepper_kinematics(sk)
     def _build_config(self):
         self._mcu.add_config_cmd(
-            "config_stepper oid=%d step_pin=%s dir_pin=%s"
-            " min_stop_interval=0 invert_step=%d" % (
+            "config_stepper oid=%d step_pin=%s dir_pin=%s invert_step=%d" % (
                 self._oid, self._step_pin, self._dir_pin, self._invert_step))
         self._mcu.add_config_cmd("reset_step_clock oid=%d clock=0"
                                  % (self._oid,), on_restart=True)
diff --git a/src/stepper.c b/src/stepper.c
index f191be6e5..83da362dc 100644
--- a/src/stepper.c
+++ b/src/stepper.c
@@ -44,7 +44,6 @@ struct stepper {
     struct gpio_out step_pin, dir_pin;
     uint32_t position;
     struct move_queue_head mq;
-    uint32_t min_stop_interval;
     // gcc (pre v6) does better optimization when uint8_t are bitfields
     uint8_t flags : 8;
 };
@@ -53,7 +52,7 @@ enum { POSITION_BIAS=0x40000000 };
 
 enum {
     SF_LAST_DIR=1<<0, SF_NEXT_DIR=1<<1, SF_INVERT_STEP=1<<2, SF_HAVE_ADD=1<<3,
-    SF_LAST_RESET=1<<4, SF_NO_NEXT_CHECK=1<<5, SF_NEED_RESET=1<<6
+    SF_LAST_RESET=1<<4, SF_NEED_RESET=1<<5
 };
 
 // Setup a stepper for the next move in its queue
@@ -62,9 +61,6 @@ stepper_load_next(struct stepper *s, uint32_t min_next_time)
 {
     if (move_queue_empty(&s->mq)) {
         // There is no next move - the queue is empty
-        if (s->interval - s->add < s->min_stop_interval
-            && !(s->flags & SF_NO_NEXT_CHECK))
-            shutdown("No next step");
         s->count = 0;
         return SF_DONE;
     }
@@ -186,16 +182,14 @@ command_config_stepper(uint32_t *args)
     struct stepper *s = oid_alloc(args[0], command_config_stepper, sizeof(*s));
     if (!CONFIG_INLINE_STEPPER_HACK)
         s->time.func = stepper_event;
-    s->flags = args[4] ? SF_INVERT_STEP : 0;
+    s->flags = args[3] ? SF_INVERT_STEP : 0;
     s->step_pin = gpio_out_setup(args[1], s->flags & SF_INVERT_STEP);
     s->dir_pin = gpio_out_setup(args[2], 0);
-    s->min_stop_interval = args[3];
     s->position = -POSITION_BIAS;
     move_queue_setup(&s->mq, sizeof(struct stepper_move));
 }
 DECL_COMMAND(command_config_stepper,
-             "config_stepper oid=%c step_pin=%c dir_pin=%c"
-             " min_stop_interval=%u invert_step=%c");
+             "config_stepper oid=%c step_pin=%c dir_pin=%c invert_step=%c");
 
 // Return the 'struct stepper' for a given stepper oid
 struct stepper *
@@ -223,10 +217,6 @@ command_queue_step(uint32_t *args)
         flags ^= SF_LAST_DIR;
         m->flags |= MF_DIR;
     }
-    flags &= ~SF_NO_NEXT_CHECK;
-    if (m->count == 1 && (m->flags || flags & SF_LAST_RESET))
-        // count=1 moves after a reset or dir change can have small intervals
-        flags |= SF_NO_NEXT_CHECK;
     flags &= ~SF_LAST_RESET;
     if (s->count) {
         s->flags = flags;