From 2acfa282942c13c725af6a2cb3ea314edf53406f Mon Sep 17 00:00:00 2001 From: FrY Sennberg Date: Sun, 10 Sep 2023 20:41:59 +0200 Subject: [PATCH] tmc2240: Adding UART interface support to tmc2240 (#6305) Signed-off-by: Christoph Frei --- docs/Config_Reference.md | 5 ++++- klippy/extras/tmc2240.py | 12 +++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index 5b8038f7d332..25e7cc46e6fb 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -3442,7 +3442,7 @@ run_current: ### [tmc2240] -Configure a TMC2240 stepper motor driver via SPI bus. To use this +Configure a TMC2240 stepper motor driver via SPI bus or UART. To use this feature, define a config section with a "tmc2240" prefix followed by the name of the corresponding stepper config section (for example, "[tmc2240 stepper_x]"). @@ -3460,6 +3460,9 @@ cs_pin: #spi_software_miso_pin: # See the "common SPI settings" section for a description of the # above parameters. +#uart_pin: +# The pin connected to the TMC2240 DIAG1/SW line. If this parameter +# is provided UART communication is used rather then SPI. #chain_position: #chain_length: # These parameters configure an SPI daisy chain. The two parameters diff --git a/klippy/extras/tmc2240.py b/klippy/extras/tmc2240.py index 19e62ab76a71..aef2280f279a 100644 --- a/klippy/extras/tmc2240.py +++ b/klippy/extras/tmc2240.py @@ -5,7 +5,7 @@ # # This file may be distributed under the terms of the GNU GPLv3 license. import math, logging -from . import bus, tmc, tmc2130 +from . import bus, tmc, tmc2130, tmc_uart TMC_FREQUENCY=12500000. @@ -343,8 +343,14 @@ class TMC2240: def __init__(self, config): # Setup mcu communication self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters) - self.mcu_tmc = tmc2130.MCU_TMC_SPI(config, Registers, self.fields, - TMC_FREQUENCY) + if config.get("uart_pin", None) is not None: + # use UART for communication + self.mcu_tmc = tmc_uart.MCU_TMC_uart(config, Registers, self.fields, + 3, TMC_FREQUENCY) + else: + # Use SPI bus for communication + self.mcu_tmc = tmc2130.MCU_TMC_SPI(config, Registers, self.fields, + TMC_FREQUENCY) # Allow virtual pins to be created tmc.TMCVirtualPinHelper(config, self.mcu_tmc) # Register commands