diff --git a/Marlin/src/HAL/DUE/HAL.h b/Marlin/src/HAL/DUE/HAL.h index 97b94b5db..90b6fabc0 100644 --- a/Marlin/src/HAL/DUE/HAL.h +++ b/Marlin/src/HAL/DUE/HAL.h @@ -94,7 +94,6 @@ #endif #endif - #include "MarlinSerial.h" #include "MarlinSerialUSB.h" diff --git a/Marlin/src/HAL/DUE/MarlinSerial.cpp b/Marlin/src/HAL/DUE/MarlinSerial.cpp index d827def42..d114c7598 100644 --- a/Marlin/src/HAL/DUE/MarlinSerial.cpp +++ b/Marlin/src/HAL/DUE/MarlinSerial.cpp @@ -629,23 +629,13 @@ void MarlinSerial::printFloat(double number, uint8_t digits) { // If not using the USB port as serial port #if SERIAL_PORT >= 0 - - // Preinstantiate - template class MarlinSerial>; - - // Instantiate - MarlinSerial> customizedSerial1; - + template class MarlinSerial>; // Define + MarlinSerial> customizedSerial1; // Instantiate #endif -#ifdef SERIAL_PORT_2 - - // Preinstantiate - template class MarlinSerial>; - - // Instantiate - MarlinSerial> customizedSerial2; - +#if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0 + template class MarlinSerial>; // Define + MarlinSerial> customizedSerial2; // Instantiate #endif #endif // ARDUINO_ARCH_SAM diff --git a/Marlin/src/HAL/DUE/MarlinSerial.h b/Marlin/src/HAL/DUE/MarlinSerial.h index eb26a5644..fa6a2c7d1 100644 --- a/Marlin/src/HAL/DUE/MarlinSerial.h +++ b/Marlin/src/HAL/DUE/MarlinSerial.h @@ -172,13 +172,9 @@ struct MarlinSerialCfg { }; #if SERIAL_PORT >= 0 - extern MarlinSerial> customizedSerial1; +#endif -#endif // SERIAL_PORT >= 0 - -#ifdef SERIAL_PORT_2 - +#if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0 extern MarlinSerial> customizedSerial2; - #endif diff --git a/Marlin/src/HAL/DUE/MarlinSerialUSB.cpp b/Marlin/src/HAL/DUE/MarlinSerialUSB.cpp index 41ffb52ba..7a020bbaf 100644 --- a/Marlin/src/HAL/DUE/MarlinSerialUSB.cpp +++ b/Marlin/src/HAL/DUE/MarlinSerialUSB.cpp @@ -29,7 +29,7 @@ #include "../../inc/MarlinConfig.h" -#if SERIAL_PORT == -1 +#if HAS_USB_SERIAL #include "MarlinSerialUSB.h" @@ -283,8 +283,12 @@ void MarlinSerialUSB::printFloat(double number, uint8_t digits) { } // Preinstantiate -MarlinSerialUSB customizedSerial1; - -#endif // SERIAL_PORT == -1 +#if SERIAL_PORT == -1 + MarlinSerialUSB customizedSerial1; +#endif +#if SERIAL_PORT_2 == -1 + MarlinSerialUSB customizedSerial2; +#endif +#endif // HAS_USB_SERIAL #endif // ARDUINO_ARCH_SAM diff --git a/Marlin/src/HAL/DUE/MarlinSerialUSB.h b/Marlin/src/HAL/DUE/MarlinSerialUSB.h index d8b051d37..9aece901b 100644 --- a/Marlin/src/HAL/DUE/MarlinSerialUSB.h +++ b/Marlin/src/HAL/DUE/MarlinSerialUSB.h @@ -28,7 +28,7 @@ #include "../../inc/MarlinConfig.h" -#if SERIAL_PORT == -1 +#if HAS_USB_SERIAL #include @@ -88,6 +88,12 @@ private: static void printFloat(double, uint8_t); }; -extern MarlinSerialUSB customizedSerial1; +#if SERIAL_PORT == -1 + extern MarlinSerialUSB customizedSerial1; +#endif + +#if SERIAL_PORT_2 == -1 + extern MarlinSerialUSB customizedSerial2; +#endif -#endif // SERIAL_PORT == -1 +#endif // HAS_USB_SERIAL diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 2907694fb..dd1f13fae 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -683,6 +683,10 @@ #define SPI_SPEED SPI_FULL_SPEED #endif +#if SERIAL_PORT == -1 || SERIAL_PORT_2 == -1 + #define HAS_USB_SERIAL 1 +#endif + /** * This setting is also used by M109 when trying to calculate * a ballpark safe margin to prevent wait-forever situation.