From f1863ccbcc40022173ddf08df1004f800e2432d5 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Thu, 7 May 2020 23:15:12 -0700 Subject: [PATCH] Add TMC driver HW serial defines (#17909) --- Marlin/src/core/drivers.h | 1 + Marlin/src/inc/Conditionals_post.h | 3 +++ Marlin/src/module/stepper/trinamic.cpp | 22 ++++++++++++--------- buildroot/share/tests/STM32F103RC_btt-tests | 6 +++++- buildroot/share/tests/STM32F103RE_btt-tests | 4 +++- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Marlin/src/core/drivers.h b/Marlin/src/core/drivers.h index 37654dc11fb4c..707926791b2a4 100644 --- a/Marlin/src/core/drivers.h +++ b/Marlin/src/core/drivers.h @@ -131,6 +131,7 @@ #define AXIS_HAS_RXTX AXIS_HAS_UART +#define AXIS_HAS_HW_SERIAL(A) ( AXIS_HAS_UART(A) && defined(A##_HARDWARE_SERIAL) ) #define AXIS_HAS_SW_SERIAL(A) ( AXIS_HAS_UART(A) && !defined(A##_HARDWARE_SERIAL) ) #define AXIS_HAS_STALLGUARD(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \ diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index f66c2f16ad453..26cad8797911d 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -1549,6 +1549,9 @@ #define HAS_E_STEPPER_ENABLE 1 #endif +#if ANY_AXIS_HAS(HW_SERIAL) + #define HAS_TMC_HW_SERIAL 1 +#endif #if ANY_AXIS_HAS(SW_SERIAL) #define HAS_TMC_SW_SERIAL 1 #endif diff --git a/Marlin/src/module/stepper/trinamic.cpp b/Marlin/src/module/stepper/trinamic.cpp index e2bf706bf13ac..ed238ede7d05d 100644 --- a/Marlin/src/module/stepper/trinamic.cpp +++ b/Marlin/src/module/stepper/trinamic.cpp @@ -318,15 +318,19 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E }; enum TMCAxis : uint8_t { X, Y, Z, X2, Y2, Z2, Z3, Z4, E0, E1, E2, E3, E4, E5, E6, E7, TOTAL }; void tmc_serial_begin() { - struct { - const void *ptr[TMCAxis::TOTAL]; - bool began(const TMCAxis a, const void * const p) { - LOOP_L_N(i, a) if (p == ptr[i]) return true; - ptr[a] = p; return false; - }; - } sp_helper; - #define HW_SERIAL_BEGIN(A) do{ if (!sp_helper.began(TMCAxis::A, &A##_HARDWARE_SERIAL)) \ - A##_HARDWARE_SERIAL.begin(TMC_BAUD_RATE); }while(0) + #if HAS_TMC_HW_SERIAL + struct { + const void *ptr[TMCAxis::TOTAL]; + bool began(const TMCAxis a, const void * const p) { + LOOP_L_N(i, a) if (p == ptr[i]) return true; + ptr[a] = p; return false; + }; + } sp_helper; + + #define HW_SERIAL_BEGIN(A) do{ if (!sp_helper.began(TMCAxis::A, &A##_HARDWARE_SERIAL)) \ + A##_HARDWARE_SERIAL.begin(TMC_BAUD_RATE); }while(0) + #endif + #if AXIS_HAS_UART(X) #ifdef X_HARDWARE_SERIAL HW_SERIAL_BEGIN(X); diff --git a/buildroot/share/tests/STM32F103RC_btt-tests b/buildroot/share/tests/STM32F103RC_btt-tests index 8805c748af693..8780eb535cf4c 100644 --- a/buildroot/share/tests/STM32F103RC_btt-tests +++ b/buildroot/share/tests/STM32F103RC_btt-tests @@ -13,7 +13,11 @@ restore_configs opt_set MOTHERBOARD BOARD_BTT_SKR_MINI_E3_V1_0 opt_set SERIAL_PORT 1 opt_set SERIAL_PORT_2 -1 -exec_test $1 $2 "BigTreeTech SKR Mini E3 - Basic Configuration" +opt_set X_DRIVER_TYPE TMC2209 +opt_set Y_DRIVER_TYPE TMC2209 +opt_set Z_DRIVER_TYPE TMC2209 +opt_set E_DRIVER_TYPE TMC2209 +exec_test $1 $2 "BigTreeTech SKR Mini E3 1.0 - Basic Config with TMC2209 HW Serial" # clean up restore_configs diff --git a/buildroot/share/tests/STM32F103RE_btt-tests b/buildroot/share/tests/STM32F103RE_btt-tests index 77751d776e9ce..9a829a553efe1 100644 --- a/buildroot/share/tests/STM32F103RE_btt-tests +++ b/buildroot/share/tests/STM32F103RE_btt-tests @@ -13,7 +13,9 @@ restore_configs opt_set MOTHERBOARD BOARD_BTT_SKR_E3_DIP opt_set SERIAL_PORT 1 opt_set SERIAL_PORT_2 -1 -exec_test $1 $2 "BigTreeTech SKR E3 DIP v1.0 - Basic Configuration" +opt_set X_DRIVER_TYPE TMC2209 +opt_set Y_DRIVER_TYPE TMC2130 +exec_test $1 $2 "BigTreeTech SKR E3 DIP v1.0 - Basic Config with mixed TMC Drivers" # clean up restore_configs