Skip to content

Commit 5ff5539

Browse files
committed
Add: printf() could be used in non-global-constructor functions when debug=On
1 parent 8ed9028 commit 5ff5539

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

boards.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ seeed_wio_terminal.menu.usbstack.tinyusb=TinyUSB
8282
seeed_wio_terminal.menu.usbstack.tinyusb.build.flags.usbstack=-DUSE_TINYUSB
8383
seeed_wio_terminal.menu.debug.off=Off
8484
seeed_wio_terminal.menu.debug.on=On
85-
seeed_wio_terminal.menu.debug.on.build.flags.debug=-g
85+
seeed_wio_terminal.menu.debug.on.build.flags.debug=-g -DDEBUG=1
8686

8787
# Seeed Femto M0 (SAMD21)
8888
# ------------------------------
@@ -118,7 +118,7 @@ Seeed_femto_m0.menu.usbstack.tinyusb=TinyUSB
118118
Seeed_femto_m0.menu.usbstack.tinyusb.build.flags.usbstack=-DUSE_TINYUSB
119119
Seeed_femto_m0.menu.debug.off=Off
120120
Seeed_femto_m0.menu.debug.on=On
121-
Seeed_femto_m0.menu.debug.on.build.flags.debug=-g
121+
Seeed_femto_m0.menu.debug.on.build.flags.debug=-g -DDEBUG=1
122122

123123
# Seeed XIAO M0 (SAMD21)
124124
# ------------------------------
@@ -154,7 +154,7 @@ seeed_XIAO_m0.menu.usbstack.tinyusb=TinyUSB
154154
seeed_XIAO_m0.menu.usbstack.tinyusb.build.flags.usbstack=-DUSE_TINYUSB
155155
seeed_XIAO_m0.menu.debug.off=Off
156156
seeed_XIAO_m0.menu.debug.on=On
157-
seeed_XIAO_m0.menu.debug.on.build.flags.debug=-g
157+
seeed_XIAO_m0.menu.debug.on.build.flags.debug=-g -DDEBUG=1
158158

159159

160160
# Seeed XIAO M0 (SAMD21)
@@ -191,7 +191,7 @@ Wio_Lite_MG126.menu.usbstack.tinyusb=TinyUSB
191191
Wio_Lite_MG126.menu.usbstack.tinyusb.build.flags.usbstack=-DUSE_TINYUSB
192192
Wio_Lite_MG126.menu.debug.off=Off
193193
Wio_Lite_MG126.menu.debug.on=On
194-
Wio_Lite_MG126.menu.debug.on.build.flags.debug=-g
194+
Wio_Lite_MG126.menu.debug.on.build.flags.debug=-g -DDEBUG=1
195195

196196

197197
# Wio GPS Board
@@ -228,7 +228,7 @@ WioGPS.menu.usbstack.tinyusb=TinyUSB
228228
WioGPS.menu.usbstack.tinyusb.build.flags.usbstack=-DUSE_TINYUSB
229229
WioGPS.menu.debug.off=Off
230230
WioGPS.menu.debug.on=On
231-
WioGPS.menu.debug.on.build.flags.debug=-g
231+
WioGPS.menu.debug.on.build.flags.debug=-g -DDEBUG=1
232232

233233
# Seeeduino Zero
234234
# ---------------------------------------
@@ -264,7 +264,7 @@ zero.menu.usbstack.tinyusb=TinyUSB
264264
zero.menu.usbstack.tinyusb.build.flags.usbstack=-DUSE_TINYUSB
265265
zero.menu.debug.off=Off
266266
zero.menu.debug.on=On
267-
zero.menu.debug.on.build.flags.debug=-g
267+
zero.menu.debug.on.build.flags.debug=-g -DDEBUG=1
268268

269269
# Seeeduino LoRaWAN
270270
# ---------------------------------------
@@ -300,7 +300,7 @@ rolawan.menu.usbstack.tinyusb=TinyUSB
300300
rolawan.menu.usbstack.tinyusb.build.flags.usbstack=-DUSE_TINYUSB
301301
rolawan.menu.debug.off=Off
302302
rolawan.menu.debug.on=On
303-
rolawan.menu.debug.on.build.flags.debug=-g
303+
rolawan.menu.debug.on.build.flags.debug=-g -DDEBUG=1
304304

305305

306306
# Seeed Grove UI Wireless (SAMD51)
@@ -364,6 +364,6 @@ seeed_grove_ui_wireless.menu.usbstack.tinyusb=TinyUSB
364364
seeed_grove_ui_wireless.menu.usbstack.tinyusb.build.flags.usbstack=-DUSE_TINYUSB
365365
seeed_grove_ui_wireless.menu.debug.off=Off
366366
seeed_grove_ui_wireless.menu.debug.on=On
367-
seeed_grove_ui_wireless.menu.debug.on.build.flags.debug=-g
367+
seeed_grove_ui_wireless.menu.debug.on.build.flags.debug=-g -DDEBUG=1
368368

369369

cores/arduino/Retarget.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,21 @@ extern int __real__write (int fd, const char *ptr, int len);
5555
int __wrap__write (int fd, const char *ptr, int len) {
5656
(void)fd; // UNUSED
5757

58-
int i;
58+
#if defined(DEBUG) && DEBUG
59+
static int serial_init = 0;
60+
if (!serial_init) {
61+
SERIAL_PORT_HARDWARE.begin(115200);
62+
serial_init = 1;
63+
}
5964

60-
if (!Serial) {
65+
if (!SERIAL_PORT_HARDWARE) {
6166
return len;
6267
}
6368

64-
for (i = 0; i < len; i++) {
65-
Serial.write(ptr[i]);
69+
for (int i = 0; i < len; i++) {
70+
SERIAL_PORT_HARDWARE.write(ptr[i]);
6671
}
72+
#endif
6773
return len;
6874
}
6975

platform.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,
4747
compiler.elf2hex.bin.flags=-O binary
4848
compiler.elf2hex.hex.flags=-O ihex -R .eeprom
4949
compiler.elf2hex.cmd=arm-none-eabi-objcopy
50-
compiler.ldflags=-mcpu={build.mcu} -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -u _printf_float -u _scanf_float
50+
compiler.ldflags=-mcpu={build.mcu} -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -u _printf_float -u _scanf_float -Wl,--wrap,_write -u __wrap__write
5151
compiler.size.cmd=arm-none-eabi-size
5252
compiler.define=-DARDUINO=
5353
compiler.readelf.cmd=arm-none-eabi-readelf

0 commit comments

Comments
 (0)