From 4b928b2da8ae26bd4a949debe470a914e23545ca Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 19:45:33 -0500 Subject: [PATCH] HAL and serial cleanup Co-Authored-By: Jason Smith <20053467+sjasonsmith@users.noreply.github.com> --- Marlin/src/HAL/AVR/HAL.h | 21 +---- Marlin/src/HAL/AVR/MarlinSerial.cpp | 20 ++--- Marlin/src/HAL/AVR/MarlinSerial.h | 6 +- Marlin/src/HAL/DUE/HAL.h | 47 +++-------- Marlin/src/HAL/ESP32/HAL.h | 3 - Marlin/src/HAL/HAL.h | 6 ++ Marlin/src/HAL/LINUX/HAL.h | 1 - Marlin/src/HAL/LINUX/main.cpp | 2 +- Marlin/src/HAL/LPC1768/HAL.h | 47 +++-------- Marlin/src/HAL/LPC1768/inc/SanityCheck.h | 37 ++++++--- Marlin/src/HAL/SAMD51/HAL.h | 46 +++-------- Marlin/src/HAL/STM32/HAL.h | 81 ++++++------------- Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h | 2 +- Marlin/src/HAL/STM32F1/HAL.h | 5 +- Marlin/src/HAL/STM32F1/MarlinSerial.h | 1 + Marlin/src/HAL/STM32F1/sdio.cpp | 2 +- Marlin/src/HAL/STM32_F4_F7/HAL.h | 61 +++----------- Marlin/src/HAL/TEENSY31_32/HAL.h | 14 ++-- Marlin/src/HAL/TEENSY35_36/HAL.h | 14 ++-- Marlin/src/HAL/TEENSY40_41/HAL.h | 51 +++--------- Marlin/src/MarlinCore.cpp | 18 ++--- Marlin/src/gcode/config/M575.cpp | 19 +---- Marlin/src/inc/SanityCheck.h | 40 +++++++-- Marlin/src/lcd/extui/malyan_lcd.cpp | 6 +- Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h | 8 +- .../pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h | 8 +- .../pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h | 8 +- Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h | 8 +- Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h | 16 ++-- .../pins/stm32f1/pins_MKS_ROBIN_E3_common.h | 8 +- .../src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h | 16 ++-- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h | 17 ++-- buildroot/tests/malyan_M300-tests | 1 + 33 files changed, 220 insertions(+), 420 deletions(-) diff --git a/Marlin/src/HAL/AVR/HAL.h b/Marlin/src/HAL/AVR/HAL.h index 609375e386..fcaaf75c4a 100644 --- a/Marlin/src/HAL/AVR/HAL.h +++ b/Marlin/src/HAL/AVR/HAL.h @@ -81,12 +81,7 @@ typedef int8_t pin_t; // Serial ports #ifdef USBCON - #if ENABLED(BLUETOOTH) - #define MYSERIAL0 bluetoothSerial - #else - #define MYSERIAL0 Serial - #endif - #define NUM_SERIAL 1 + #define MYSERIAL0 TERN(BLUETOOTH, bluetoothSerial, Serial) #else #if !WITHIN(SERIAL_PORT, -1, 3) #error "SERIAL_PORT must be from -1 to 3. Please update your configuration." @@ -97,36 +92,22 @@ typedef int8_t pin_t; #ifdef SERIAL_PORT_2 #if !WITHIN(SERIAL_PORT_2, -1, 3) #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." - #elif SERIAL_PORT_2 == SERIAL_PORT - #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration." #endif #define MYSERIAL1 customizedSerial2 - #define NUM_SERIAL 2 - #else - #define NUM_SERIAL 1 #endif #endif #ifdef DGUS_SERIAL_PORT #if !WITHIN(DGUS_SERIAL_PORT, -1, 3) #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration." - #elif DGUS_SERIAL_PORT == SERIAL_PORT - #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." - #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2 - #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." #endif #define DGUS_SERIAL internalDgusSerial - #define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.get_tx_buffer_free #endif #ifdef ANYCUBIC_LCD_SERIAL_PORT #if !WITHIN(ANYCUBIC_LCD_SERIAL_PORT, -1, 3) #error "ANYCUBIC_LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration." - #elif ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT - #error "ANYCUBIC_LCD_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." - #elif defined(SERIAL_PORT_2) && ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT_2 - #error "ANYCUBIC_LCD_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." #endif #define ANYCUBIC_LCD_SERIAL anycubicLcdSerial #endif diff --git a/Marlin/src/HAL/AVR/MarlinSerial.cpp b/Marlin/src/HAL/AVR/MarlinSerial.cpp index 3d44a3f59f..838627001d 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.cpp +++ b/Marlin/src/HAL/AVR/MarlinSerial.cpp @@ -712,11 +712,11 @@ } // Hookup ISR handlers - ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_RX_vect)) { + ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _RX_vect)) { MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_UDRE_vect)) { + ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _UDRE_vect)) { MarlinSerial>::_tx_udr_empty_irq(); } @@ -729,11 +729,11 @@ #ifdef SERIAL_PORT_2 // Hookup ISR handlers - ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_RX_vect)) { + ISR(SERIAL_REGNAME(USART, SERIAL_PORT_2, _RX_vect)) { MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_UDRE_vect)) { + ISR(SERIAL_REGNAME(USART, SERIAL_PORT_2, _UDRE_vect)) { MarlinSerial>::_tx_udr_empty_irq(); } @@ -749,11 +749,11 @@ #ifdef INTERNAL_SERIAL_PORT - ISR(SERIAL_REGNAME(USART,INTERNAL_SERIAL_PORT,_RX_vect)) { + ISR(SERIAL_REGNAME(USART, INTERNAL_SERIAL_PORT, _RX_vect)) { MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART,INTERNAL_SERIAL_PORT,_UDRE_vect)) { + ISR(SERIAL_REGNAME(USART, INTERNAL_SERIAL_PORT, _UDRE_vect)) { MarlinSerial>::_tx_udr_empty_irq(); } @@ -776,11 +776,11 @@ return ret; } - ISR(SERIAL_REGNAME(USART,DGUS_SERIAL_PORT,_RX_vect)) { + ISR(SERIAL_REGNAME(USART, DGUS_SERIAL_PORT, _RX_vect)) { MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART,DGUS_SERIAL_PORT,_UDRE_vect)) { + ISR(SERIAL_REGNAME(USART, DGUS_SERIAL_PORT, _UDRE_vect)) { MarlinSerial>::_tx_udr_empty_irq(); } @@ -794,11 +794,11 @@ #ifdef ANYCUBIC_LCD_SERIAL_PORT - ISR(SERIAL_REGNAME(USART,ANYCUBIC_LCD_SERIAL_PORT,_RX_vect)) { + ISR(SERIAL_REGNAME(USART, ANYCUBIC_LCD_SERIAL_PORT, _RX_vect)) { MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART,ANYCUBIC_LCD_SERIAL_PORT,_UDRE_vect)) { + ISR(SERIAL_REGNAME(USART, ANYCUBIC_LCD_SERIAL_PORT, _UDRE_vect)) { MarlinSerial>::_tx_udr_empty_irq(); } diff --git a/Marlin/src/HAL/AVR/MarlinSerial.h b/Marlin/src/HAL/AVR/MarlinSerial.h index e8bfc5583a..8dbed4d85b 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.h +++ b/Marlin/src/HAL/AVR/MarlinSerial.h @@ -48,11 +48,11 @@ // These are macros to build serial port register names for the selected SERIAL_PORT (C preprocessor // requires two levels of indirection to expand macro values properly) - #define SERIAL_REGNAME(registerbase,number,suffix) SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) + #define SERIAL_REGNAME(registerbase,number,suffix) _SERIAL_REGNAME(registerbase,number,suffix) #if SERIAL_PORT == 0 && (!defined(UBRR0H) || !defined(UDR0)) // use un-numbered registers if necessary - #define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##suffix + #define _SERIAL_REGNAME(registerbase,number,suffix) registerbase##suffix #else - #define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##number##suffix + #define _SERIAL_REGNAME(registerbase,number,suffix) registerbase##number##suffix #endif // Registers used by MarlinSerial class (expanded depending on selected serial port) diff --git a/Marlin/src/HAL/DUE/HAL.h b/Marlin/src/HAL/DUE/HAL.h index 31409c76dd..974f1ccc16 100644 --- a/Marlin/src/HAL/DUE/HAL.h +++ b/Marlin/src/HAL/DUE/HAL.h @@ -38,57 +38,34 @@ #include +#define _MSERIAL(X) Serial##X +#define MSERIAL(X) _MSERIAL(X) +#define Serial0 Serial + // Define MYSERIAL0/1 before MarlinSerial includes! #if SERIAL_PORT == -1 || ENABLED(EMERGENCY_PARSER) #define MYSERIAL0 customizedSerial1 -#elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial -#elif SERIAL_PORT == 1 - #define MYSERIAL0 Serial1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 Serial2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 Serial3 +#elif WITHIN(SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else #error "The required SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif #ifdef SERIAL_PORT_2 - #if SERIAL_PORT_2 == SERIAL_PORT - #error "SERIAL_PORT_2 must be different from SERIAL_PORT. Please update your configuration." - #elif SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER) + #if SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER) #define MYSERIAL1 customizedSerial2 - #elif SERIAL_PORT_2 == 0 - #define MYSERIAL1 Serial - #elif SERIAL_PORT_2 == 1 - #define MYSERIAL1 Serial1 - #elif SERIAL_PORT_2 == 2 - #define MYSERIAL1 Serial2 - #elif SERIAL_PORT_2 == 3 - #define MYSERIAL1 Serial3 + #elif WITHIN(SERIAL_PORT_2, 0, 3) + #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #ifdef DGUS_SERIAL_PORT - #if DGUS_SERIAL_PORT == SERIAL_PORT - #error "DGUS_SERIAL_PORT must be different from SERIAL_PORT. Please update your configuration." - #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2 - #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." - #elif DGUS_SERIAL_PORT == -1 + #if DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL internalDgusSerial - #elif DGUS_SERIAL_PORT == 0 - #define DGUS_SERIAL Serial - #elif DGUS_SERIAL_PORT == 1 - #define DGUS_SERIAL Serial1 - #elif DGUS_SERIAL_PORT == 2 - #define DGUS_SERIAL Serial2 - #elif DGUS_SERIAL_PORT == 3 - #define DGUS_SERIAL Serial3 + #elif WITHIN(DGUS_SERIAL_PORT, 0, 3) + #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) #else #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif diff --git a/Marlin/src/HAL/ESP32/HAL.h b/Marlin/src/HAL/ESP32/HAL.h index c91f9efff0..5eb84fdc30 100644 --- a/Marlin/src/HAL/ESP32/HAL.h +++ b/Marlin/src/HAL/ESP32/HAL.h @@ -58,9 +58,6 @@ extern portMUX_TYPE spinlock; #else #define MYSERIAL1 webSocketSerial #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #define CRITICAL_SECTION_START() portENTER_CRITICAL(&spinlock) diff --git a/Marlin/src/HAL/HAL.h b/Marlin/src/HAL/HAL.h index c7b7531442..8b6a978d21 100644 --- a/Marlin/src/HAL/HAL.h +++ b/Marlin/src/HAL/HAL.h @@ -25,6 +25,12 @@ #include HAL_PATH(.,HAL.h) +#ifdef SERIAL_PORT_2 + #define NUM_SERIAL 2 +#else + #define NUM_SERIAL 1 +#endif + #define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION) #ifndef I2C_ADDRESS diff --git a/Marlin/src/HAL/LINUX/HAL.h b/Marlin/src/HAL/LINUX/HAL.h index 96e121d915..778ba2db4d 100644 --- a/Marlin/src/HAL/LINUX/HAL.h +++ b/Marlin/src/HAL/LINUX/HAL.h @@ -62,7 +62,6 @@ uint8_t _getc(); extern HalSerial usb_serial; #define MYSERIAL0 usb_serial -#define NUM_SERIAL 1 #define ST7920_DELAY_1 DELAY_NS(600) #define ST7920_DELAY_2 DELAY_NS(750) diff --git a/Marlin/src/HAL/LINUX/main.cpp b/Marlin/src/HAL/LINUX/main.cpp index 4eeef318e7..481f059030 100644 --- a/Marlin/src/HAL/LINUX/main.cpp +++ b/Marlin/src/HAL/LINUX/main.cpp @@ -107,7 +107,7 @@ int main() { std::thread write_serial (write_serial_thread); std::thread read_serial (read_serial_thread); - #if NUM_SERIAL > 0 + #ifdef MYSERIAL0 MYSERIAL0.begin(BAUDRATE); SERIAL_ECHOLNPGM("x86_64 Initialized"); SERIAL_FLUSHTX(); diff --git a/Marlin/src/HAL/LPC1768/HAL.h b/Marlin/src/HAL/LPC1768/HAL.h index 0153bacf42..e9f05fcc61 100644 --- a/Marlin/src/HAL/LPC1768/HAL.h +++ b/Marlin/src/HAL/LPC1768/HAL.h @@ -63,56 +63,33 @@ extern "C" volatile uint32_t _millis; #define ST7920_DELAY_3 DELAY_NS(750) #endif +#define _MSERIAL(X) MSerial##X +#define MSERIAL(X) _MSERIAL(X) +#define MSerial0 MSerial + #if SERIAL_PORT == -1 #define MYSERIAL0 UsbSerial -#elif SERIAL_PORT == 0 - #define MYSERIAL0 MSerial -#elif SERIAL_PORT == 1 - #define MYSERIAL0 MSerial1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 MSerial2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 MSerial3 +#elif WITHIN(SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else #error "SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif #ifdef SERIAL_PORT_2 - #if SERIAL_PORT_2 == SERIAL_PORT - #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration." - #elif SERIAL_PORT_2 == -1 + #if SERIAL_PORT_2 == -1 #define MYSERIAL1 UsbSerial - #elif SERIAL_PORT_2 == 0 - #define MYSERIAL1 MSerial - #elif SERIAL_PORT_2 == 1 - #define MYSERIAL1 MSerial1 - #elif SERIAL_PORT_2 == 2 - #define MYSERIAL1 MSerial2 - #elif SERIAL_PORT_2 == 3 - #define MYSERIAL1 MSerial3 + #elif WITHIN(SERIAL_PORT_2, 0, 3) + #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #ifdef DGUS_SERIAL_PORT - #if DGUS_SERIAL_PORT == SERIAL_PORT - #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." - #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2 - #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." - #elif DGUS_SERIAL_PORT == -1 + #if DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL UsbSerial - #elif DGUS_SERIAL_PORT == 0 - #define DGUS_SERIAL MSerial - #elif DGUS_SERIAL_PORT == 1 - #define DGUS_SERIAL MSerial1 - #elif DGUS_SERIAL_PORT == 2 - #define DGUS_SERIAL MSerial2 - #elif DGUS_SERIAL_PORT == 3 - #define DGUS_SERIAL MSerial3 + #elif WITHIN(DGUS_SERIAL_PORT, 0, 3) + #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) #else #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif diff --git a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h index 3fc1dd801a..2ca8a29da4 100644 --- a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h +++ b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h @@ -89,6 +89,9 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o * Serial2 | P0_10 | P0_11 | * Serial3 | P0_00 | P0_01 | */ +#define ANY_TX(N,V...) DO(IS_TX##N,||,V) +#define ANY_RX(N,V...) DO(IS_RX##N,||,V) + #if (defined(SERIAL_PORT) && SERIAL_PORT == 0) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == 0) || (defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT == 0) #define IS_TX0(P) (P == P0_02) #define IS_RX0(P) (P == P0_03) @@ -106,48 +109,56 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o #if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 || DGUS_SERIAL_PORT == 1 #define IS_TX1(P) (P == P0_15) #define IS_RX1(P) (P == P0_16) + #define _IS_TX1_1 IS_TX1 + #define _IS_RX1_1 IS_RX1 #if IS_TX1(TMC_SW_SCK) #error "Serial port pins (1) conflict with other pins!" #elif HAS_SPI_LCD #if IS_TX1(BTN_EN2) || IS_RX1(BTN_EN1) #error "Serial port pins (1) conflict with Encoder Buttons!" - #elif IS_TX1(SCK_PIN) || IS_TX1(LCD_PINS_D4) || IS_TX1(DOGLCD_SCK) || IS_TX1(LCD_RESET_PIN) || IS_TX1(LCD_PINS_RS) || IS_TX1(SHIFT_CLK) \ - || IS_RX1(LCD_SDSS) || IS_RX1(LCD_PINS_RS) || IS_RX1(MISO_PIN) || IS_RX1(DOGLCD_A0) || IS_RX1(SS_PIN) || IS_RX1(LCD_SDSS) || IS_RX1(DOGLCD_CS) || IS_RX1(LCD_RESET_PIN) || IS_RX1(LCD_BACKLIGHT_PIN) + #elif ANY_TX(1, SCK_PIN, LCD_PINS_D4, DOGLCD_SCK, LCD_RESET_PIN, LCD_PINS_RS, SHIFT_CLK) \ + || ANY_RX(1, LCD_SDSS, LCD_PINS_RS, MISO_PIN, DOGLCD_A0, SS_PIN, LCD_SDSS, DOGLCD_CS, LCD_RESET_PIN, LCD_BACKLIGHT_PIN) #error "Serial port pins (1) conflict with LCD pins!" #endif #endif #undef IS_TX1 #undef IS_RX1 + #undef _IS_TX1_1 + #undef _IS_RX1_1 #endif #if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2 #define IS_TX2(P) (P == P0_10) #define IS_RX2(P) (P == P0_11) - #if IS_TX2(X2_ENABLE_PIN) || IS_RX2(X2_DIR_PIN) || IS_RX2(X2_STEP_PIN) || (AXIS_HAS_SPI(X2) && IS_TX2(X2_CS_PIN)) + #define _IS_TX2_1 IS_TX2 + #define _IS_RX2_1 IS_RX2 + #if IS_TX2(X2_ENABLE_PIN) || ANY_RX(2, X2_DIR_PIN, X2_STEP_PIN) || (AXIS_HAS_SPI(X2) && IS_TX2(X2_CS_PIN)) #error "Serial port pins (2) conflict with X2 pins!" - #elif IS_TX2(Y2_ENABLE_PIN) || IS_RX2(Y2_DIR_PIN) || IS_RX2(Y2_STEP_PIN) || (AXIS_HAS_SPI(Y2) && IS_TX2(Y2_CS_PIN)) + #elif IS_TX2(Y2_ENABLE_PIN) || ANY_RX(2, Y2_DIR_PIN, Y2_STEP_PIN) || (AXIS_HAS_SPI(Y2) && IS_TX2(Y2_CS_PIN)) #error "Serial port pins (2) conflict with Y2 pins!" - #elif IS_TX2(Z2_ENABLE_PIN) || IS_RX2(Z2_DIR_PIN) || IS_RX2(Z2_STEP_PIN) || (AXIS_HAS_SPI(Z2) && IS_TX2(Z2_CS_PIN)) + #elif IS_TX2(Z2_ENABLE_PIN) || ANY_RX(2, Z2_DIR_PIN, Z2_STEP_PIN) || (AXIS_HAS_SPI(Z2) && IS_TX2(Z2_CS_PIN)) #error "Serial port pins (2) conflict with Z2 pins!" - #elif IS_TX2(Z3_ENABLE_PIN) || IS_RX2(Z3_DIR_PIN) || IS_RX2(Z3_STEP_PIN) || (AXIS_HAS_SPI(Z3) && IS_TX2(Z3_CS_PIN)) + #elif IS_TX2(Z3_ENABLE_PIN) || ANY_RX(2, Z3_DIR_PIN, Z3_STEP_PIN) || (AXIS_HAS_SPI(Z3) && IS_TX2(Z3_CS_PIN)) #error "Serial port pins (2) conflict with Z3 pins!" - #elif IS_TX2(Z4_ENABLE_PIN) || IS_RX2(Z4_DIR_PIN) || IS_RX2(Z4_STEP_PIN) || (AXIS_HAS_SPI(Z4) && IS_TX2(Z4_CS_PIN)) + #elif IS_TX2(Z4_ENABLE_PIN) || ANY_RX(2, Z4_DIR_PIN, Z4_STEP_PIN) || (AXIS_HAS_SPI(Z4) && IS_TX2(Z4_CS_PIN)) #error "Serial port pins (2) conflict with Z4 pins!" - #elif IS_RX2(X_DIR_PIN) || IS_RX2(Y_DIR_PIN) + #elif ANY_RX(2, X_DIR_PIN, Y_DIR_PIN) #error "Serial port pins (2) conflict with other pins!" #elif Y_HOME_DIR < 0 && IS_TX2(Y_STOP_PIN) #error "Serial port pins (2) conflict with Y endstop pin!" #elif HAS_CUSTOM_PROBE_PIN && IS_TX2(Z_MIN_PROBE_PIN) #error "Serial port pins (2) conflict with probe pin!" - #elif IS_TX2(X_ENABLE_PIN) || IS_RX2(X_DIR_PIN) || IS_TX2(Y_ENABLE_PIN) || IS_RX2(Y_DIR_PIN) + #elif ANY_TX(2, X_ENABLE_PIN, Y_ENABLE_PIN) || ANY_RX(2, X_DIR_PIN, Y_DIR_PIN) #error "Serial port pins (2) conflict with X/Y stepper pins!" #elif HAS_MULTI_EXTRUDER && (IS_TX2(E1_ENABLE_PIN) || (AXIS_HAS_SPI(E1) && IS_TX2(E1_CS_PIN))) #error "Serial port pins (2) conflict with E1 stepper pins!" - #elif EXTRUDERS && (IS_RX2(E0_DIR_PIN) || IS_RX2(E0_STEP_PIN)) + #elif EXTRUDERS && ANY_RX(2, E0_DIR_PIN, E0_STEP_PIN) #error "Serial port pins (2) conflict with E stepper pins!" #endif #undef IS_TX2 #undef IS_RX2 + #undef _IS_TX2_1 + #undef _IS_RX2_1 #endif #if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3 @@ -155,8 +166,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o #define PIN_IS_RX3(P) (P##_PIN == P0_01) #if PIN_IS_TX3(X_MIN) || PIN_IS_RX3(X_MAX) #error "Serial port pins (3) conflict with X endstop pins!" - #elif PIN_IS_TX3(Y_SERIAL_TX) || PIN_IS_TX3(Y_SERIAL_RX) \ - || PIN_IS_RX3(X_SERIAL_TX) || PIN_IS_RX3(X_SERIAL_RX) + #elif PIN_IS_TX3(Y_SERIAL_TX) || PIN_IS_TX3(Y_SERIAL_RX) || PIN_IS_RX3(X_SERIAL_TX) || PIN_IS_RX3(X_SERIAL_RX) #error "Serial port pins (3) conflict with X/Y axis UART pins!" #elif PIN_IS_TX3(X2_DIR) || PIN_IS_RX3(X2_STEP) #error "Serial port pins (3) conflict with X2 pins!" @@ -175,6 +185,9 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o #undef PIN_IS_RX3 #endif +#undef ANY_TX +#undef ANY_RX + // // Flag any i2c pin conflicts // diff --git a/Marlin/src/HAL/SAMD51/HAL.h b/Marlin/src/HAL/SAMD51/HAL.h index ea0f694cdc..b516cb769f 100644 --- a/Marlin/src/HAL/SAMD51/HAL.h +++ b/Marlin/src/HAL/SAMD51/HAL.h @@ -35,56 +35,32 @@ // MYSERIAL0 required before MarlinSerial includes! + #define _MSERIAL(X) Serial##X + #define MSERIAL(X) _MSERIAL(INCREMENT(X)) + #if SERIAL_PORT == -1 #define MYSERIAL0 Serial - #elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial1 - #elif SERIAL_PORT == 1 - #define MYSERIAL0 Serial2 - #elif SERIAL_PORT == 2 - #define MYSERIAL0 Serial3 - #elif SERIAL_PORT == 3 - #define MYSERIAL0 Serial4 + #elif WITHIN(SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else #error "SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif #ifdef SERIAL_PORT_2 - #if SERIAL_PORT_2 == SERIAL_PORT - #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration." - #elif SERIAL_PORT_2 == -1 + #if SERIAL_PORT_2 == -1 #define MYSERIAL1 Serial - #elif SERIAL_PORT_2 == 0 - #define MYSERIAL1 Serial1 - #elif SERIAL_PORT_2 == 1 - #define MYSERIAL1 Serial2 - #elif SERIAL_PORT_2 == 2 - #define MYSERIAL1 Serial3 - #elif SERIAL_PORT_2 == 3 - #define MYSERIAL1 Serial4 + #elif WITHIN(SERIAL_PORT_2, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #endif - #define NUM_SERIAL 2 - #else - #define NUM_SERIAL 1 #endif #ifdef DGUS_SERIAL_PORT - #if DGUS_SERIAL_PORT == SERIAL_PORT - #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." - #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2 - #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." - #elif DGUS_SERIAL_PORT == -1 + #if DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL Serial - #elif DGUS_SERIAL_PORT == 0 - #define DGUS_SERIAL Serial1 - #elif DGUS_SERIAL_PORT == 1 - #define DGUS_SERIAL Serial2 - #elif DGUS_SERIAL_PORT == 2 - #define DGUS_SERIAL Serial3 - #elif DGUS_SERIAL_PORT == 2 - #define DGUS_SERIAL Serial4 + #elif WITHIN(DGUS_SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(DGUS_SERIAL_PORT) #else #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h index 08081331b7..9ec2d5c19e 100644 --- a/Marlin/src/HAL/STM32/HAL.h +++ b/Marlin/src/HAL/STM32/HAL.h @@ -43,82 +43,47 @@ // ------------------------ // Defines // ------------------------ +#define _MSERIAL(X) MSerial##X +#define MSERIAL(X) _MSERIAL(X) -#if SERIAL_PORT == 0 - #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration." -#elif SERIAL_PORT == -1 +#if SERIAL_PORT == -1 #define MYSERIAL0 SerialUSB -#elif SERIAL_PORT == 1 - #define MYSERIAL0 MSerial1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 MSerial2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 MSerial3 -#elif SERIAL_PORT == 4 - #define MYSERIAL0 MSerial4 -#elif SERIAL_PORT == 5 - #define MYSERIAL0 MSerial5 -#elif SERIAL_PORT == 6 - #define MYSERIAL0 MSerial6 +#elif WITHIN(SERIAL_PORT, 1, 6) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else - #error "SERIAL_PORT must be from -1 to 6. Please update your configuration." + #error "SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration." #endif #ifdef SERIAL_PORT_2 - #define NUM_SERIAL 2 - #if SERIAL_PORT_2 == 0 - #error "SERIAL_PORT_2 cannot be 0. (Port 0 does not exist.) Please update your configuration." - #elif SERIAL_PORT_2 == SERIAL_PORT - #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration." - #elif SERIAL_PORT_2 == -1 + #if SERIAL_PORT_2 == -1 #define MYSERIAL1 SerialUSB - #elif SERIAL_PORT_2 == 1 - #define MYSERIAL1 MSerial1 - #elif SERIAL_PORT_2 == 2 - #define MYSERIAL1 MSerial2 - #elif SERIAL_PORT_2 == 3 - #define MYSERIAL1 MSerial3 - #elif SERIAL_PORT_2 == 4 - #define MYSERIAL1 MSerial4 - #elif SERIAL_PORT_2 == 5 - #define MYSERIAL1 MSerial5 - #elif SERIAL_PORT_2 == 6 - #define MYSERIAL1 MSerial6 + #elif WITHIN(SERIAL_PORT_2, 1, 6) + #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #else - #error "SERIAL_PORT_2 must be from -1 to 6. Please update your configuration." + #error "SERIAL_PORT_2 must be -1 or from 1 to 6. Please update your configuration." #endif -#else - #define NUM_SERIAL 1 #endif #if HAS_DGUS_LCD - #if DGUS_SERIAL_PORT == 0 - #error "DGUS_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration." - #elif DGUS_SERIAL_PORT == SERIAL_PORT - #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." - #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2 - #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." - #elif DGUS_SERIAL_PORT == -1 + #if DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL SerialUSB - #elif DGUS_SERIAL_PORT == 1 - #define DGUS_SERIAL MSerial1 - #elif DGUS_SERIAL_PORT == 2 - #define DGUS_SERIAL MSerial2 - #elif DGUS_SERIAL_PORT == 3 - #define DGUS_SERIAL MSerial3 - #elif DGUS_SERIAL_PORT == 4 - #define DGUS_SERIAL MSerial4 - #elif DGUS_SERIAL_PORT == 5 - #define DGUS_SERIAL MSerial5 - #elif DGUS_SERIAL_PORT == 6 - #define DGUS_SERIAL MSerial6 + #elif WITHIN(DGUS_SERIAL_PORT, 1, 6) + #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) #else - #error "DGUS_SERIAL_PORT must be from -1 to 6. Please update your configuration." + #error "DGUS_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration." #endif - #define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.availableForWrite #endif +#if ENABLED(MALYAN_LCD) + #if LCD_SERIAL_PORT == -1 + #define LCD_SERIAL SerialUSB + #elif WITHIN(LCD_SERIAL_PORT, 1, 6) + #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT) + #else + #error "LCD_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration." + #endif +#endif /** * TODO: review this to return 1 for pins that are not analog input diff --git a/Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h b/Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h index 5ff40debea..9069d9f7bd 100644 --- a/Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h +++ b/Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h @@ -98,7 +98,7 @@ static inline void pwm_details(const pin_t pin) { timer_dev * const tdev = PIN_MAP[pin].timer_device; const uint8_t channel = PIN_MAP[pin].timer_channel; const char num = ( - #if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) + #if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY) tdev == &timer8 ? '8' : tdev == &timer5 ? '5' : #endif diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index f76d8c54a0..47414cb45e 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -53,7 +53,7 @@ // ------------------------ #ifndef STM32_FLASH_SIZE - #if defined(MCU_STM32F103RE) || defined(MCU_STM32F103VE) + #if EITHER(MCU_STM32F103RE, MCU_STM32F103VE) #define STM32_FLASH_SIZE 512 #else #define STM32_FLASH_SIZE 256 @@ -106,9 +106,6 @@ #else #error "SERIAL_PORT_2 must be from -1 to 5. Please update your configuration." #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #ifdef DGUS_SERIAL diff --git a/Marlin/src/HAL/STM32F1/MarlinSerial.h b/Marlin/src/HAL/STM32F1/MarlinSerial.h index eb0059bfbc..b9248e50ca 100644 --- a/Marlin/src/HAL/STM32F1/MarlinSerial.h +++ b/Marlin/src/HAL/STM32F1/MarlinSerial.h @@ -30,6 +30,7 @@ #include "../../feature/e_parser.h" #endif +// Increase priority of serial interrupts, to reduce overflow errors #define UART_IRQ_PRIO 1 class MarlinSerial : public HardwareSerial { diff --git a/Marlin/src/HAL/STM32F1/sdio.cpp b/Marlin/src/HAL/STM32F1/sdio.cpp index 0e9a3b2d04..ffa6db1206 100644 --- a/Marlin/src/HAL/STM32F1/sdio.cpp +++ b/Marlin/src/HAL/STM32F1/sdio.cpp @@ -26,7 +26,7 @@ #include "../../inc/MarlinConfig.h" // Allow pins/pins.h to set density -#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) +#if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY) #include "sdio.h" diff --git a/Marlin/src/HAL/STM32_F4_F7/HAL.h b/Marlin/src/HAL/STM32_F4_F7/HAL.h index 5601400c5a..e132168205 100644 --- a/Marlin/src/HAL/STM32_F4_F7/HAL.h +++ b/Marlin/src/HAL/STM32_F4_F7/HAL.h @@ -46,24 +46,16 @@ // Serial override //extern HalSerial usb_serial; +#define _MSERIAL(X) SerialUART##X +#define MSERIAL(X) _MSERIAL(X) +#define SerialUART0 Serial1 + #if defined(STM32F4) && SERIAL_PORT == 0 #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration." #elif SERIAL_PORT == -1 #define MYSERIAL0 SerialUSB -#elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial1 -#elif SERIAL_PORT == 1 - #define MYSERIAL0 SerialUART1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 SerialUART2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 SerialUART3 -#elif SERIAL_PORT == 4 - #define MYSERIAL0 SerialUART4 -#elif SERIAL_PORT == 5 - #define MYSERIAL0 SerialUART5 -#elif SERIAL_PORT == 6 - #define MYSERIAL0 SerialUART6 +#elif WITHIN(SERIAL_PORT, 0, 6) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else #error "SERIAL_PORT must be from -1 to 6. Please update your configuration." #endif @@ -71,55 +63,22 @@ #ifdef SERIAL_PORT_2 #if defined(STM32F4) && SERIAL_PORT_2 == 0 #error "SERIAL_PORT_2 cannot be 0. (Port 0 does not exist.) Please update your configuration." - #elif SERIAL_PORT_2 == SERIAL_PORT - #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration." #elif SERIAL_PORT_2 == -1 #define MYSERIAL1 SerialUSB - #elif SERIAL_PORT_2 == 0 - #define MYSERIAL1 Serial1 - #elif SERIAL_PORT_2 == 1 - #define MYSERIAL1 SerialUART1 - #elif SERIAL_PORT_2 == 2 - #define MYSERIAL1 SerialUART2 - #elif SERIAL_PORT_2 == 3 - #define MYSERIAL1 SerialUART3 - #elif SERIAL_PORT_2 == 4 - #define MYSERIAL1 SerialUART4 - #elif SERIAL_PORT_2 == 5 - #define MYSERIAL1 SerialUART5 - #elif SERIAL_PORT_2 == 6 - #define MYSERIAL1 SerialUART6 + #elif WITHIN(SERIAL_PORT_2, 0, 6) + #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 6. Please update your configuration." #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #ifdef DGUS_SERIAL_PORT #if defined(STM32F4) && DGUS_SERIAL_PORT == 0 #error "DGUS_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration." - #elif DGUS_SERIAL_PORT == SERIAL_PORT - #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." - #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2 - #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." #elif DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL SerialUSB - #elif DGUS_SERIAL_PORT == 0 - #define DGUS_SERIAL Serial1 - #elif DGUS_SERIAL_PORT == 1 - #define DGUS_SERIAL SerialUART1 - #elif DGUS_SERIAL_PORT == 2 - #define DGUS_SERIAL SerialUART2 - #elif DGUS_SERIAL_PORT == 3 - #define DGUS_SERIAL SerialUART3 - #elif DGUS_SERIAL_PORT == 4 - #define DGUS_SERIAL SerialUART4 - #elif DGUS_SERIAL_PORT == 5 - #define DGUS_SERIAL SerialUART5 - #elif DGUS_SERIAL_PORT == 6 - #define DGUS_SERIAL SerialUART6 + #elif WITHIN(DGUS_SERIAL_PORT, 0, 6) + #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) #else #error "DGUS_SERIAL_PORT must be from -1 to 6. Please update your configuration." #endif diff --git a/Marlin/src/HAL/TEENSY31_32/HAL.h b/Marlin/src/HAL/TEENSY31_32/HAL.h index ad095cba83..31ceb8b87c 100644 --- a/Marlin/src/HAL/TEENSY31_32/HAL.h +++ b/Marlin/src/HAL/TEENSY31_32/HAL.h @@ -49,18 +49,14 @@ #define IS_TEENSY32 1 #endif -#define NUM_SERIAL 1 +#define _MSERIAL(X) Serial##X +#define MSERIAL(X) _MSERIAL(X) +#define Serial0 Serial #if SERIAL_PORT == -1 #define MYSERIAL0 SerialUSB -#elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial -#elif SERIAL_PORT == 1 - #define MYSERIAL0 Serial1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 Serial2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 Serial3 +#elif WITHIN(SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #endif #define HAL_SERVO_LIB libServo diff --git a/Marlin/src/HAL/TEENSY35_36/HAL.h b/Marlin/src/HAL/TEENSY35_36/HAL.h index 96be08d7b7..11f0fb941e 100644 --- a/Marlin/src/HAL/TEENSY35_36/HAL.h +++ b/Marlin/src/HAL/TEENSY35_36/HAL.h @@ -54,18 +54,14 @@ #define IS_TEENSY36 1 #endif -#define NUM_SERIAL 1 +#define _MSERIAL(X) Serial##X +#define MSERIAL(X) _MSERIAL(X) +#define Serial0 Serial #if SERIAL_PORT == -1 #define MYSERIAL0 SerialUSB -#elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial -#elif SERIAL_PORT == 1 - #define MYSERIAL0 Serial1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 Serial2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 Serial3 +#elif WITHIN(SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #endif #define HAL_SERVO_LIB libServo diff --git a/Marlin/src/HAL/TEENSY40_41/HAL.h b/Marlin/src/HAL/TEENSY40_41/HAL.h index 0626d4ee9c..77f7af2956 100644 --- a/Marlin/src/HAL/TEENSY40_41/HAL.h +++ b/Marlin/src/HAL/TEENSY40_41/HAL.h @@ -50,59 +50,26 @@ #define IS_TEENSY41 1 #endif +#define _MSERIAL(X) Serial##X +#define MSERIAL(X) _MSERIAL(X) +#define Serial0 Serial + #if SERIAL_PORT == -1 #define MYSERIAL0 SerialUSB -#elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial -#elif SERIAL_PORT == 1 - #define MYSERIAL0 Serial1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 Serial2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 Serial3 -#elif SERIAL_PORT == 4 - #define MYSERIAL0 Serial4 -#elif SERIAL_PORT == 5 - #define MYSERIAL0 Serial5 -#elif SERIAL_PORT == 6 - #define MYSERIAL0 Serial6 -#elif SERIAL_PORT == 7 - #define MYSERIAL0 Serial7 -#elif SERIAL_PORT == 8 - #define MYSERIAL0 Serial8 +#elif WITHIN(SERIAL_PORT, 0, 8) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else #error "The required SERIAL_PORT must be from -1 to 8. Please update your configuration." #endif #ifdef SERIAL_PORT_2 - #if SERIAL_PORT_2 == SERIAL_PORT - #error "SERIAL_PORT_2 must be different from SERIAL_PORT. Please update your configuration." - #elif SERIAL_PORT_2 == -1 + #if SERIAL_PORT_2 == -1 #define MYSERIAL1 usbSerial - #elif SERIAL_PORT_2 == 0 - #define MYSERIAL1 Serial - #elif SERIAL_PORT_2 == 1 - #define MYSERIAL1 Serial1 - #elif SERIAL_PORT_2 == 2 - #define MYSERIAL1 Serial2 - #elif SERIAL_PORT_2 == 3 - #define MYSERIAL1 Serial3 - #elif SERIAL_PORT_2 == 4 - #define MYSERIAL1 Serial4 - #elif SERIAL_PORT_2 == 5 - #define MYSERIAL1 Serial5 - #elif SERIAL_PORT_2 == 6 - #define MYSERIAL1 Serial6 - #elif SERIAL_PORT_2 == 7 - #define MYSERIAL1 Serial7 - #elif SERIAL_PORT_2 == 8 - #define MYSERIAL1 Serial8 + #elif WITHIN(SERIAL_PORT_2, 0, 8) + #define MYSERIAL0 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 8. Please update your configuration." #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #define HAL_SERVO_LIB libServo diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 22935c1460..e11439861b 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -912,17 +912,15 @@ void setup() { #endif #endif - #if NUM_SERIAL > 0 - MYSERIAL0.begin(BAUDRATE); - uint32_t serial_connect_timeout = millis() + 1000UL; - while (!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } - #if HAS_MULTI_SERIAL - MYSERIAL1.begin(BAUDRATE); - serial_connect_timeout = millis() + 1000UL; - while (!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } - #endif - SERIAL_ECHO_MSG("start"); + MYSERIAL0.begin(BAUDRATE); + uint32_t serial_connect_timeout = millis() + 1000UL; + while (!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } + #if HAS_MULTI_SERIAL + MYSERIAL1.begin(BAUDRATE); + serial_connect_timeout = millis() + 1000UL; + while (!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } #endif + SERIAL_ECHO_MSG("start"); #if BOTH(HAS_TFT_LVGL_UI, USE_WIFI_FUNCTION) mks_esp_wifi_init(); diff --git a/Marlin/src/gcode/config/M575.cpp b/Marlin/src/gcode/config/M575.cpp index 3aa5844653..44723b7f2f 100644 --- a/Marlin/src/gcode/config/M575.cpp +++ b/Marlin/src/gcode/config/M575.cpp @@ -53,23 +53,10 @@ void GcodeSuite::M575() { case 115200: case 250000: case 500000: case 1000000: { const int8_t port = parser.intval('P', -99); const bool set0 = (port == -99 || port == 0); - if (set0) { - SERIAL_ECHO_START(); - SERIAL_ECHOLNPAIR(" Serial " - #if HAS_MULTI_SERIAL - , '0', - #else - "0" - #endif - " baud rate set to ", baud - ); - } + if (set0) SERIAL_ECHO_MSG(" Serial ", '0', " baud rate set to ", baud); #if HAS_MULTI_SERIAL const bool set1 = (port == -99 || port == 1); - if (set1) { - SERIAL_ECHO_START(); - SERIAL_ECHOLNPAIR(" Serial ", '1', " baud rate set to ", baud); - } + if (set1) SERIAL_ECHO_MSG(" Serial ", '1', " baud rate set to ", baud); #endif SERIAL_FLUSH(); @@ -85,4 +72,4 @@ void GcodeSuite::M575() { } } -#endif // NUM_SERIAL > 0 && BAUD_RATE_GCODE +#endif // BAUD_RATE_GCODE diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 8d68b33ece..4c0b68e8ae 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -582,12 +582,10 @@ #error "SERIAL_XON_XOFF and SERIAL_STATS_* features not supported on USB-native AVR devices." #endif -#if SERIAL_PORT > 7 - #error "Set SERIAL_PORT to the port on your board. Usually this is 0." -#endif - -#if defined(SERIAL_PORT_2) && NUM_SERIAL < 2 - #error "SERIAL_PORT_2 is not supported for your MOTHERBOARD. Disable it to continue." +#ifndef SERIAL_PORT + #error "SERIAL_PORT must be defined in Configuration.h" +#elif defined(SERIAL_PORT_2) && SERIAL_PORT_2 == SERIAL_PORT + #error "SERIAL_PORT_2 cannot be the same as SERIAL_PORT. Please update your configuration." #endif /** @@ -2280,6 +2278,36 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal #error "Please enable only one LCD_SCREEN_ROT_* option: 0, 90, 180, or 270." #endif +/** + * Serial displays require a dedicated serial port + */ +#if HAS_DGUS_LCD + #ifndef DGUS_SERIAL_PORT + #error "The DGUS LCD requires DGUS_SERIAL_PORT to be defined in Configuration.h" + #elif DGUS_SERIAL_PORT == SERIAL_PORT + #error "DGUS_SERIAL_PORT cannot be the same as SERIAL_PORT. Please update your configuration." + #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2 + #error "DGUS_SERIAL_PORT cannot be the same as SERIAL_PORT_2. Please update your configuration." + #endif +#elif ENABLED(MALYAN_LCD) + #ifndef LCD_SERIAL_PORT + #error "MALYAN_LCD requires LCD_SERIAL_PORT to be defined in Configuration.h" + #elif LCD_SERIAL_PORT == SERIAL_PORT + #error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT. Please update your configuration." + #elif defined(SERIAL_PORT_2) && LCD_SERIAL_PORT == SERIAL_PORT_2 + #error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT_2. Please update your configuration." + #endif +#elif EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON) + #ifndef ANYCUBIC_LCD_SERIAL_PORT + #error "The ANYCUBIC LCD requires ANYCUBIC_LCD_SERIAL_PORT to be defined in Configuration.h" + #elif ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT + #error "ANYCUBIC_LCD_SERIAL_PORT cannot be the same as SERIAL_PORT. Please update your configuration." + #elif defined(SERIAL_PORT_2) && ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT_2 + #error "ANYCUBIC_LCD_SERIAL_PORT cannot be the same as SERIAL_PORT_2. Please update your configuration." + #endif + #define ANYCUBIC_LCD_SERIAL anycubicLcdSerial +#endif + /** * FYSETC Mini 12864 RGB backlighting required */ diff --git a/Marlin/src/lcd/extui/malyan_lcd.cpp b/Marlin/src/lcd/extui/malyan_lcd.cpp index b5148065c7..ece1b14235 100644 --- a/Marlin/src/lcd/extui/malyan_lcd.cpp +++ b/Marlin/src/lcd/extui/malyan_lcd.cpp @@ -45,7 +45,7 @@ #if ENABLED(MALYAN_LCD) -#define DEBUG_MALYAN_LCD +//#define DEBUG_MALYAN_LCD #include "ui_api.h" @@ -61,10 +61,6 @@ #define DEBUG_OUT ENABLED(DEBUG_MALYAN_LCD) #include "../../core/debug_out.h" -// On the Malyan M200, this will be Serial1. On a RAMPS board, -// it might not be. -#define LCD_SERIAL Serial1 - // This is based on longest sys command + a filename, plus some buffer // in case we encounter some data we don't recognize // There is no evidence a line will ever be this long, but better safe than sorry diff --git a/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h b/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h index f018a40c3e..a3cb987fff 100644 --- a/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h +++ b/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h @@ -117,10 +117,10 @@ * Hardware serial communication ports. * If undefined software serial is used according to the pins below */ - //#define X_HARDWARE_SERIAL Serial1 - //#define Y_HARDWARE_SERIAL Serial1 - //#define Z_HARDWARE_SERIAL Serial1 - //#define E0_HARDWARE_SERIAL Serial1 + //#define X_HARDWARE_SERIAL MSerial1 + //#define Y_HARDWARE_SERIAL MSerial1 + //#define Z_HARDWARE_SERIAL MSerial1 + //#define E0_HARDWARE_SERIAL MSerial1 // // Software serial diff --git a/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h b/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h index b658f3d714..78751a6bac 100644 --- a/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h +++ b/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h @@ -30,8 +30,8 @@ * Hardware serial communication ports. */ #if HAS_TMC_UART - #define X_HARDWARE_SERIAL Serial4 - #define Y_HARDWARE_SERIAL Serial4 - #define Z_HARDWARE_SERIAL Serial4 - #define E0_HARDWARE_SERIAL Serial4 + #define X_HARDWARE_SERIAL MSerial4 + #define Y_HARDWARE_SERIAL MSerial4 + #define Z_HARDWARE_SERIAL MSerial4 + #define E0_HARDWARE_SERIAL MSerial4 #endif diff --git a/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h b/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h index cb94f0bdca..0a0d857db3 100644 --- a/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h +++ b/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h @@ -52,8 +52,8 @@ * Hardware serial communication ports. */ #if HAS_TMC_UART - #define X_HARDWARE_SERIAL Serial4 - #define Y_HARDWARE_SERIAL Serial4 - #define Z_HARDWARE_SERIAL Serial4 - #define E0_HARDWARE_SERIAL Serial4 + #define X_HARDWARE_SERIAL MSerial4 + #define Y_HARDWARE_SERIAL MSerial4 + #define Z_HARDWARE_SERIAL MSerial4 + #define E0_HARDWARE_SERIAL MSerial4 #endif diff --git a/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h b/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h index b7db592e78..a04d6d261f 100644 --- a/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h +++ b/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h @@ -93,10 +93,10 @@ // // Hardware serial with switch // - #define X_HARDWARE_SERIAL Serial1 - #define Y_HARDWARE_SERIAL Serial1 - #define Z_HARDWARE_SERIAL Serial1 - #define E0_HARDWARE_SERIAL Serial1 + #define X_HARDWARE_SERIAL MSerial1 + #define Y_HARDWARE_SERIAL MSerial1 + #define Z_HARDWARE_SERIAL MSerial1 + #define E0_HARDWARE_SERIAL MSerial1 // The 4xTMC2209 module doesn't have a serial multiplexer and // needs to set *_SLAVE_ADDRESS in Configuration_adv.h for X,Y,Z,E0 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h index e39c8f2342..48da17adc5 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h @@ -188,17 +188,11 @@ * Hardware serial communication ports. * If undefined software serial is used according to the pins below */ - //#define X_HARDWARE_SERIAL Serial1 - //#define X2_HARDWARE_SERIAL Serial1 - //#define Y_HARDWARE_SERIAL Serial1 - //#define Y2_HARDWARE_SERIAL Serial1 - //#define Z_HARDWARE_SERIAL Serial1 - //#define Z2_HARDWARE_SERIAL Serial1 - //#define E0_HARDWARE_SERIAL Serial1 - //#define E1_HARDWARE_SERIAL Serial1 - //#define E2_HARDWARE_SERIAL Serial1 - //#define E3_HARDWARE_SERIAL Serial1 - //#define E4_HARDWARE_SERIAL Serial1 + //#define X_HARDWARE_SERIAL MSerial1 + //#define Y_HARDWARE_SERIAL MSerial1 + //#define Z_HARDWARE_SERIAL MSerial1 + //#define E0_HARDWARE_SERIAL MSerial1 + //#define E1_HARDWARE_SERIAL MSerial1 // Unused servo pins may be repurposed with SoftwareSerialM //#define X_SERIAL_TX_PIN PF8 // SERVO3_PIN -- XS2 - 6 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h index f6a3b555c3..bbacbf5585 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h @@ -83,10 +83,10 @@ * Hardware serial communication ports. * If undefined software serial is used according to the pins below */ - //#define X_HARDWARE_SERIAL Serial1 - //#define Y_HARDWARE_SERIAL Serial1 - //#define Z_HARDWARE_SERIAL Serial1 - //#define E0_HARDWARE_SERIAL Serial1 + //#define X_HARDWARE_SERIAL MSerial1 + //#define Y_HARDWARE_SERIAL MSerial1 + //#define Z_HARDWARE_SERIAL MSerial1 + //#define E0_HARDWARE_SERIAL MSerial1 // // Software serial diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h index ccb07b35f8..be3b130c85 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h @@ -132,17 +132,11 @@ * Hardware serial communication ports. * If undefined software serial is used according to the pins below */ - //#define X_HARDWARE_SERIAL Serial1 - //#define X2_HARDWARE_SERIAL Serial1 - //#define Y_HARDWARE_SERIAL Serial1 - //#define Y2_HARDWARE_SERIAL Serial1 - //#define Z_HARDWARE_SERIAL Serial1 - //#define Z2_HARDWARE_SERIAL Serial1 - //#define E0_HARDWARE_SERIAL Serial1 - //#define E1_HARDWARE_SERIAL Serial1 - //#define E2_HARDWARE_SERIAL Serial1 - //#define E3_HARDWARE_SERIAL Serial1 - //#define E4_HARDWARE_SERIAL Serial1 + //#define X_HARDWARE_SERIAL MSerial1 + //#define Y_HARDWARE_SERIAL MSerial1 + //#define Z_HARDWARE_SERIAL MSerial1 + //#define E0_HARDWARE_SERIAL MSerial1 + //#define E1_HARDWARE_SERIAL MSerial1 // // Software serial diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h index 2e74b6b15f..e445b8169b 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h @@ -125,17 +125,12 @@ * Hardware serial communication ports. * If undefined software serial is used according to the pins below */ - //#define X_HARDWARE_SERIAL Serial1 - //#define X2_HARDWARE_SERIAL Serial1 - //#define Y_HARDWARE_SERIAL Serial1 - //#define Y2_HARDWARE_SERIAL Serial1 - //#define Z_HARDWARE_SERIAL Serial1 - //#define Z2_HARDWARE_SERIAL Serial1 - //#define E0_HARDWARE_SERIAL Serial1 - //#define E1_HARDWARE_SERIAL Serial1 - //#define E2_HARDWARE_SERIAL Serial1 - //#define E3_HARDWARE_SERIAL Serial1 - //#define E4_HARDWARE_SERIAL Serial1 + //#define X_HARDWARE_SERIAL MSerial1 + //#define Y_HARDWARE_SERIAL MSerial1 + //#define Z_HARDWARE_SERIAL MSerial1 + //#define E0_HARDWARE_SERIAL MSerial1 + //#define E1_HARDWARE_SERIAL MSerial1 + //#define E2_HARDWARE_SERIAL MSerial1 // // Software serial diff --git a/buildroot/tests/malyan_M300-tests b/buildroot/tests/malyan_M300-tests index ada60d5584..1955accaa5 100755 --- a/buildroot/tests/malyan_M300-tests +++ b/buildroot/tests/malyan_M300-tests @@ -9,6 +9,7 @@ set -e restore_configs use_example_configs "delta/Malyan M300" opt_disable AUTO_BED_LEVELING_3POINT +opt_set LCD_SERIAL_PORT 1 exec_test $1 $2 "Malyan M300 (delta)" # cleanup