Skip to content

Commit 31c09e4

Browse files
committed
minimal-printf: Enable by a target config parameter
1 parent 609612c commit 31c09e4

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

targets/targets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"default_lib": "std",
1616
"bootloader_supported": false,
1717
"static_memory_defines": true,
18+
"printf_lib": "std",
1819
"config": {
1920
"console-uart": {
2021
"help": "Target has UART console on pins STDIO_UART_TX, STDIO_UART_RX. Value is only significant if target has SERIAL device.",

tools/toolchains/arm.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ def __init__(self, target, notify=None, macros=None,
8181
if "--library_type=microlib" not in self.flags['common']:
8282
self.flags['common'].append("--library_type=microlib")
8383

84+
if (
85+
target.printf_lib == "minimal-printf" and
86+
"-DMBED_MINIMAL_PRINTF" not in self.flags['common']
87+
):
88+
self.flags["common"].append("-DMBED_MINIMAL_PRINTF")
89+
8490
cpu = {
8591
"Cortex-M0+": "Cortex-M0plus",
8692
"Cortex-M4F": "Cortex-M4.fp.sp",
@@ -568,6 +574,12 @@ def __init__(self, target, *args, **kwargs):
568574
if "--library_type=microlib" not in self.flags['asm']:
569575
self.flags['asm'].append("--library_type=microlib")
570576

577+
if (
578+
target.printf_lib == "minimal-printf" and
579+
"-DMBED_MINIMAL_PRINTF" not in self.flags["common"]
580+
):
581+
self.flags["common"].append("-DMBED_MINIMAL_PRINTF")
582+
571583
if target.is_TrustZone_secure_target:
572584
if kwargs.get('build_dir', False):
573585
# Output secure import library

tools/toolchains/gcc.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
5858
self.flags["common"].append("-DMBED_RTOS_SINGLE_THREAD")
5959
self.flags["ld"].append("--specs=nano.specs")
6060

61+
if target.printf_lib == "minimal-printf":
62+
if "-DMBED_MINIMAL_PRINTF" not in self.flags['common']:
63+
self.flags["common"].append("-DMBED_MINIMAL_PRINTF")
64+
65+
minimal_printf_wraps = [
66+
"-Wl,--wrap,printf",
67+
"-Wl,--wrap,sprintf",
68+
"-Wl,--wrap,snprintf",
69+
"-Wl,--wrap,vprintf",
70+
"-Wl,--wrap,vsprintf",
71+
"-Wl,--wrap,vsnprintf",
72+
"-Wl,--wrap,fprintf",
73+
"-Wl,--wrap,vfprintf",
74+
]
75+
76+
for minimal_printf_wrap in minimal_printf_wraps:
77+
if minimal_printf_wrap not in self.flags["ld"]:
78+
self.flags["ld"].add(minimal_printf_wrap)
79+
6180
self.cpu = []
6281
if target.is_TrustZone_secure_target:
6382
# Enable compiler security extensions

tools/toolchains/iar.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
6969
define_string = self.make_ld_define("DOMAIN_NS", "0x1")
7070
self.flags["ld"].append(define_string)
7171

72+
if (
73+
target.printf_lib == "minimal-printf" and
74+
"-DMBED_MINIMAL_PRINTF" not in self.flags["common"]
75+
):
76+
self.flags["common"].append("-DMBED_MINIMAL_PRINTF")
77+
7278
core = target.core_without_NS
7379
cpu = {
7480
"Cortex-M7F": "Cortex-M7.fp.sp",

0 commit comments

Comments
 (0)