From 8ec86b810d96e1692efa8253714957d3f95ae313 Mon Sep 17 00:00:00 2001 From: Giuliano Zaro <3684609+GMagician@users.noreply.github.com> Date: Sun, 14 Feb 2021 04:04:22 +0100 Subject: [PATCH] Don't create unused Serial Port instances (#21066) Co-authored-by: Scott Lahteine --- Marlin/src/HAL/DUE/HAL.cpp | 19 +++++++++++++------ Marlin/src/HAL/DUE/HAL.h | 4 ++-- Marlin/src/HAL/SAMD51/HAL.cpp | 17 +++++++++++++++-- Marlin/src/HAL/SAMD51/HAL.h | 8 +++++++- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/Marlin/src/HAL/DUE/HAL.cpp b/Marlin/src/HAL/DUE/HAL.cpp index 2ae70843f0..c15adee0c7 100644 --- a/Marlin/src/HAL/DUE/HAL.cpp +++ b/Marlin/src/HAL/DUE/HAL.cpp @@ -102,11 +102,18 @@ uint16_t HAL_adc_get_result() { return HAL_adc_result; } -// Forward the default serial port -DefaultSerial MSerial(false, Serial); - -DefaultSerial1 MSerial1(false, Serial1); -DefaultSerial2 MSerial2(false, Serial2); -DefaultSerial3 MSerial3(false, Serial3); +// Forward the default serial ports +#if ANY_SERIAL_IS(0) + DefaultSerial MSerial(false, Serial); +#endif +#if ANY_SERIAL_IS(1) + DefaultSerial1 MSerial1(false, Serial1); +#endif +#if ANY_SERIAL_IS(2) + DefaultSerial2 MSerial2(false, Serial2); +#endif +#if ANY_SERIAL_IS(3) + DefaultSerial3 MSerial3(false, Serial3); +#endif #endif // ARDUINO_ARCH_SAM diff --git a/Marlin/src/HAL/DUE/HAL.h b/Marlin/src/HAL/DUE/HAL.h index 78c8a800b9..b1c6a38c0f 100644 --- a/Marlin/src/HAL/DUE/HAL.h +++ b/Marlin/src/HAL/DUE/HAL.h @@ -37,12 +37,12 @@ #include #include "../../core/serial_hook.h" -typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial; -extern DefaultSerial MSerial; +typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial; typedef ForwardSerial0Type< decltype(Serial1) > DefaultSerial1; typedef ForwardSerial0Type< decltype(Serial2) > DefaultSerial2; typedef ForwardSerial0Type< decltype(Serial3) > DefaultSerial3; +extern DefaultSerial MSerial; extern DefaultSerial1 MSerial1; extern DefaultSerial2 MSerial2; extern DefaultSerial3 MSerial3; diff --git a/Marlin/src/HAL/SAMD51/HAL.cpp b/Marlin/src/HAL/SAMD51/HAL.cpp index a413c4cd80..17e89c723f 100644 --- a/Marlin/src/HAL/SAMD51/HAL.cpp +++ b/Marlin/src/HAL/SAMD51/HAL.cpp @@ -25,8 +25,21 @@ #include #ifdef ADAFRUIT_GRAND_CENTRAL_M4 - DefaultSerial MSerial(false, Serial); - DefaultSerial1 MSerial1(false, Serial1); + #if ANY_SERIAL_IS(-1) + DefaultSerial MSerial(false, Serial); + #endif + #if ANY_SERIAL_IS(0) + DefaultSerial1 MSerial1(false, Serial1); + #endif + #if ANY_SERIAL_IS(1) + DefaultSerial2 MSerial2(false, Serial2); + #endif + #if ANY_SERIAL_IS(2) + DefaultSerial3 MSerial3(false, Serial3); + #endif + #if ANY_SERIAL_IS(3) + DefaultSerial4 MSerial4(false, Serial4); + #endif #endif // ------------------------ diff --git a/Marlin/src/HAL/SAMD51/HAL.h b/Marlin/src/HAL/SAMD51/HAL.h index f28583c771..7b272af842 100644 --- a/Marlin/src/HAL/SAMD51/HAL.h +++ b/Marlin/src/HAL/SAMD51/HAL.h @@ -33,9 +33,15 @@ // Serial ports typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial; - extern DefaultSerial MSerial; typedef ForwardSerial0Type< decltype(Serial1) > DefaultSerial1; + typedef ForwardSerial0Type< decltype(Serial2) > DefaultSerial2; + typedef ForwardSerial0Type< decltype(Serial3) > DefaultSerial3; + typedef ForwardSerial0Type< decltype(Serial4) > DefaultSerial4; + extern DefaultSerial MSerial; extern DefaultSerial1 MSerial1; + extern DefaultSerial2 MSerial2; + extern DefaultSerial3 MSerial3; + extern DefaultSerial4 MSerial4; // MYSERIAL0 required before MarlinSerial includes!