Skip to content

Commit

Permalink
tmc2240: Adding UART interface support to tmc2240 (#6305)
Browse files Browse the repository at this point in the history
Signed-off-by:  Christoph Frei <[email protected]>
  • Loading branch information
FrYakaTKoP authored Sep 10, 2023
1 parent 8f178b8 commit 2acfa28
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]").
Expand All @@ -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
Expand Down
12 changes: 9 additions & 3 deletions klippy/extras/tmc2240.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2acfa28

Please sign in to comment.