From b779b42ffd00ca608fb46f522cb5b3e35554f361 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Mon, 5 Nov 2018 02:48:43 -0600
Subject: [PATCH] Prevent current step-down going negative

Addressing #11348
---
 Marlin/src/feature/tmc_util.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Marlin/src/feature/tmc_util.cpp b/Marlin/src/feature/tmc_util.cpp
index 1b14172ca7..07128df4fc 100644
--- a/Marlin/src/feature/tmc_util.cpp
+++ b/Marlin/src/feature/tmc_util.cpp
@@ -153,7 +153,7 @@
     #if CURRENT_STEP_DOWN > 0
       // Decrease current if is_otpw is true and driver is enabled and there's been more than 4 warnings
       if (data.is_otpw && st.isEnabled() && st.otpw_count > 4) {
-        st.rms_current(st.getMilliamps() - (CURRENT_STEP_DOWN));
+        st.rms_current(MAX(int16_t(st.getMilliamps() - (CURRENT_STEP_DOWN)), 0));
         #if ENABLED(REPORT_CURRENT_CHANGE)
           st.printLabel();
           SERIAL_ECHOLNPAIR(" current decreased to ", st.getMilliamps());
-- 
GitLab