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>
This commit is contained in:
Kevin O'Connor 2019-06-25 18:15:17 -04:00
parent 79c24f95b3
commit 6ec7dee07d
4 changed files with 21 additions and 14 deletions

View file

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