tmc: Query latest value during _init_registers()

The set_register() code may block, and it therefore may be possible
that the loop in _init_registers() could occur in parallel with other
updates.  That could result in a "OrderedDict mutated during
iteration" error.

Avoid the error by querying the latest value during each iteration of
the loop.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2023-11-20 19:43:36 -05:00
parent ea2f6bc0f5
commit 03f69cd81a
1 changed files with 2 additions and 1 deletions

View File

@ -262,7 +262,8 @@ class TMCCommandHelper:
desc=self.cmd_SET_TMC_CURRENT_help)
def _init_registers(self, print_time=None):
# Send registers
for reg_name, val in self.fields.registers.items():
for reg_name in list(self.fields.registers.keys()):
val = self.fields.registers[reg_name] # Val may change during loop
self.mcu_tmc.set_register(reg_name, val, print_time)
cmd_INIT_TMC_help = "Initialize TMC stepper driver registers"
def cmd_INIT_TMC(self, gcmd):