Skip to content

Commit

Permalink
tmc: Fix order of init during sensorless homing
Browse files Browse the repository at this point in the history
With commit 53b10d3 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 <[email protected]>
  • Loading branch information
KevinOConnor committed Feb 28, 2021
1 parent 36ca639 commit 1b989b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 8 additions & 4 deletions klippy/extras/tmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,26 +347,30 @@ def handle_homing_move_begin(self, endstops):
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)


######################################################################
Expand Down
3 changes: 3 additions & 0 deletions klippy/extras/tmc5160.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@
Fields["TPWMTHRS"] = {
"TPWMTHRS": 0xfffff << 0
}
Fields["TCOOLTHRS"] = {
"TCOOLTHRS": 0xfffff << 0
}
Fields["TSTEP"] = {
"TSTEP": 0xfffff << 0
}
Expand Down

0 comments on commit 1b989b8

Please sign in to comment.