From e817db62a45da3e5353aa311541863108b0163b5 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 25 Mar 2021 16:49:04 -0500 Subject: [PATCH] Apply TMC UART to STM32, simplify --- Marlin/src/HAL/DUE/MarlinSerial.cpp | 2 +- Marlin/src/HAL/STM32/MarlinSerial.cpp | 39 ++++++++++++++++++++------- Marlin/src/inc/Conditionals_post.h | 8 +----- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/Marlin/src/HAL/DUE/MarlinSerial.cpp b/Marlin/src/HAL/DUE/MarlinSerial.cpp index 50b84c0b1d..5b333fbeb5 100644 --- a/Marlin/src/HAL/DUE/MarlinSerial.cpp +++ b/Marlin/src/HAL/DUE/MarlinSerial.cpp @@ -476,7 +476,7 @@ void MarlinSerial::flushTX() { // If not using the USB port as serial port -#if SERIAL_PORT >= 0 +#if defined(SERIAL_PORT) && SERIAL_PORT >= 0 template class MarlinSerial< MarlinSerialCfg >; MSerialT customizedSerial1(MarlinSerialCfg::EMERGENCYPARSER); #endif diff --git a/Marlin/src/HAL/STM32/MarlinSerial.cpp b/Marlin/src/HAL/STM32/MarlinSerial.cpp index 132c602a0c..265e8b5ab6 100644 --- a/Marlin/src/HAL/STM32/MarlinSerial.cpp +++ b/Marlin/src/HAL/STM32/MarlinSerial.cpp @@ -37,19 +37,38 @@ MSerialT MSerial ## ser_num (true, USART ## ser_num, &_rx_complete_irq_ ## ser_num); \ void _rx_complete_irq_ ## ser_num (serial_t * obj) { MSerial ## ser_num ._rx_complete_irq(obj); } -#define DECLARE_SERIAL_PORT_EXP(ser_num) DECLARE_SERIAL_PORT(ser_num) - -#if defined(SERIAL_PORT) && SERIAL_PORT >= 0 - DECLARE_SERIAL_PORT_EXP(SERIAL_PORT) +#if USING_HW_SERIAL1 + DECLARE_SERIAL_PORT(1) #endif -#if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0 - DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2) +#if USING_HW_SERIAL2 + DECLARE_SERIAL_PORT(2) #endif -#if defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT >= 0 - DECLARE_SERIAL_PORT_EXP(MMU2_SERIAL_PORT) +#if USING_HW_SERIAL3 + DECLARE_SERIAL_PORT(3) #endif -#if defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT >= 0 - DECLARE_SERIAL_PORT_EXP(LCD_SERIAL_PORT) +#if USING_HW_SERIAL4 + DECLARE_SERIAL_PORT(4) +#endif +#if USING_HW_SERIAL5 + DECLARE_SERIAL_PORT(5) +#endif +#if USING_HW_SERIAL6 + DECLARE_SERIAL_PORT(6) +#endif +#if USING_HW_SERIAL7 + DECLARE_SERIAL_PORT(7) +#endif +#if USING_HW_SERIAL8 + DECLARE_SERIAL_PORT(8) +#endif +#if USING_HW_SERIAL9 + DECLARE_SERIAL_PORT(9) +#endif +#if USING_HW_SERIAL10 + DECLARE_SERIAL_PORT(10) +#endif +#if USING_HW_SERIALLP1 + DECLARE_SERIAL_PORT(LP1) #endif void MarlinSerial::begin(unsigned long baud, uint8_t config) { diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 84e9cf8955..2433050528 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -1842,13 +1842,6 @@ // Set USING_HW_SERIALn flags for used Serial Ports // -// ... HW_SerialX -#define _SERIAL_ID(P) _CAT(HW_,P) - -// ... (HW_Serial1 == HW_SerialX || HW_Serial1 == HW_MSerialX) -#define _TMC_UART_IS(P,N) ( _SERIAL_ID(P##_HARDWARE_SERIAL) == _SERIAL_ID(Serial##N) || _SERIAL_ID(P) == _SERIAL_ID(MSerial##N) ) -#define TMC_UART_IS(A,N) (defined(A##_HARDWARE_SERIAL) && _TMC_UART_IS(A, N)) - // Flag the indexed hardware serial ports in use #define CONF_SERIAL_IS(N) ( (defined(SERIAL_PORT) && SERIAL_PORT == N) \ || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == N) \ @@ -1856,6 +1849,7 @@ || (defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == N) ) // Flag the named hardware serial ports in use +#define TMC_UART_IS(A,N) (defined(A##_HARDWARE_SERIAL) && (CAT(HW_,A##_HARDWARE_SERIAL) == HW_Serial##N || CAT(HW_,A##_HARDWARE_SERIAL) == HW_MSerial##N)) #define ANY_SERIAL_IS(N) ( CONF_SERIAL_IS(N) \ || TMC_UART_IS(X, N) || TMC_UART_IS(Y , N) || TMC_UART_IS(Z , N) \ || TMC_UART_IS(X2, N) || TMC_UART_IS(Y2, N) || TMC_UART_IS(Z2, N) || TMC_UART_IS(Z3, N) || TMC_UART_IS(Z4, N) \