From 274857357e8801368ba9894340ed2deb3fb29423 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 18 Jun 2019 11:58:36 -0400 Subject: [PATCH] tmc: Retry register init during connect Signed-off-by: Kevin O'Connor --- klippy/extras/tmc.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/klippy/extras/tmc.py b/klippy/extras/tmc.py index ad6085ff..f3dcdb92 100644 --- a/klippy/extras/tmc.py +++ b/klippy/extras/tmc.py @@ -101,10 +101,18 @@ class TMCCommandHelper: for reg_name, val in self.fields.registers.items(): self.mcu_tmc.set_register(reg_name, val, print_time) def _handle_connect(self): - try: - self._init_registers(0.) - except self.printer.command_error as e: - raise self.printer.config_error(str(e)) + retry_count = 0 + while 1: + try: + self._init_registers(0.) + return + except self.printer.command_error as e: + logging.exception("TMC init error") + retry_count += 1 + if retry_count > 5: + raise self.printer.config_error(str(e)) + reactor = self.printer.get_reactor() + reactor.pause(reactor.monotonic() + 1.) cmd_INIT_TMC_help = "Initialize TMC stepper driver registers" def cmd_INIT_TMC(self, params): logging.info("INIT_TMC %s", self.name)