From 5990266724eb79536cb6d0d72b6130aebba2cbba Mon Sep 17 00:00:00 2001 From: teemuatlut Date: Sat, 10 Feb 2018 22:08:53 +0200 Subject: [PATCH] Init CS pins before loading settings (#9566) --- Marlin/src/Marlin.cpp | 7 ++++++ Marlin/src/feature/tmc_util.cpp | 39 +++++++++++++++++++++++++++++++++ Marlin/src/feature/tmc_util.h | 4 ++++ 3 files changed, 50 insertions(+) diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp index d9c5c9b457..18e3a2c70d 100644 --- a/Marlin/src/Marlin.cpp +++ b/Marlin/src/Marlin.cpp @@ -689,6 +689,13 @@ void setup() { SERIAL_PROTOCOLLNPGM("start"); SERIAL_ECHO_START(); + #if ENABLED(HAVE_TMC2130) + tmc_init_cs_pins(); + #endif + #if ENABLED(HAVE_TMC2208) + tmc2208_serial_begin(); + #endif + // Check startup - does nothing if bootloader sets MCUSR to 0 byte mcu = HAL_get_reset_source(); if (mcu & 1) SERIAL_ECHOLNPGM(MSG_POWERUP); diff --git a/Marlin/src/feature/tmc_util.cpp b/Marlin/src/feature/tmc_util.cpp index a45136381b..11bec933a5 100644 --- a/Marlin/src/feature/tmc_util.cpp +++ b/Marlin/src/feature/tmc_util.cpp @@ -582,4 +582,43 @@ void _tmc_say_sgt(const char name[], const uint32_t sgt) { #endif // SENSORLESS_HOMING +#if ENABLED(HAVE_TMC2130) + #define SET_CS_PIN(st) OUT_WRITE(st##_CS_PIN, HIGH) + void tmc_init_cs_pins() { + #if ENABLED(X_IS_TMC2130) + SET_CS_PIN(X); + #endif + #if ENABLED(Y_IS_TMC2130) + SET_CS_PIN(Y); + #endif + #if ENABLED(Z_IS_TMC2130) + SET_CS_PIN(Z); + #endif + #if ENABLED(X2_IS_TMC2130) + SET_CS_PIN(X2); + #endif + #if ENABLED(Y2_IS_TMC2130) + SET_CS_PIN(Y2); + #endif + #if ENABLED(Z2_IS_TMC2130) + SET_CS_PIN(Z2); + #endif + #if ENABLED(E0_IS_TMC2130) + SET_CS_PIN(E0); + #endif + #if ENABLED(E1_IS_TMC2130) + SET_CS_PIN(E1); + #endif + #if ENABLED(E2_IS_TMC2130) + SET_CS_PIN(E2); + #endif + #if ENABLED(E3_IS_TMC2130) + SET_CS_PIN(E3); + #endif + #if ENABLED(E4_IS_TMC2130) + SET_CS_PIN(E4); + #endif + } +#endif // HAVE_TMC2130 + #endif // HAS_TRINAMIC diff --git a/Marlin/src/feature/tmc_util.h b/Marlin/src/feature/tmc_util.h index abe44e9dbc..46d5b4f286 100644 --- a/Marlin/src/feature/tmc_util.h +++ b/Marlin/src/feature/tmc_util.h @@ -100,4 +100,8 @@ void monitor_tmc_driver(); void tmc_sensorless_homing(TMC2130Stepper &st, bool enable=true); #endif +#if ENABLED(HAVE_TMC2130) + void tmc_init_cs_pins(); +#endif + #endif // _TMC_UTIL_H_