Skip to content

Commit fa37b20

Browse files
committed
Changed minimal-printf to call fputc so that it does not bypass the retargetting code
Removed minimal-printf-console-output
1 parent a6c316a commit fa37b20

File tree

6 files changed

+8
-88
lines changed

6 files changed

+8
-88
lines changed

TESTS/mbed_platform/minimal-printf/compliance/mbed_printf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int mbed_printf(const char *format, ...)
2323
{
2424
va_list arguments;
2525
va_start(arguments, format);
26-
int result = mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, NULL);
26+
int result = mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);
2727
va_end(arguments);
2828

2929
return result;
@@ -41,7 +41,7 @@ int mbed_snprintf(char *buffer, size_t length, const char *format, ...)
4141

4242
int mbed_vprintf(const char *format, va_list arguments)
4343
{
44-
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, NULL);
44+
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);
4545
}
4646

4747
int mbed_vsnprintf(char *buffer, size_t length, const char *format, va_list arguments)

platform/mbed_lib.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@
128128
"help": "Use the MPU if available to fault execution from RAM and writes to ROM. Can be disabled to reduce image size.",
129129
"value": true
130130
},
131-
"minimal-printf-console-output": {
132-
"help": "Console output when using mprintf profile. Options: UART, SWO",
133-
"value": "UART"
134-
},
135131
"minimal-printf-enable-64-bit": {
136132
"help": "Enable printing 64 bit integers when using mprintf profile",
137133
"value": true

platform/source/minimal-printf/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Library supports both printf and snprintf in 1252 bytes of flash.
55

66
Prints directly to stdio/UART without using malloc. All flags and precision modifiers are ignored.
7+
There is no error handling if a writing error occurs.
78

89
Supports:
910
* %d: signed integer [h, hh, (none), l, ll, z, j, t].
@@ -34,10 +35,6 @@ Minimal printf is configured by the following parameters defined in `platform/mb
3435
{
3536
"name": "platform",
3637
"config": {
37-
"minimal-printf-console-output": {
38-
"help": "Console output when using minimal-printf profile. Options: UART, SWO",
39-
"value": "UART"
40-
},
4138
"minimal-printf-enable-64-bit": {
4239
"help": "Enable printing 64 bit integers when using minimal-printf profile",
4340
"value": true

platform/source/minimal-printf/mbed_printf_implementation.c

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -26,59 +26,10 @@
2626
/***************************/
2727
#if TARGET_LIKE_MBED
2828

29-
#define CONSOLE_OUTPUT_UART 1
30-
#define CONSOLE_OUTPUT_SWO 2
31-
#define mbed_console_concat_(x) CONSOLE_OUTPUT_##x
32-
#define mbed_console_concat(x) mbed_console_concat_(x)
33-
#define CONSOLE_OUTPUT mbed_console_concat(MBED_CONF_PLATFORM_MINIMAL_PRINTF_CONSOLE_OUTPUT)
34-
3529
#if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES
3630
static char mbed_stdio_out_prev = 0;
3731
#endif
3832

39-
#if CONSOLE_OUTPUT == CONSOLE_OUTPUT_UART
40-
#if DEVICE_SERIAL
41-
/*
42-
Serial initialization and new line replacement is a direct copy from mbed_retarget.cpp
43-
If the static modifier were to be removed, this part of the code would not be necessary.
44-
*/
45-
#include "hal/serial_api.h"
46-
47-
static serial_t stdio_uart = { 0 };
48-
49-
/* module variable for keeping track of initialization */
50-
static bool not_initialized = true;
51-
52-
static void init_serial()
53-
{
54-
if (not_initialized) {
55-
not_initialized = false;
56-
57-
serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX);
58-
#if MBED_CONF_PLATFORM_STDIO_BAUD_RATE
59-
serial_baud(&stdio_uart, MBED_CONF_PLATFORM_STDIO_BAUD_RATE);
60-
#endif
61-
}
62-
}
63-
64-
#define MBED_INITIALIZE_PRINT(x) { init_serial(); }
65-
#define MBED_PRINT_CHARACTER(x) { serial_putc(&stdio_uart, x); }
66-
67-
#else
68-
69-
#define MBED_INITIALIZE_PRINT(x)
70-
#define MBED_PRINT_CHARACTER(x)
71-
72-
#endif // if DEVICE_SERIAL
73-
74-
#elif CONSOLE_OUTPUT == CONSOLE_OUTPUT_SWO
75-
76-
#include "hal/itm_api.h"
77-
78-
#define MBED_INITIALIZE_PRINT(x) { mbed_itm_init(); }
79-
#define MBED_PRINT_CHARACTER(x) { mbed_itm_send(ITM_PORT_SWO, x); }
80-
81-
#endif // if CONSOLE_OUTPUT
8233

8334
/***************************/
8435
/* Linux */
@@ -88,8 +39,6 @@ static void init_serial()
8839
#define MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FLOATING_POINT 1
8940
#define MBED_CONF_PLATFORM_MINIMAL_PRINTF_SET_FLOATING_POINT_MAX_DECIMALS 6
9041
#define MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_64_BIT 1
91-
#define MBED_INITIALIZE_PRINT(x) { ; }
92-
#define MBED_PRINT_CHARACTER(x) { printf("%c", x); }
9342
#endif
9443

9544
#ifndef MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FLOATING_POINT
@@ -177,14 +126,7 @@ static void mbed_minimal_putchar(char *buffer, size_t length, int *result, char
177126
if (buffer) {
178127
buffer[*result] = data;
179128
} else {
180-
#if MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FILE_STREAM
181-
if (stream) {
182-
fputc(data, (FILE *) stream);
183-
} else
184-
#endif
185-
{
186-
MBED_PRINT_CHARACTER(data);
187-
}
129+
fputc(data, stream);
188130
}
189131
}
190132
/* increment 'result' even if data was not written. This ensures that
@@ -434,9 +376,6 @@ static void mbed_minimal_formatted_string_string(char *buffer, size_t length, in
434376
*/
435377
int mbed_minimal_formatted_string(char *buffer, size_t length, const char *format, va_list arguments, FILE *stream)
436378
{
437-
/* initialize output if needed */
438-
MBED_INITIALIZE_PRINT();
439-
440379
int result = 0;
441380
bool empty_buffer = false;
442381

platform/source/minimal-printf/mbed_printf_wrapper.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,11 @@
6464
#warning "This compiler is not yet supported."
6565
#endif
6666

67-
// Prevent optimization of printf() by the ARMCC or IAR compiler.
68-
// This is done to prevent optimization which can cause printf() to be
69-
// substituted with a different function (e.g. puts()) and cause
70-
// the output to be missing some strings.
71-
// Note: Optimization prevention for other supported compilers is done
72-
// via compiler optional command line arguments.
73-
#if defined(__CC_ARM) /* ARMC5 */
74-
#pragma push
75-
#pragma O0
76-
#elif defined(__ICCARM__) /* IAR */
77-
#pragma optimize=none
78-
#endif
7967
int SUB_PRINTF(const char *format, ...)
8068
{
8169
va_list arguments;
8270
va_start(arguments, format);
83-
int result = mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, NULL);
71+
int result = mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);
8472
va_end(arguments);
8573

8674
return result;
@@ -108,7 +96,7 @@ int SUB_SNPRINTF(char *buffer, size_t length, const char *format, ...)
10896

10997
int SUB_VPRINTF(const char *format, va_list arguments)
11098
{
111-
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, NULL);
99+
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);
112100
}
113101

114102
int SUB_VSPRINTF(char *buffer, const char *format, va_list arguments)

tools/profiles/extensions/minimal-printf.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"GCC_ARM": {
3-
"common": ["-DMBED_MINIMAL_PRINTF", "-fno-builtin-printf"],
3+
"common": ["-DMBED_MINIMAL_PRINTF"],
44
"ld": ["-Wl,--wrap,printf", "-Wl,--wrap,sprintf", "-Wl,--wrap,snprintf",
55
"-Wl,--wrap,vprintf", "-Wl,--wrap,vsprintf", "-Wl,--wrap,vsnprintf",
66
"-Wl,--wrap,fprintf", "-Wl,--wrap,vfprintf"]
77
},
88
"ARMC6": {
9-
"common": ["-DMBED_MINIMAL_PRINTF", "-fno-builtin-printf"]
9+
"common": ["-DMBED_MINIMAL_PRINTF"]
1010
},
1111
"ARM": {
1212
"common": ["-DMBED_MINIMAL_PRINTF"]

0 commit comments

Comments
 (0)