From 1b989b81e0be596d6b61599c8bce0d8a21c606ee Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 28 Feb 2021 18:30:25 -0500 Subject: [PATCH] tmc: Fix order of init during sensorless homing With commit 53b10d3a the setup of sensorless homing could occur before the driver was enabled which would cause the reinitialization of the driver settings to undo the sensorless homing setup. Use set_field() when setting the sensorless homing registers so that it wont conflict with a driver init. Signed-off-by: Kevin O'Connor --- klippy/extras/tmc.py | 12 ++++++++---- klippy/extras/tmc5160.py | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/klippy/extras/tmc.py b/klippy/extras/tmc.py index d3249540..8ac22ae7 100644 --- a/klippy/extras/tmc.py +++ b/klippy/extras/tmc.py @@ -347,26 +347,30 @@ class TMCVirtualPinHelper: reg = self.fields.lookup_register("en_pwm_mode", None) if reg is None: # On "stallguard4" drivers, "stealthchop" must be enabled - self.mcu_tmc.set_register("TPWMTHRS", 0) + tp_val = self.fields.set_field("TPWMTHRS", 0) + self.mcu_tmc.set_register("TPWMTHRS", tp_val) val = self.fields.set_field("en_spreadCycle", 0) else: # On earlier drivers, "stealthchop" must be disabled self.fields.set_field("en_pwm_mode", 0) val = self.fields.set_field(self.diag_pin_field, 1) self.mcu_tmc.set_register("GCONF", val) - self.mcu_tmc.set_register("TCOOLTHRS", 0xfffff) + tc_val = self.fields.set_field("TCOOLTHRS", 0xfffff) + self.mcu_tmc.set_register("TCOOLTHRS", tc_val) def handle_homing_move_end(self, endstops): if self.mcu_endstop not in endstops: return reg = self.fields.lookup_register("en_pwm_mode", None) if reg is None: - self.mcu_tmc.set_register("TPWMTHRS", self.pwmthrs) + tp_val = self.fields.set_field("TPWMTHRS", self.pwmthrs) + self.mcu_tmc.set_register("TPWMTHRS", tp_val) val = self.fields.set_field("en_spreadCycle", not self.en_pwm) else: self.fields.set_field("en_pwm_mode", self.en_pwm) val = self.fields.set_field(self.diag_pin_field, 0) self.mcu_tmc.set_register("GCONF", val) - self.mcu_tmc.set_register("TCOOLTHRS", 0) + tc_val = self.fields.set_field("TCOOLTHRS", 0) + self.mcu_tmc.set_register("TCOOLTHRS", tc_val) ###################################################################### diff --git a/klippy/extras/tmc5160.py b/klippy/extras/tmc5160.py index 70c331c1..adc172da 100644 --- a/klippy/extras/tmc5160.py +++ b/klippy/extras/tmc5160.py @@ -208,6 +208,9 @@ Fields["TPOWERDOWN"] = { Fields["TPWMTHRS"] = { "TPWMTHRS": 0xfffff << 0 } +Fields["TCOOLTHRS"] = { + "TCOOLTHRS": 0xfffff << 0 +} Fields["TSTEP"] = { "TSTEP": 0xfffff << 0 }