From e5edbf9d3526953f7683f03abdb88355fd8a79c9 Mon Sep 17 00:00:00 2001
From: elementfoundry <57408038+elementfoundry@users.noreply.github.com>
Date: Thu, 19 Dec 2019 01:23:54 -0700
Subject: [PATCH] Allow TMC2209 to save/restore spreadCycle (#16153)

Co-Authored-By: teemuatlut <teemu.mantykallio@live.fi>
---
 Marlin/src/feature/tmc_util.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Marlin/src/feature/tmc_util.cpp b/Marlin/src/feature/tmc_util.cpp
index f5c95098316..3eb29c0f995 100644
--- a/Marlin/src/feature/tmc_util.cpp
+++ b/Marlin/src/feature/tmc_util.cpp
@@ -1038,9 +1038,10 @@
 
   bool tmc_enable_stallguard(TMC2209Stepper &st) {
     st.TCOOLTHRS(0xFFFFF);
-    return true;
+    return stealthchop_was_enabled;
   }
-  void tmc_disable_stallguard(TMC2209Stepper &st, const bool restore_stealth _UNUSED) {
+  void tmc_disable_stallguard(TMC2209Stepper &st, const bool restore_stealth) {
+    st.en_spreadCycle(!restore_stealth);
     st.TCOOLTHRS(0);
   }