From de1161536bb25743266564d0ecba2554ccbef48e Mon Sep 17 00:00:00 2001 From: MarlinFirmware Date: Thu, 25 Mar 2021 00:27:01 +0000 Subject: [PATCH 1/7] [cron] Bump distribution date (2021-03-25) --- Marlin/src/inc/Version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/inc/Version.h b/Marlin/src/inc/Version.h index 7d3f6d8a64445..8ed540d0f695c 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -42,7 +42,7 @@ * version was tagged. */ #ifndef STRING_DISTRIBUTION_DATE - #define STRING_DISTRIBUTION_DATE "2021-03-24" + #define STRING_DISTRIBUTION_DATE "2021-03-25" #endif /** From cfdeab70cdacc9949eadc23b91d8e7c2a1fe63d8 Mon Sep 17 00:00:00 2001 From: espr14 Date: Thu, 25 Mar 2021 04:39:10 +0100 Subject: [PATCH 2/7] Endstops always on after delta homing (#21442) --- Marlin/src/module/delta.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/module/delta.cpp b/Marlin/src/module/delta.cpp index a1676b3ba346a..2312e1a0127a4 100644 --- a/Marlin/src/module/delta.cpp +++ b/Marlin/src/module/delta.cpp @@ -253,7 +253,7 @@ void home_delta() { planner.synchronize(); // Re-enable stealthChop if used. Disable diag1 pin on driver. - #if ENABLED(SENSORLESS_HOMING) + #if ENABLED(SENSORLESS_HOMING) && DISABLED(ENDSTOPS_ALWAYS_ON_DEFAULT) TERN_(X_SENSORLESS, end_sensorless_homing_per_axis(X_AXIS, stealth_states_x)); TERN_(Y_SENSORLESS, end_sensorless_homing_per_axis(Y_AXIS, stealth_states_y)); TERN_(Z_SENSORLESS, end_sensorless_homing_per_axis(Z_AXIS, stealth_states_z)); From e989bf3b0ed79156c094f6e298b5ff326a53e3fb Mon Sep 17 00:00:00 2001 From: espr14 Date: Thu, 25 Mar 2021 04:39:29 +0100 Subject: [PATCH 3/7] Endstops always on in G28 (#21441) --- Marlin/src/gcode/calibrate/G28.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/gcode/calibrate/G28.cpp b/Marlin/src/gcode/calibrate/G28.cpp index 9470678872370..73bfc3bdc6c07 100644 --- a/Marlin/src/gcode/calibrate/G28.cpp +++ b/Marlin/src/gcode/calibrate/G28.cpp @@ -102,7 +102,7 @@ current_position.set(0.0, 0.0); - #if ENABLED(SENSORLESS_HOMING) + #if ENABLED(SENSORLESS_HOMING) && DISABLED(ENDSTOPS_ALWAYS_ON_DEFAULT) tmc_disable_stallguard(stepperX, stealth_states.x); tmc_disable_stallguard(stepperY, stealth_states.y); #if AXIS_HAS_STALLGUARD(X2) From 69c6ffa90b017d31bf70dc174c716232ca2752ee Mon Sep 17 00:00:00 2001 From: ldursw <37294448+ldursw@users.noreply.github.com> Date: Thu, 25 Mar 2021 00:40:48 -0300 Subject: [PATCH 4/7] Followup to SDIO patch (#21440) --- Marlin/src/feature/binary_stream.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/feature/binary_stream.h b/Marlin/src/feature/binary_stream.h index 4bfa3998f12a3..b5d68196ae3a8 100644 --- a/Marlin/src/feature/binary_stream.h +++ b/Marlin/src/feature/binary_stream.h @@ -39,7 +39,7 @@ inline int bs_read_serial(const serial_index_t index) { #if ENABLED(BINARY_STREAM_COMPRESSION) static heatshrink_decoder hsd; - #ifdef BOTH(ARDUINO_ARCH_STM32F1, SDIO_SUPPORT) + #if BOTH(ARDUINO_ARCH_STM32F1, SDIO_SUPPORT) // STM32 requires a word-aligned buffer for SD card transfers via DMA static __attribute__((aligned(sizeof(size_t)))) uint8_t decode_buffer[512] = {}; #else From 8bf6b190ff074ae9aa76734389cf7612a1e0fb0c Mon Sep 17 00:00:00 2001 From: Ramiro Polla Date: Thu, 25 Mar 2021 04:56:48 +0100 Subject: [PATCH 5/7] Optimize LSF for size, efficiency (#21443) --- Marlin/src/libs/least_squares_fit.cpp | 26 +++++++++++++------------- Marlin/src/libs/least_squares_fit.h | 4 +--- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Marlin/src/libs/least_squares_fit.cpp b/Marlin/src/libs/least_squares_fit.cpp index c7593c049fc40..aac21c019295f 100644 --- a/Marlin/src/libs/least_squares_fit.cpp +++ b/Marlin/src/libs/least_squares_fit.cpp @@ -46,23 +46,23 @@ int finish_incremental_LSF(struct linear_fit_data *lsf) { if (N == 0.0) return 1; - lsf->xbar /= N; - lsf->ybar /= N; - lsf->zbar /= N; - lsf->x2bar = lsf->x2bar / N - sq(lsf->xbar); - lsf->y2bar = lsf->y2bar / N - sq(lsf->ybar); - lsf->z2bar = lsf->z2bar / N - sq(lsf->zbar); - lsf->xybar = lsf->xybar / N - lsf->xbar * lsf->ybar; - lsf->yzbar = lsf->yzbar / N - lsf->ybar * lsf->zbar; - lsf->xzbar = lsf->xzbar / N - lsf->xbar * lsf->zbar; - const float DD = lsf->x2bar * lsf->y2bar - sq(lsf->xybar); + const float RN = 1.0f / N, + xbar = lsf->xbar * RN, + ybar = lsf->ybar * RN, + zbar = lsf->zbar * RN, + x2bar = lsf->x2bar * RN - sq(xbar), + y2bar = lsf->y2bar * RN - sq(ybar), + xybar = lsf->xybar * RN - xbar * ybar, + yzbar = lsf->yzbar * RN - ybar * zbar, + xzbar = lsf->xzbar * RN - xbar * zbar, + DD = x2bar * y2bar - sq(xybar); if (ABS(DD) <= 1e-10 * (lsf->max_absx + lsf->max_absy)) return 1; - lsf->A = (lsf->yzbar * lsf->xybar - lsf->xzbar * lsf->y2bar) / DD; - lsf->B = (lsf->xzbar * lsf->xybar - lsf->yzbar * lsf->x2bar) / DD; - lsf->D = -(lsf->zbar + lsf->A * lsf->xbar + lsf->B * lsf->ybar); + lsf->A = (yzbar * xybar - xzbar * y2bar) / DD; + lsf->B = (xzbar * xybar - yzbar * x2bar) / DD; + lsf->D = -(zbar + lsf->A * xbar + lsf->B * ybar); return 0; } diff --git a/Marlin/src/libs/least_squares_fit.h b/Marlin/src/libs/least_squares_fit.h index 44ca8afc76d81..dbbab0a55e9ef 100644 --- a/Marlin/src/libs/least_squares_fit.h +++ b/Marlin/src/libs/least_squares_fit.h @@ -37,7 +37,7 @@ struct linear_fit_data { float xbar, ybar, zbar, - x2bar, y2bar, z2bar, + x2bar, y2bar, xybar, xzbar, yzbar, max_absx, max_absy, A, B, D, N; @@ -56,7 +56,6 @@ inline void incremental_WLSF(struct linear_fit_data *lsf, const float &x, const lsf->zbar += wz; lsf->x2bar += wx * x; lsf->y2bar += wy * y; - lsf->z2bar += wz * z; lsf->xybar += wx * y; lsf->xzbar += wx * z; lsf->yzbar += wy * z; @@ -74,7 +73,6 @@ inline void incremental_LSF(struct linear_fit_data *lsf, const float &x, const f lsf->zbar += z; lsf->x2bar += sq(x); lsf->y2bar += sq(y); - lsf->z2bar += sq(z); lsf->xybar += x * y; lsf->xzbar += x * z; lsf->yzbar += y * z; From 84b961cb20a4f0b2c1ad67a71d6c507a12f9da2a Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 25 Mar 2021 16:19:03 -0500 Subject: [PATCH 6/7] Define HW serial ports needed for TMC UART (#21446) --- Marlin/src/HAL/DUE/HAL.cpp | 8 +- Marlin/src/HAL/DUE/MarlinSerial.h | 2 +- Marlin/src/HAL/LPC1768/MarlinSerial.cpp | 19 ++-- Marlin/src/HAL/LPC1768/inc/SanityCheck.h | 8 +- Marlin/src/HAL/SAMD51/HAL.cpp | 10 +- Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.cpp | 6 +- Marlin/src/HAL/STM32/MarlinSerial.cpp | 4 - Marlin/src/inc/Conditionals_adv.h | 6 -- Marlin/src/inc/Conditionals_post.h | 106 +++++++++++++++++++ buildroot/share/extras/header.h | 2 +- 10 files changed, 134 insertions(+), 37 deletions(-) diff --git a/Marlin/src/HAL/DUE/HAL.cpp b/Marlin/src/HAL/DUE/HAL.cpp index 0e4caa47ac978..249535723f8c7 100644 --- a/Marlin/src/HAL/DUE/HAL.cpp +++ b/Marlin/src/HAL/DUE/HAL.cpp @@ -106,16 +106,16 @@ uint16_t HAL_adc_get_result() { } // Forward the default serial ports -#if ANY_SERIAL_IS(0) +#if USING_HW_SERIAL0 DefaultSerial1 MSerial0(false, Serial); #endif -#if ANY_SERIAL_IS(1) +#if USING_HW_SERIAL1 DefaultSerial2 MSerial1(false, Serial1); #endif -#if ANY_SERIAL_IS(2) +#if USING_HW_SERIAL2 DefaultSerial3 MSerial2(false, Serial2); #endif -#if ANY_SERIAL_IS(3) +#if USING_HW_SERIAL3 DefaultSerial4 MSerial3(false, Serial3); #endif diff --git a/Marlin/src/HAL/DUE/MarlinSerial.h b/Marlin/src/HAL/DUE/MarlinSerial.h index e74d234b4ae3e..0fb15cf8adbc7 100644 --- a/Marlin/src/HAL/DUE/MarlinSerial.h +++ b/Marlin/src/HAL/DUE/MarlinSerial.h @@ -140,7 +140,7 @@ struct MarlinSerialCfg { static constexpr bool MAX_RX_QUEUED = ENABLED(SERIAL_STATS_MAX_RX_QUEUED); }; -#if SERIAL_PORT >= 0 +#if defined(SERIAL_PORT) && SERIAL_PORT >= 0 typedef Serial1Class< MarlinSerial< MarlinSerialCfg > > MSerialT; extern MSerialT customizedSerial1; #endif diff --git a/Marlin/src/HAL/LPC1768/MarlinSerial.cpp b/Marlin/src/HAL/LPC1768/MarlinSerial.cpp index be42c7f960489..f35328d22f0aa 100644 --- a/Marlin/src/HAL/LPC1768/MarlinSerial.cpp +++ b/Marlin/src/HAL/LPC1768/MarlinSerial.cpp @@ -21,25 +21,26 @@ */ #ifdef TARGET_LPC1768 -#include "../../inc/MarlinConfigPre.h" #include "MarlinSerial.h" -#if ANY_SERIAL_IS(0) +#include "../../inc/MarlinConfig.h" + +#if USING_HW_SERIAL0 MarlinSerial _MSerial(LPC_UART0); MSerialT MSerial0(true, _MSerial); extern "C" void UART0_IRQHandler() { _MSerial.IRQHandler(); } #endif -#if ANY_SERIAL_IS(1) +#if USING_HW_SERIAL1 MarlinSerial _MSerial1((LPC_UART_TypeDef *) LPC_UART1); MSerialT MSerial1(true, _MSerial1); extern "C" void UART1_IRQHandler() { _MSerial1.IRQHandler(); } #endif -#if ANY_SERIAL_IS(2) +#if USING_HW_SERIAL2 MarlinSerial _MSerial2(LPC_UART2); MSerialT MSerial2(true, _MSerial2); extern "C" void UART2_IRQHandler() { _MSerial2.IRQHandler(); } #endif -#if ANY_SERIAL_IS(3) +#if USING_HW_SERIAL3 MarlinSerial _MSerial3(LPC_UART3); MSerialT MSerial3(true, _MSerial3); extern "C" void UART3_IRQHandler() { _MSerial3.IRQHandler(); } @@ -50,16 +51,16 @@ bool MarlinSerial::recv_callback(const char c) { // Need to figure out which serial port we are and react in consequence (Marlin does not have CONTAINER_OF macro) if (false) {} - #if ANY_SERIAL_IS(0) + #if USING_HW_SERIAL0 else if (this == &_MSerial) emergency_parser.update(MSerial0.emergency_state, c); #endif - #if ANY_SERIAL_IS(1) + #if USING_HW_SERIAL1 else if (this == &_MSerial1) emergency_parser.update(MSerial1.emergency_state, c); #endif - #if ANY_SERIAL_IS(2) + #if USING_HW_SERIAL2 else if (this == &_MSerial2) emergency_parser.update(MSerial2.emergency_state, c); #endif - #if ANY_SERIAL_IS(3) + #if USING_HW_SERIAL3 else if (this == &_MSerial3) emergency_parser.update(MSerial3.emergency_state, c); #endif return true; diff --git a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h index dda1c640fa739..a6286ba6f4047 100644 --- a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h +++ b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h @@ -92,7 +92,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o #define ANY_TX(N,V...) DO(IS_TX##N,||,V) #define ANY_RX(N,V...) DO(IS_RX##N,||,V) -#if ANY_SERIAL_IS(0) +#if USING_HW_SERIAL0 #define IS_TX0(P) (P == P0_02) #define IS_RX0(P) (P == P0_03) #if IS_TX0(TMC_SW_MISO) || IS_RX0(TMC_SW_MOSI) @@ -106,7 +106,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o #undef IS_RX0 #endif -#if ANY_SERIAL_IS(1) +#if USING_HW_SERIAL1 #define IS_TX1(P) (P == P0_15) #define IS_RX1(P) (P == P0_16) #define _IS_TX1_1 IS_TX1 @@ -127,7 +127,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o #undef _IS_RX1_1 #endif -#if ANY_SERIAL_IS(2) +#if USING_HW_SERIAL2 #define IS_TX2(P) (P == P0_10) #define IS_RX2(P) (P == P0_11) #define _IS_TX2_1 IS_TX2 @@ -161,7 +161,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o #undef _IS_RX2_1 #endif -#if ANY_SERIAL_IS(3) +#if USING_HW_SERIAL3 #define PIN_IS_TX3(P) (PIN_EXISTS(P) && P##_PIN == P0_00) #define PIN_IS_RX3(P) (P##_PIN == P0_01) #if PIN_IS_TX3(X_MIN) || PIN_IS_RX3(X_MAX) diff --git a/Marlin/src/HAL/SAMD51/HAL.cpp b/Marlin/src/HAL/SAMD51/HAL.cpp index 8dd2fefd0a161..39167fc467d2b 100644 --- a/Marlin/src/HAL/SAMD51/HAL.cpp +++ b/Marlin/src/HAL/SAMD51/HAL.cpp @@ -25,19 +25,19 @@ #include #ifdef ADAFRUIT_GRAND_CENTRAL_M4 - #if ANY_SERIAL_IS(-1) + #if USING_HW_SERIALUSB DefaultSerial1 MSerial0(false, Serial); #endif - #if ANY_SERIAL_IS(0) + #if USING_HW_SERIAL0 DefaultSerial2 MSerial1(false, Serial1); #endif - #if ANY_SERIAL_IS(1) + #if USING_HW_SERIAL1 DefaultSerial3 MSerial2(false, Serial2); #endif - #if ANY_SERIAL_IS(2) + #if USING_HW_SERIAL2 DefaultSerial4 MSerial3(false, Serial3); #endif - #if ANY_SERIAL_IS(3) + #if USING_HW_SERIAL3 DefaultSerial5 MSerial4(false, Serial4); #endif #endif diff --git a/Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.cpp b/Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.cpp index 3f43585cf2421..a16ea2f758214 100644 --- a/Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.cpp +++ b/Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.cpp @@ -27,7 +27,7 @@ #include "../../inc/MarlinConfig.h" -#if ANY_SERIAL_IS(1) +#if USING_HW_SERIAL1 UartT Serial2(false, &sercom4, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX); void SERCOM4_0_Handler() { Serial2.IrqHandler(); } void SERCOM4_1_Handler() { Serial2.IrqHandler(); } @@ -35,7 +35,7 @@ void SERCOM4_3_Handler() { Serial2.IrqHandler(); } #endif -#if ANY_SERIAL_IS(2) +#if USING_HW_SERIAL2 UartT Serial3(false, &sercom1, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX); void SERCOM1_0_Handler() { Serial3.IrqHandler(); } void SERCOM1_1_Handler() { Serial3.IrqHandler(); } @@ -43,7 +43,7 @@ void SERCOM1_3_Handler() { Serial3.IrqHandler(); } #endif -#if ANY_SERIAL_IS(3) +#if USING_HW_SERIAL3 UartT Serial4(false, &sercom5, PIN_SERIAL4_RX, PIN_SERIAL4_TX, PAD_SERIAL4_RX, PAD_SERIAL4_TX); void SERCOM5_0_Handler() { Serial4.IrqHandler(); } void SERCOM5_1_Handler() { Serial4.IrqHandler(); } diff --git a/Marlin/src/HAL/STM32/MarlinSerial.cpp b/Marlin/src/HAL/STM32/MarlinSerial.cpp index cfb13f5bb561a..132c602a0cdb4 100644 --- a/Marlin/src/HAL/STM32/MarlinSerial.cpp +++ b/Marlin/src/HAL/STM32/MarlinSerial.cpp @@ -28,7 +28,6 @@ #ifndef USART4 #define USART4 UART4 #endif - #ifndef USART5 #define USART5 UART5 #endif @@ -43,15 +42,12 @@ #if defined(SERIAL_PORT) && SERIAL_PORT >= 0 DECLARE_SERIAL_PORT_EXP(SERIAL_PORT) #endif - #if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0 DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2) #endif - #if defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT >= 0 DECLARE_SERIAL_PORT_EXP(MMU2_SERIAL_PORT) #endif - #if defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT >= 0 DECLARE_SERIAL_PORT_EXP(LCD_SERIAL_PORT) #endif diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 5ef0efa9684b5..2177dc48611dd 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -530,12 +530,6 @@ #define NEED_LSF 1 #endif -// Flag the indexed serial ports that are in use -#define ANY_SERIAL_IS(N) (defined(SERIAL_PORT) && SERIAL_PORT == (N)) || \ - (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == (N)) || \ - (defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT == (N)) || \ - (defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == (N)) - #if BOTH(HAS_TFT_LVGL_UI, CUSTOM_MENU_MAIN) #define _HAS_1(N) (defined(USER_DESC_##N) && defined(USER_GCODE_##N)) #define HAS_USER_ITEM(V...) DO(HAS,||,V) diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 1cd7e5f0e93a1..84e9cf8955ff6 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -1838,6 +1838,112 @@ #define HAS_TMC_SW_SERIAL 1 #endif +// +// 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) \ + || (defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT == N) \ + || (defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == N) ) + +// Flag the named hardware serial ports in use +#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) \ + || TMC_UART_IS(E0, N) || TMC_UART_IS(E1, N) || TMC_UART_IS(E2, N) || TMC_UART_IS(E3, N) || TMC_UART_IS(E4, N) ) + +#define HW_Serial 501 +#define HW_Serial0 502 +#define HW_Serial1 503 +#define HW_Serial2 504 +#define HW_Serial3 505 +#define HW_Serial4 506 +#define HW_Serial5 507 +#define HW_Serial6 508 +#define HW_MSerial0 509 +#define HW_MSerial1 510 +#define HW_MSerial2 511 +#define HW_MSerial3 512 +#define HW_MSerial4 513 +#define HW_MSerial5 514 +#define HW_MSerial6 515 +#define HW_MSerial7 516 +#define HW_MSerial8 517 +#define HW_MSerial9 518 +#define HW_MSerial10 519 + +#if CONF_SERIAL_IS(-1) + #define USING_HW_SERIALUSB 1 +#endif +#if ANY_SERIAL_IS(0) + #define USING_HW_SERIAL0 1 +#endif +#if ANY_SERIAL_IS(1) + #define USING_HW_SERIAL1 1 +#endif +#if ANY_SERIAL_IS(2) + #define USING_HW_SERIAL2 1 +#endif +#if ANY_SERIAL_IS(3) + #define USING_HW_SERIAL3 1 +#endif +#if ANY_SERIAL_IS(4) + #define USING_HW_SERIAL4 1 +#endif +#if ANY_SERIAL_IS(5) + #define USING_HW_SERIAL5 1 +#endif +#if ANY_SERIAL_IS(6) + #define USING_HW_SERIAL6 1 +#endif +#if ANY_SERIAL_IS(7) + #define USING_HW_SERIAL7 1 +#endif +#if ANY_SERIAL_IS(8) + #define USING_HW_SERIAL8 1 +#endif +#if ANY_SERIAL_IS(9) + #define USING_HW_SERIAL9 1 +#endif +#if ANY_SERIAL_IS(10) + #define USING_HW_SERIAL10 1 +#endif + +#undef HW_Serial +#undef HW_Serial0 +#undef HW_Serial1 +#undef HW_Serial2 +#undef HW_Serial3 +#undef HW_Serial4 +#undef HW_Serial5 +#undef HW_Serial6 +#undef HW_MSerial0 +#undef HW_MSerial1 +#undef HW_MSerial2 +#undef HW_MSerial3 +#undef HW_MSerial4 +#undef HW_MSerial5 +#undef HW_MSerial6 +#undef HW_MSerial7 +#undef HW_MSerial8 +#undef HW_MSerial9 +#undef HW_MSerial10 + +#undef _SERIAL_ID +#undef _TMC_UART_IS +#undef TMC_UART_IS +#undef CONF_SERIAL_IS +#undef ANY_SERIAL_IS + // // Endstops and bed probe // diff --git a/buildroot/share/extras/header.h b/buildroot/share/extras/header.h index 5d2c73dfbeef6..e40471dface99 100644 --- a/buildroot/share/extras/header.h +++ b/buildroot/share/extras/header.h @@ -1,6 +1,6 @@ /** * Marlin 3D Printer Firmware - * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm From 704b8cd83c507675d6f71621e1c35172779ac9d1 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 25 Mar 2021 16:49:04 -0500 Subject: [PATCH 7/7] 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 50b84c0b1d403..5b333fbeb56f9 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 132c602a0cdb4..265e8b5ab61b9 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 USING_HW_SERIAL2 + DECLARE_SERIAL_PORT(2) +#endif +#if USING_HW_SERIAL3 + DECLARE_SERIAL_PORT(3) +#endif +#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 defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0 - DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2) +#if USING_HW_SERIAL9 + DECLARE_SERIAL_PORT(9) #endif -#if defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT >= 0 - DECLARE_SERIAL_PORT_EXP(MMU2_SERIAL_PORT) +#if USING_HW_SERIAL10 + DECLARE_SERIAL_PORT(10) #endif -#if defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT >= 0 - DECLARE_SERIAL_PORT_EXP(LCD_SERIAL_PORT) +#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 84e9cf8955ff6..2433050528fa3 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) \