From 6f10745f0ac3d57425b135abc3a325de847753a3 Mon Sep 17 00:00:00 2001 From: Rainer Clasen Date: Mon, 24 Jul 2017 21:33:46 +0200 Subject: [PATCH] Keep Serial from being linked when disabled (#877) Even with MY_DISABLED_SERIAL defined, the linker is still adding the Serial object to the binary. That's because a) the MySensors *.cpp files are actually included into the sketch and compiled as part of it (and not compiled separately and then linked) and b) due the the default(?) behavior of the linker (https://github.com/arduino/Arduino/issues/4579). --- hal/architecture/MyHwAVR.cpp | 2 ++ hal/architecture/MyHwESP8266.cpp | 2 ++ hal/architecture/MyHwNRF5.cpp | 2 ++ hal/architecture/MyHwSAMD.cpp | 2 ++ hal/architecture/MyHwSTM32F1.cpp | 2 ++ hal/architecture/MyHwTeensy3.cpp | 2 ++ 6 files changed, 12 insertions(+) diff --git a/hal/architecture/MyHwAVR.cpp b/hal/architecture/MyHwAVR.cpp index adef13c..b7158fe 100644 --- a/hal/architecture/MyHwAVR.cpp +++ b/hal/architecture/MyHwAVR.cpp @@ -303,6 +303,7 @@ uint16_t hwFreeMem() void hwDebugPrint(const char *fmt, ... ) { +#ifndef MY_DISABLED_SERIAL char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_FEATURE // prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE) @@ -327,4 +328,5 @@ void hwDebugPrint(const char *fmt, ... ) va_end (args); MY_SERIALDEVICE.print(fmtBuffer); MY_SERIALDEVICE.flush(); +#endif } diff --git a/hal/architecture/MyHwESP8266.cpp b/hal/architecture/MyHwESP8266.cpp index b2f053a..92ff089 100644 --- a/hal/architecture/MyHwESP8266.cpp +++ b/hal/architecture/MyHwESP8266.cpp @@ -149,6 +149,7 @@ uint16_t hwFreeMem() void hwDebugPrint(const char *fmt, ... ) { +#ifndef MY_DISABLED_SERIAL char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_FEATURE // prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE) @@ -173,4 +174,5 @@ void hwDebugPrint(const char *fmt, ... ) va_end (args); MY_SERIALDEVICE.print(fmtBuffer); MY_SERIALDEVICE.flush(); +#endif } diff --git a/hal/architecture/MyHwNRF5.cpp b/hal/architecture/MyHwNRF5.cpp index 889343e..3aa7b49 100644 --- a/hal/architecture/MyHwNRF5.cpp +++ b/hal/architecture/MyHwNRF5.cpp @@ -472,6 +472,7 @@ uint16_t hwFreeMem() void hwDebugPrint(const char *fmt, ...) { +#ifndef MY_DISABLED_SERIAL char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_FEATURE // prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE) @@ -496,4 +497,5 @@ void hwDebugPrint(const char *fmt, ...) va_end (args); MY_SERIALDEVICE.print(fmtBuffer); MY_SERIALDEVICE.flush(); +#endif } diff --git a/hal/architecture/MyHwSAMD.cpp b/hal/architecture/MyHwSAMD.cpp index 04a3b51..0a022d8 100644 --- a/hal/architecture/MyHwSAMD.cpp +++ b/hal/architecture/MyHwSAMD.cpp @@ -181,6 +181,7 @@ uint16_t hwFreeMem() void hwDebugPrint(const char *fmt, ... ) { +#ifndef MY_DISABLED_SERIAL if (MY_SERIALDEVICE) { char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_FEATURE @@ -207,4 +208,5 @@ void hwDebugPrint(const char *fmt, ... ) MY_SERIALDEVICE.print(fmtBuffer); // MY_SERIALDEVICE.flush(); } +#endif } diff --git a/hal/architecture/MyHwSTM32F1.cpp b/hal/architecture/MyHwSTM32F1.cpp index ef34318..52e14e9 100644 --- a/hal/architecture/MyHwSTM32F1.cpp +++ b/hal/architecture/MyHwSTM32F1.cpp @@ -169,6 +169,7 @@ uint16_t hwFreeMem() void hwDebugPrint(const char *fmt, ...) { +#ifndef MY_DISABLED_SERIAL char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_FEATURE // prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE) @@ -195,4 +196,5 @@ void hwDebugPrint(const char *fmt, ...) // Disable flush since current STM32duino implementation performs a reset // instead of an actual flush //MY_SERIALDEVICE.flush(); +#endif } diff --git a/hal/architecture/MyHwTeensy3.cpp b/hal/architecture/MyHwTeensy3.cpp index eb5071f..9acdfff 100644 --- a/hal/architecture/MyHwTeensy3.cpp +++ b/hal/architecture/MyHwTeensy3.cpp @@ -167,6 +167,7 @@ void hwRandomNumberInit(void) void hwDebugPrint(const char *fmt, ...) { +#ifndef MY_DISABLED_SERIAL char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_FEATURE // prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE) @@ -190,4 +191,5 @@ void hwDebugPrint(const char *fmt, ...) #endif va_end(args); MY_SERIALDEVICE.print(fmtBuffer); +#endif }