aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-06-25 18:15:17 -0400
committerKevin O'Connor <kevin@koconnor.net>2019-06-25 18:19:05 -0400
commit6ec7dee07d20de1a58c2c0b103513efb45d7d205 (patch)
tree76cf1b1ae31fcbef040259634d102b8eea1098ed /klippy/extras
parent79c24f95b3e87957056b943b8883e88031846798 (diff)
downloadkutter-6ec7dee07d20de1a58c2c0b103513efb45d7d205.tar.gz
kutter-6ec7dee07d20de1a58c2c0b103513efb45d7d205.tar.xz
kutter-6ec7dee07d20de1a58c2c0b103513efb45d7d205.zip
tmc: It's not valid to schedule messages with print_time=0
A print_time of zero may translate to a negative clock on a secondary micro-controller, which would cause an internal error. Change the code to pass a real print_time or None if it is not needed. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras')
-rw-r--r--klippy/extras/tmc.py4
-rw-r--r--klippy/extras/tmc2130.py8
-rw-r--r--klippy/extras/tmc2660.py17
-rw-r--r--klippy/extras/tmc_uart.py6
4 files changed, 21 insertions, 14 deletions
diff --git a/klippy/extras/tmc.py b/klippy/extras/tmc.py
index 46b9a8cf..f0a9ad38 100644
--- a/klippy/extras/tmc.py
+++ b/klippy/extras/tmc.py
@@ -96,7 +96,7 @@ class TMCCommandHelper:
self.cmd_INIT_TMC, desc=self.cmd_INIT_TMC_help)
self.printer.register_event_handler("klippy:connect",
self._handle_connect)
- def _init_registers(self, print_time):
+ def _init_registers(self, print_time=None):
# Send registers
for reg_name, val in self.fields.registers.items():
self.mcu_tmc.set_register(reg_name, val, print_time)
@@ -104,7 +104,7 @@ class TMCCommandHelper:
retry_count = 0
while 1:
try:
- self._init_registers(0.)
+ self._init_registers()
return
except self.printer.command_error as e:
logging.exception("TMC init error")
diff --git a/klippy/extras/tmc2130.py b/klippy/extras/tmc2130.py
index 4dce19c9..bb235962 100644
--- a/klippy/extras/tmc2130.py
+++ b/klippy/extras/tmc2130.py
@@ -186,12 +186,14 @@ class MCU_TMC_SPI:
params = self.spi.spi_transfer([reg, 0x00, 0x00, 0x00, 0x00])
pr = bytearray(params['response'])
return (pr[1] << 24) | (pr[2] << 16) | (pr[3] << 8) | pr[4]
- def set_register(self, reg_name, val, print_time=0.):
- min_clock = self.spi.get_mcu().print_time_to_clock(print_time)
+ def set_register(self, reg_name, val, print_time=None):
+ minclock = 0
+ if print_time is not None:
+ minclock = self.spi.get_mcu().print_time_to_clock(print_time)
reg = Registers[reg_name]
data = [(reg | 0x80) & 0xff, (val >> 24) & 0xff, (val >> 16) & 0xff,
(val >> 8) & 0xff, val & 0xff]
- self.spi.spi_send(data, min_clock)
+ self.spi.spi_send(data, minclock)
######################################################################
diff --git a/klippy/extras/tmc2660.py b/klippy/extras/tmc2660.py
index 893f8d1b..cb9b6c86 100644
--- a/klippy/extras/tmc2660.py
+++ b/klippy/extras/tmc2660.py
@@ -169,7 +169,8 @@ class TMC2660CurrentHelper:
return vsense, cs
def handle_printing(self, print_time):
- self.set_current(0., self.current) # workaround
+ print_time -= 0.100 # Schedule slightly before deadline
+ self.set_current(print_time, self.current)
def handle_ready(self, print_time):
self.set_current(print_time, (float(self.idle_current_percentage)
@@ -213,15 +214,17 @@ class MCU_TMC2660_SPI:
val = self.fields.set_field("RDSEL", ReadRegisters.index(reg_name))
if self.printer.get_start_args().get('debugoutput') is not None:
return 0
- params = self.spi.spi_transfer([((val >> 16) | reg) & 0xff,
- (val >> 8) & 0xff, val & 0xff])
+ msg = [((val >> 16) | reg) & 0xff, (val >> 8) & 0xff, val & 0xff]
+ params = self.spi.spi_transfer(msg)
pr = bytearray(params['response'])
return (pr[0] << 16) | (pr[1] << 8) | pr[2]
- def set_register(self, reg_name, val, print_time=0.):
- min_clock = self.spi.get_mcu().print_time_to_clock(print_time)
+ def set_register(self, reg_name, val, print_time=None):
+ minclock = 0
+ if print_time is not None:
+ minclock = self.spi.get_mcu().print_time_to_clock(print_time)
reg = self.name_to_reg[reg_name]
- self.spi.spi_send([((val >> 16) | reg) & 0xff,
- (val >> 8) & 0xff, val & 0xff], min_clock)
+ msg = [((val >> 16) | reg) & 0xff, (val >> 8) & 0xff, val & 0xff]
+ self.spi.spi_send(msg, minclock)
######################################################################
diff --git a/klippy/extras/tmc_uart.py b/klippy/extras/tmc_uart.py
index 288fb76d..f5584e8b 100644
--- a/klippy/extras/tmc_uart.py
+++ b/klippy/extras/tmc_uart.py
@@ -149,8 +149,10 @@ class MCU_TMC_uart_bitbang:
params = self.tmcuart_send_cmd.send_with_response(
[self.oid, msg, 10], 'tmcuart_response', self.oid)
return self._decode_read(reg, params['read'])
- def reg_write(self, instance_id, addr, reg, val, print_time=0.):
- minclock = self.mcu.print_time_to_clock(print_time)
+ def reg_write(self, instance_id, addr, reg, val, print_time=None):
+ minclock = 0
+ if print_time is not None:
+ minclock = self.mcu.print_time_to_clock(print_time)
if self.analog_mux is not None:
self.analog_mux.activate(instance_id)
msg = self._encode_write(0xf5, 0x00, reg | 0x80, val)