Skip to content

Commit

Permalink
🔧 Auto-assign UART Rx based on Tx
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Oct 27, 2024
1 parent 51f2f1e commit cffd6b6
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 130 deletions.
64 changes: 42 additions & 22 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -3059,49 +3059,69 @@ static_assert(NUM_SERVOS <= NUM_SERVO_PLUGS, "NUM_SERVOS (or some servo index) i
#define INVALID_TMC_UART(ST) (AXIS_HAS_UART(ST) && !(defined(ST##_HARDWARE_SERIAL) || (PINS_EXIST(ST##_SERIAL_RX, ST##_SERIAL_TX))))
#if INVALID_TMC_UART(X)
#error "TMC2208 or TMC2209 on X requires X_HARDWARE_SERIAL or X_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(X2)
#endif
#if INVALID_TMC_UART(X2)
#error "TMC2208 or TMC2209 on X2 requires X2_HARDWARE_SERIAL or X2_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(Y)
#endif
#if INVALID_TMC_UART(Y)
#error "TMC2208 or TMC2209 on Y requires Y_HARDWARE_SERIAL or Y_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(Y2)
#endif
#if INVALID_TMC_UART(Y2)
#error "TMC2208 or TMC2209 on Y2 requires Y2_HARDWARE_SERIAL or Y2_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(Z)
#endif
#if INVALID_TMC_UART(Z)
#error "TMC2208 or TMC2209 on Z requires Z_HARDWARE_SERIAL or Z_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(Z2)
#endif
#if INVALID_TMC_UART(Z2)
#error "TMC2208 or TMC2209 on Z2 requires Z2_HARDWARE_SERIAL or Z2_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(Z3)
#endif
#if INVALID_TMC_UART(Z3)
#error "TMC2208 or TMC2209 on Z3 requires Z3_HARDWARE_SERIAL or Z3_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(Z4)
#endif
#if INVALID_TMC_UART(Z4)
#error "TMC2208 or TMC2209 on Z4 requires Z4_HARDWARE_SERIAL or Z4_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(E0)
#endif
#if INVALID_TMC_UART(E0)
#error "TMC2208 or TMC2209 on E0 requires E0_HARDWARE_SERIAL or E0_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(E1)
#endif
#if INVALID_TMC_UART(E1)
#error "TMC2208 or TMC2209 on E1 requires E1_HARDWARE_SERIAL or E1_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(E2)
#endif
#if INVALID_TMC_UART(E2)
#error "TMC2208 or TMC2209 on E2 requires E2_HARDWARE_SERIAL or E2_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(E3)
#endif
#if INVALID_TMC_UART(E3)
#error "TMC2208 or TMC2209 on E3 requires E3_HARDWARE_SERIAL or E3_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(E4)
#endif
#if INVALID_TMC_UART(E4)
#error "TMC2208 or TMC2209 on E4 requires E4_HARDWARE_SERIAL or E4_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(E5)
#endif
#if INVALID_TMC_UART(E5)
#error "TMC2208 or TMC2209 on E5 requires E5_HARDWARE_SERIAL or E5_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(E6)
#endif
#if INVALID_TMC_UART(E6)
#error "TMC2208 or TMC2209 on E6 requires E6_HARDWARE_SERIAL or E6_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(E7)
#endif
#if INVALID_TMC_UART(E7)
#error "TMC2208 or TMC2209 on E7 requires E7_HARDWARE_SERIAL or E7_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(I)
#endif
#if INVALID_TMC_UART(I)
#error "TMC2208 or TMC2209 on I requires I_HARDWARE_SERIAL or I_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(J)
#endif
#if INVALID_TMC_UART(J)
#error "TMC2208 or TMC2209 on J requires J_HARDWARE_SERIAL or J_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(K)
#endif
#if INVALID_TMC_UART(K)
#error "TMC2208 or TMC2209 on K requires K_HARDWARE_SERIAL or K_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(U)
#endif
#if INVALID_TMC_UART(U)
#error "TMC2208 or TMC2209 on U requires U_HARDWARE_SERIAL or U_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(V)
#endif
#if INVALID_TMC_UART(V)
#error "TMC2208 or TMC2209 on V requires V_HARDWARE_SERIAL or V_SERIAL_(RX|TX)_PIN."
#elif INVALID_TMC_UART(W)
#endif
#if INVALID_TMC_UART(W)
#error "TMC2208 or TMC2209 on W requires W_HARDWARE_SERIAL or W_SERIAL_(RX|TX)_PIN."

#endif
#undef INVALID_TMC_UART

Expand Down
12 changes: 0 additions & 12 deletions Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,30 +124,18 @@
#ifndef X_SERIAL_TX_PIN
#define X_SERIAL_TX_PIN P0_01
#endif
#ifndef X_SERIAL_RX_PIN
#define X_SERIAL_RX_PIN X_SERIAL_TX_PIN
#endif

#ifndef Y_SERIAL_TX_PIN
#define Y_SERIAL_TX_PIN P0_00
#endif
#ifndef Y_SERIAL_RX_PIN
#define Y_SERIAL_RX_PIN Y_SERIAL_TX_PIN
#endif

#ifndef Z_SERIAL_TX_PIN
#define Z_SERIAL_TX_PIN P2_13
#endif
#ifndef Z_SERIAL_RX_PIN
#define Z_SERIAL_RX_PIN Z_SERIAL_TX_PIN
#endif

#ifndef E0_SERIAL_TX_PIN
#define E0_SERIAL_TX_PIN P2_08
#endif
#ifndef E0_SERIAL_RX_PIN
#define E0_SERIAL_RX_PIN E0_SERIAL_TX_PIN
#endif

// Reduce baud rate to improve software serial reliability
#ifndef TMC_BAUD_RATE
Expand Down
158 changes: 116 additions & 42 deletions Marlin/src/pins/pins_postprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,74 +307,148 @@
#define E7_CS_PIN -1
#endif

#if HAS_TMC_UART
#if !defined(X_SERIAL_RX_PIN) && PIN_EXISTS(X_SERIAL_TX)
#define X_SERIAL_RX_PIN X_SERIAL_TX_PIN
#endif
#if !defined(X2_SERIAL_RX_PIN) && PIN_EXISTS(X2_SERIAL_TX)
#define X2_SERIAL_RX_PIN X2_SERIAL_TX_PIN
#endif
#if !defined(Y_SERIAL_RX_PIN) && PIN_EXISTS(Y_SERIAL_TX)
#define Y_SERIAL_RX_PIN Y_SERIAL_TX_PIN
#endif
#if !defined(Y2_SERIAL_RX_PIN) && PIN_EXISTS(Y2_SERIAL_TX)
#define Y2_SERIAL_RX_PIN Y2_SERIAL_TX_PIN
#endif
#if !defined(Z_SERIAL_RX_PIN) && PIN_EXISTS(Z_SERIAL_TX)
#define Z_SERIAL_RX_PIN Z_SERIAL_TX_PIN
#endif
#if !defined(Z2_SERIAL_RX_PIN) && PIN_EXISTS(Z2_SERIAL_TX)
#define Z2_SERIAL_RX_PIN Z2_SERIAL_TX_PIN
#endif
#if !defined(Z3_SERIAL_RX_PIN) && PIN_EXISTS(Z3_SERIAL_TX)
#define Z3_SERIAL_RX_PIN Z3_SERIAL_TX_PIN
#endif
#if !defined(Z4_SERIAL_RX_PIN) && PIN_EXISTS(Z4_SERIAL_TX)
#define Z4_SERIAL_RX_PIN Z4_SERIAL_TX_PIN
#endif
#if !defined(EX_SERIAL_RX_PIN) && PIN_EXISTS(EX_SERIAL_TX)
#define EX_SERIAL_RX_PIN EX_SERIAL_TX_PIN
#endif
#if !defined(E0_SERIAL_RX_PIN) && PIN_EXISTS(E0_SERIAL_TX)
#define E0_SERIAL_RX_PIN E0_SERIAL_TX_PIN
#endif
#if !defined(E1_SERIAL_RX_PIN) && PIN_EXISTS(E1_SERIAL_TX)
#define E1_SERIAL_RX_PIN E1_SERIAL_TX_PIN
#endif
#if !defined(E2_SERIAL_RX_PIN) && PIN_EXISTS(E2_SERIAL_TX)
#define E2_SERIAL_RX_PIN E2_SERIAL_TX_PIN
#endif
#if !defined(E3_SERIAL_RX_PIN) && PIN_EXISTS(E3_SERIAL_TX)
#define E3_SERIAL_RX_PIN E3_SERIAL_TX_PIN
#endif
#if !defined(E4_SERIAL_RX_PIN) && PIN_EXISTS(E4_SERIAL_TX)
#define E4_SERIAL_RX_PIN E4_SERIAL_TX_PIN
#endif
#if !defined(E5_SERIAL_RX_PIN) && PIN_EXISTS(E5_SERIAL_TX)
#define E5_SERIAL_RX_PIN E5_SERIAL_TX_PIN
#endif
#if !defined(E6_SERIAL_RX_PIN) && PIN_EXISTS(E6_SERIAL_TX)
#define E6_SERIAL_RX_PIN E6_SERIAL_TX_PIN
#endif
#if !defined(E7_SERIAL_RX_PIN) && PIN_EXISTS(E7_SERIAL_TX)
#define E7_SERIAL_RX_PIN E7_SERIAL_TX_PIN
#endif
#endif

//
// Destroy stepper driver RX and TX pins when set to -1
// Some RX depend on TX, so RX needs to be un-defined before TX
// or it breaks "PIN_EXISTS(NAME_OF_UNDEF)".
//
#if !PIN_EXISTS(Z2_SERIAL_TX)
#undef Z2_SERIAL_TX_PIN
#if !PIN_EXISTS(W_SERIAL_RX)
#undef W_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(Z2_SERIAL_RX)
#undef Z2_SERIAL_RX_PIN
#if !PIN_EXISTS(W_SERIAL_TX)
#undef W_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(Z3_SERIAL_TX)
#undef Z3_SERIAL_TX_PIN
#if !PIN_EXISTS(V_SERIAL_RX)
#undef V_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(Z3_SERIAL_RX)
#undef Z3_SERIAL_RX_PIN
#if !PIN_EXISTS(V_SERIAL_TX)
#undef V_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(Z4_SERIAL_TX)
#undef Z4_SERIAL_TX_PIN
#if !PIN_EXISTS(U_SERIAL_RX)
#undef U_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(Z4_SERIAL_RX)
#undef Z4_SERIAL_RX_PIN
#if !PIN_EXISTS(U_SERIAL_TX)
#undef U_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(X2_SERIAL_TX)
#undef X2_SERIAL_TX_PIN
#if !PIN_EXISTS(K_SERIAL_RX)
#undef K_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(X2_SERIAL_RX)
#undef X2_SERIAL_RX_PIN
#if !PIN_EXISTS(K_SERIAL_TX)
#undef K_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(Y2_SERIAL_TX)
#undef Y2_SERIAL_TX_PIN
#if !PIN_EXISTS(J_SERIAL_RX)
#undef J_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(Y2_SERIAL_RX)
#undef Y2_SERIAL_RX_PIN
#if !PIN_EXISTS(J_SERIAL_TX)
#undef J_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(I_SERIAL_RX)
#undef I_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(I_SERIAL_TX)
#undef I_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(I_SERIAL_RX)
#undef I_SERIAL_RX_PIN
#if !PIN_EXISTS(Z4_SERIAL_RX)
#undef Z4_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(J_SERIAL_TX)
#undef J_SERIAL_TX_PIN
#if !PIN_EXISTS(Z4_SERIAL_TX)
#undef Z4_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(J_SERIAL_RX)
#undef J_SERIAL_RX_PIN
#if !PIN_EXISTS(Z3_SERIAL_RX)
#undef Z3_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(K_SERIAL_TX)
#undef K_SERIAL_TX_PIN
#if !PIN_EXISTS(Z3_SERIAL_TX)
#undef Z3_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(K_SERIAL_RX)
#undef K_SERIAL_RX_PIN
#if !PIN_EXISTS(Z2_SERIAL_RX)
#undef Z2_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(U_SERIAL_TX)
#undef U_SERIAL_TX_PIN
#if !PIN_EXISTS(Z2_SERIAL_TX)
#undef Z2_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(U_SERIAL_RX)
#undef U_SERIAL_RX_PIN
#if !PIN_EXISTS(Y2_SERIAL_RX)
#undef Y2_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(V_SERIAL_TX)
#undef V_SERIAL_TX_PIN
#if !PIN_EXISTS(Y2_SERIAL_TX)
#undef Y2_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(V_SERIAL_RX)
#undef V_SERIAL_RX_PIN
#if !PIN_EXISTS(X2_SERIAL_RX)
#undef X2_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(W_SERIAL_TX)
#undef W_SERIAL_TX_PIN
#if !PIN_EXISTS(X2_SERIAL_TX)
#undef X2_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(W_SERIAL_RX)
#undef W_SERIAL_RX_PIN
#if !PIN_EXISTS(Z_SERIAL_RX)
#undef Z_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(Z_SERIAL_TX)
#undef Z_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(Y_SERIAL_RX)
#undef Y_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(Y_SERIAL_TX)
#undef Y_SERIAL_TX_PIN
#endif
#if !PIN_EXISTS(X_SERIAL_RX)
#undef X_SERIAL_RX_PIN
#endif
#if !PIN_EXISTS(X_SERIAL_TX)
#undef X_SERIAL_TX_PIN
#endif

#ifndef FAN0_PIN
Expand Down
24 changes: 0 additions & 24 deletions Marlin/src/pins/samd/pins_RAMPS_144.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,54 +210,30 @@
#ifndef X_SERIAL_TX_PIN
#define X_SERIAL_TX_PIN 47
#endif
#ifndef X_SERIAL_RX_PIN
#define X_SERIAL_RX_PIN X_SERIAL_TX_PIN
#endif
#ifndef X2_SERIAL_TX_PIN
#define X2_SERIAL_TX_PIN -1
#endif
#ifndef X2_SERIAL_RX_PIN
#define X2_SERIAL_RX_PIN X2_SERIAL_TX_PIN
#endif

#ifndef Y_SERIAL_TX_PIN
#define Y_SERIAL_TX_PIN 45
#endif
#ifndef Y_SERIAL_RX_PIN
#define Y_SERIAL_RX_PIN Y_SERIAL_TX_PIN
#endif
#ifndef Y2_SERIAL_TX_PIN
#define Y2_SERIAL_TX_PIN -1
#endif
#ifndef Y2_SERIAL_RX_PIN
#define Y2_SERIAL_RX_PIN Y2_SERIAL_TX_PIN
#endif

#ifndef Z_SERIAL_TX_PIN
#define Z_SERIAL_TX_PIN 32
#endif
#ifndef Z_SERIAL_RX_PIN
#define Z_SERIAL_RX_PIN Z_SERIAL_TX_PIN
#endif
#ifndef Z2_SERIAL_TX_PIN
#define Z2_SERIAL_TX_PIN 22
#endif
#ifndef Z2_SERIAL_RX_PIN
#define Z2_SERIAL_RX_PIN Z2_SERIAL_TX_PIN
#endif

#ifndef E0_SERIAL_TX_PIN
#define E0_SERIAL_TX_PIN 43
#endif
#ifndef E0_SERIAL_RX_PIN
#define E0_SERIAL_RX_PIN E0_SERIAL_TX_PIN
#endif
#ifndef E1_SERIAL_TX_PIN
#define E1_SERIAL_TX_PIN -1
#endif
#ifndef E1_SERIAL_RX_PIN
#define E1_SERIAL_RX_PIN E1_SERIAL_TX_PIN
#endif
#endif

//
Expand Down
12 changes: 0 additions & 12 deletions Marlin/src/pins/stm32f4/pins_FYSETC_CHEETAH_V30.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,17 @@
#ifndef X_SERIAL_TX_PIN
#define X_SERIAL_TX_PIN PB3
#endif
#ifndef X_SERIAL_RX_PIN
#define X_SERIAL_RX_PIN X_SERIAL_TX_PIN
#endif

#ifndef Y_SERIAL_TX_PIN
#define Y_SERIAL_TX_PIN PB3
#endif
#ifndef Y_SERIAL_RX_PIN
#define Y_SERIAL_RX_PIN Y_SERIAL_TX_PIN
#endif

#ifndef Z_SERIAL_TX_PIN
#define Z_SERIAL_TX_PIN PB3
#endif
#ifndef Z_SERIAL_RX_PIN
#define Z_SERIAL_RX_PIN Z_SERIAL_TX_PIN
#endif
#ifndef E0_SERIAL_TX_PIN
#define E0_SERIAL_TX_PIN PB3
#endif
#ifndef E0_SERIAL_RX_PIN
#define E0_SERIAL_RX_PIN E0_SERIAL_TX_PIN
#endif

// Default TMC slave addresses
#ifndef X_SLAVE_ADDRESS
Expand Down
Loading

0 comments on commit cffd6b6

Please sign in to comment.