Skip to content

Commit d9f3263

Browse files
evedonhugueskamba
authored andcommitted
Changed minimal-printf to call fputc so that it does not bypass the retargetting code
Removed minimal-printf-console-output
1 parent 98c0fd0 commit d9f3263

File tree

8 files changed

+11
-117
lines changed

8 files changed

+11
-117
lines changed

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

Lines changed: 2 additions & 4 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,15 +41,14 @@ 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)
4848
{
4949
return mbed_minimal_formatted_string(buffer, length, format, arguments, NULL);
5050
}
5151

52-
#if MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FILE_STREAM
5352
int mbed_fprintf(FILE *stream, const char *format, ...)
5453
{
5554
va_list arguments;
@@ -64,4 +63,3 @@ int mbed_vfprintf(FILE *stream, const char *format, va_list arguments)
6463
{
6564
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stream);
6665
}
67-
#endif

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ int mbed_vprintf(const char *format, va_list arguments);
5252
*/
5353
int mbed_vsnprintf(char *buffer, size_t length, const char *format, va_list arguments);
5454

55-
#if MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FILE_STREAM
5655
/**
5756
* Minimal fprintf
5857
*
@@ -66,7 +65,6 @@ int mbed_fprintf(FILE *stream, const char *format, ...);
6665
* Prints directly to file stream without using malloc.
6766
*/
6867
int mbed_vfprintf(FILE *stream, const char *format, va_list arguments);
69-
#endif
7068

7169
#ifdef __cplusplus
7270
}

TESTS/mbed_platform/minimal-printf/compliance/test_app.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

platform/mbed_lib.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,10 @@
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
138134
},
139-
"minimal-printf-enable-file-stream": {
140-
"help": "Enable printing to a FILE stream when using mprintf profile",
141-
"value": true
142-
},
143135
"minimal-printf-enable-floating-point": {
144136
"help": "Enable floating point printing when using mprintf profile",
145137
"value": true

platform/source/minimal-printf/README.md

Lines changed: 3 additions & 11 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].
@@ -30,22 +31,14 @@ Floating point limitations:
3031

3132
Minimal printf is configured by the following parameters defined in `platform/mbed_lib.json`:
3233

33-
```
34+
```json
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
4441
},
45-
"minimal-printf-enable-file-stream": {
46-
"help": "Enable printing to a FILE stream when using minimal-printf profile",
47-
"value": true
48-
},
4942
"minimal-printf-enable-floating-point": {
5043
"help": "Enable floating point printing when using minimal-printf profile",
5144
"value": true
@@ -64,10 +57,9 @@ If your target does not require some options then you can override the default c
6457

6558
In mbed_app.json:
6659

67-
```
60+
```json
6861
"target_overrides": {
6962
"*": {
70-
"platform.minimal-printf-enable-file-stream": false,
7163
"platform.minimal-printf-enable-floating-point": false,
7264
"platform.minimal-printf-set-floating-point-max-decimals": 6,
7365
"platform.minimal-printf-enable-64-bit": false

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: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@
3434
#define SUB_VSPRINTF __wrap_vsprintf
3535
#define SUPER_VSNPRINTF __real_vsnprintf
3636
#define SUB_VSNPRINTF __wrap_vsnprintf
37-
#if MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FILE_STREAM
3837
#define SUPER_FPRINTF __real_fprintf
3938
#define SUB_FPRINTF __wrap_fprintf
4039
#define SUPER_VFPRINTF __real_vfprintf
4140
#define SUB_VFPRINTF __wrap_vfprintf
42-
#endif
4341
#elif defined(TOOLCHAIN_ARM) /* ARMC5/ARMC6 */\
4442
|| defined(__ICCARM__) /* IAR */
4543
#define SUPER_PRINTF $Super$$printf
@@ -54,33 +52,19 @@
5452
#define SUB_VSPRINTF $Sub$$vsprintf
5553
#define SUPER_VSNPRINTF $Super$$vsnprintf
5654
#define SUB_VSNPRINTF $Sub$$vsnprintf
57-
#if MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FILE_STREAM
5855
#define SUPER_FPRINTF $Super$$fprintf
5956
#define SUB_FPRINTF $Sub$$fprintf
6057
#define SUPER_VFPRINTF $Super$$vfprintf
6158
#define SUB_VFPRINTF $Sub$$vfprintf
62-
#endif
6359
#else
6460
#warning "This compiler is not yet supported."
6561
#endif
6662

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
7963
int SUB_PRINTF(const char *format, ...)
8064
{
8165
va_list arguments;
8266
va_start(arguments, format);
83-
int result = mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, NULL);
67+
int result = mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);
8468
va_end(arguments);
8569

8670
return result;
@@ -108,7 +92,7 @@ int SUB_SNPRINTF(char *buffer, size_t length, const char *format, ...)
10892

10993
int SUB_VPRINTF(const char *format, va_list arguments)
11094
{
111-
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, NULL);
95+
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);
11296
}
11397

11498
int SUB_VSPRINTF(char *buffer, const char *format, va_list arguments)
@@ -121,7 +105,6 @@ int SUB_VSNPRINTF(char *buffer, size_t length, const char *format, va_list argum
121105
return mbed_minimal_formatted_string(buffer, length, format, arguments, NULL);
122106
}
123107

124-
#if MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FILE_STREAM
125108
int SUB_FPRINTF(FILE *stream, const char *format, ...)
126109
{
127110
va_list arguments;
@@ -136,6 +119,5 @@ int SUB_VFPRINTF(FILE *stream, const char *format, va_list arguments)
136119
{
137120
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stream);
138121
}
139-
#endif
140122

141-
#endif // MBED_MINIMAL_PRINTF
123+
#endif // MBED_MINIMAL_PRINTF

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)