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 <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-02-28 18:30:25 -05:00
parent 36ca639e1f
commit 1b989b81e0
2 changed files with 11 additions and 4 deletions

View File

@ -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)
######################################################################

View File

@ -208,6 +208,9 @@ Fields["TPOWERDOWN"] = {
Fields["TPWMTHRS"] = {
"TPWMTHRS": 0xfffff << 0
}
Fields["TCOOLTHRS"] = {
"TCOOLTHRS": 0xfffff << 0
}
Fields["TSTEP"] = {
"TSTEP": 0xfffff << 0
}