Skip to content

Commit 113af1f

Browse files
committed
Keep Serial from being linked when disabled
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).
1 parent 59337b1 commit 113af1f

File tree

6 files changed

+12
-0
lines changed

6 files changed

+12
-0
lines changed

Diff for: hal/architecture/MyHwAVR.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ uint16_t hwFreeMem()
303303

304304
void hwDebugPrint(const char *fmt, ... )
305305
{
306+
#ifndef MY_DISABLED_SERIAL
306307
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
307308
#ifdef MY_GATEWAY_FEATURE
308309
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
@@ -327,4 +328,5 @@ void hwDebugPrint(const char *fmt, ... )
327328
va_end (args);
328329
MY_SERIALDEVICE.print(fmtBuffer);
329330
MY_SERIALDEVICE.flush();
331+
#endif
330332
}

Diff for: hal/architecture/MyHwESP8266.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ uint16_t hwFreeMem()
149149

150150
void hwDebugPrint(const char *fmt, ... )
151151
{
152+
#ifndef MY_DISABLED_SERIAL
152153
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
153154
#ifdef MY_GATEWAY_FEATURE
154155
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
@@ -173,4 +174,5 @@ void hwDebugPrint(const char *fmt, ... )
173174
va_end (args);
174175
MY_SERIALDEVICE.print(fmtBuffer);
175176
MY_SERIALDEVICE.flush();
177+
#endif
176178
}

Diff for: hal/architecture/MyHwNRF5.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ uint16_t hwFreeMem()
472472

473473
void hwDebugPrint(const char *fmt, ...)
474474
{
475+
#ifndef MY_DISABLED_SERIAL
475476
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
476477
#ifdef MY_GATEWAY_FEATURE
477478
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
@@ -496,4 +497,5 @@ void hwDebugPrint(const char *fmt, ...)
496497
va_end (args);
497498
MY_SERIALDEVICE.print(fmtBuffer);
498499
MY_SERIALDEVICE.flush();
500+
#endif
499501
}

Diff for: hal/architecture/MyHwSAMD.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ uint16_t hwFreeMem()
181181

182182
void hwDebugPrint(const char *fmt, ... )
183183
{
184+
#ifndef MY_DISABLED_SERIAL
184185
if (MY_SERIALDEVICE) {
185186
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
186187
#ifdef MY_GATEWAY_FEATURE
@@ -207,4 +208,5 @@ void hwDebugPrint(const char *fmt, ... )
207208
MY_SERIALDEVICE.print(fmtBuffer);
208209
// MY_SERIALDEVICE.flush();
209210
}
211+
#endif
210212
}

Diff for: hal/architecture/MyHwSTM32F1.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ uint16_t hwFreeMem()
169169

170170
void hwDebugPrint(const char *fmt, ...)
171171
{
172+
#ifndef MY_DISABLED_SERIAL
172173
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
173174
#ifdef MY_GATEWAY_FEATURE
174175
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
@@ -195,4 +196,5 @@ void hwDebugPrint(const char *fmt, ...)
195196
// Disable flush since current STM32duino implementation performs a reset
196197
// instead of an actual flush
197198
//MY_SERIALDEVICE.flush();
199+
#endif
198200
}

Diff for: hal/architecture/MyHwTeensy3.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ void hwRandomNumberInit(void)
167167

168168
void hwDebugPrint(const char *fmt, ...)
169169
{
170+
#ifndef MY_DISABLED_SERIAL
170171
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
171172
#ifdef MY_GATEWAY_FEATURE
172173
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
@@ -190,4 +191,5 @@ void hwDebugPrint(const char *fmt, ...)
190191
#endif
191192
va_end(args);
192193
MY_SERIALDEVICE.print(fmtBuffer);
194+
#endif
193195
}

0 commit comments

Comments
 (0)