Changed minimal-printf to call fputc so that it does not bypass the retargetting code

Removed minimal-printf-console-output
pull/11235/head
Evelyne Donnaes 2019-08-15 12:33:32 +01:00 committed by Hugues Kamba
parent 98c0fd06be
commit d9f32639eb
8 changed files with 11 additions and 117 deletions

View File

@ -23,7 +23,7 @@ int mbed_printf(const char *format, ...)
{
va_list arguments;
va_start(arguments, format);
int result = mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, NULL);
int result = mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);
va_end(arguments);
return result;
@ -41,7 +41,7 @@ int mbed_snprintf(char *buffer, size_t length, const char *format, ...)
int mbed_vprintf(const char *format, va_list arguments)
{
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, NULL);
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);
}
int mbed_vsnprintf(char *buffer, size_t length, const char *format, va_list arguments)
@ -49,7 +49,6 @@ int mbed_vsnprintf(char *buffer, size_t length, const char *format, va_list argu
return mbed_minimal_formatted_string(buffer, length, format, arguments, NULL);
}
#if MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FILE_STREAM
int mbed_fprintf(FILE *stream, const char *format, ...)
{
va_list arguments;
@ -64,4 +63,3 @@ int mbed_vfprintf(FILE *stream, const char *format, va_list arguments)
{
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stream);
}
#endif

View File

@ -52,7 +52,6 @@ int mbed_vprintf(const char *format, va_list arguments);
*/
int mbed_vsnprintf(char *buffer, size_t length, const char *format, va_list arguments);
#if MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FILE_STREAM
/**
* Minimal fprintf
*
@ -66,7 +65,6 @@ int mbed_fprintf(FILE *stream, const char *format, ...);
* Prints directly to file stream without using malloc.
*/
int mbed_vfprintf(FILE *stream, const char *format, va_list arguments);
#endif
#ifdef __cplusplus
}

View File

@ -1,7 +0,0 @@
{
"target_overrides": {
"*": {
"platform.minimal-printf-enable-file-stream": 1
}
}
}

View File

@ -128,18 +128,10 @@
"help": "Use the MPU if available to fault execution from RAM and writes to ROM. Can be disabled to reduce image size.",
"value": true
},
"minimal-printf-console-output": {
"help": "Console output when using mprintf profile. Options: UART, SWO",
"value": "UART"
},
"minimal-printf-enable-64-bit": {
"help": "Enable printing 64 bit integers when using mprintf profile",
"value": true
},
"minimal-printf-enable-file-stream": {
"help": "Enable printing to a FILE stream when using mprintf profile",
"value": true
},
"minimal-printf-enable-floating-point": {
"help": "Enable floating point printing when using mprintf profile",
"value": true

View File

@ -4,6 +4,7 @@
Library supports both printf and snprintf in 1252 bytes of flash.
Prints directly to stdio/UART without using malloc. All flags and precision modifiers are ignored.
There is no error handling if a writing error occurs.
Supports:
* %d: signed integer [h, hh, (none), l, ll, z, j, t].
@ -30,22 +31,14 @@ Floating point limitations:
Minimal printf is configured by the following parameters defined in `platform/mbed_lib.json`:
```
```json
{
"name": "platform",
"config": {
"minimal-printf-console-output": {
"help": "Console output when using minimal-printf profile. Options: UART, SWO",
"value": "UART"
},
"minimal-printf-enable-64-bit": {
"help": "Enable printing 64 bit integers when using minimal-printf profile",
"value": true
},
"minimal-printf-enable-file-stream": {
"help": "Enable printing to a FILE stream when using minimal-printf profile",
"value": true
},
"minimal-printf-enable-floating-point": {
"help": "Enable floating point printing when using minimal-printf profile",
"value": true
@ -64,10 +57,9 @@ If your target does not require some options then you can override the default c
In mbed_app.json:
```
```json
"target_overrides": {
"*": {
"platform.minimal-printf-enable-file-stream": false,
"platform.minimal-printf-enable-floating-point": false,
"platform.minimal-printf-set-floating-point-max-decimals": 6,
"platform.minimal-printf-enable-64-bit": false

View File

@ -26,59 +26,10 @@
/***************************/
#if TARGET_LIKE_MBED
#define CONSOLE_OUTPUT_UART 1
#define CONSOLE_OUTPUT_SWO 2
#define mbed_console_concat_(x) CONSOLE_OUTPUT_##x
#define mbed_console_concat(x) mbed_console_concat_(x)
#define CONSOLE_OUTPUT mbed_console_concat(MBED_CONF_PLATFORM_MINIMAL_PRINTF_CONSOLE_OUTPUT)
#if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES
static char mbed_stdio_out_prev = 0;
#endif
#if CONSOLE_OUTPUT == CONSOLE_OUTPUT_UART
#if DEVICE_SERIAL
/*
Serial initialization and new line replacement is a direct copy from mbed_retarget.cpp
If the static modifier were to be removed, this part of the code would not be necessary.
*/
#include "hal/serial_api.h"
static serial_t stdio_uart = { 0 };
/* module variable for keeping track of initialization */
static bool not_initialized = true;
static void init_serial()
{
if (not_initialized) {
not_initialized = false;
serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX);
#if MBED_CONF_PLATFORM_STDIO_BAUD_RATE
serial_baud(&stdio_uart, MBED_CONF_PLATFORM_STDIO_BAUD_RATE);
#endif
}
}
#define MBED_INITIALIZE_PRINT(x) { init_serial(); }
#define MBED_PRINT_CHARACTER(x) { serial_putc(&stdio_uart, x); }
#else
#define MBED_INITIALIZE_PRINT(x)
#define MBED_PRINT_CHARACTER(x)
#endif // if DEVICE_SERIAL
#elif CONSOLE_OUTPUT == CONSOLE_OUTPUT_SWO
#include "hal/itm_api.h"
#define MBED_INITIALIZE_PRINT(x) { mbed_itm_init(); }
#define MBED_PRINT_CHARACTER(x) { mbed_itm_send(ITM_PORT_SWO, x); }
#endif // if CONSOLE_OUTPUT
/***************************/
/* Linux */
@ -88,8 +39,6 @@ static void init_serial()
#define MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FLOATING_POINT 1
#define MBED_CONF_PLATFORM_MINIMAL_PRINTF_SET_FLOATING_POINT_MAX_DECIMALS 6
#define MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_64_BIT 1
#define MBED_INITIALIZE_PRINT(x) { ; }
#define MBED_PRINT_CHARACTER(x) { printf("%c", x); }
#endif
#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
if (buffer) {
buffer[*result] = data;
} else {
#if MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FILE_STREAM
if (stream) {
fputc(data, (FILE *) stream);
} else
#endif
{
MBED_PRINT_CHARACTER(data);
}
fputc(data, stream);
}
}
/* 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
*/
int mbed_minimal_formatted_string(char *buffer, size_t length, const char *format, va_list arguments, FILE *stream)
{
/* initialize output if needed */
MBED_INITIALIZE_PRINT();
int result = 0;
bool empty_buffer = false;

View File

@ -34,12 +34,10 @@
#define SUB_VSPRINTF __wrap_vsprintf
#define SUPER_VSNPRINTF __real_vsnprintf
#define SUB_VSNPRINTF __wrap_vsnprintf
#if MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FILE_STREAM
#define SUPER_FPRINTF __real_fprintf
#define SUB_FPRINTF __wrap_fprintf
#define SUPER_VFPRINTF __real_vfprintf
#define SUB_VFPRINTF __wrap_vfprintf
#endif
#elif defined(TOOLCHAIN_ARM) /* ARMC5/ARMC6 */\
|| defined(__ICCARM__) /* IAR */
#define SUPER_PRINTF $Super$$printf
@ -54,33 +52,19 @@
#define SUB_VSPRINTF $Sub$$vsprintf
#define SUPER_VSNPRINTF $Super$$vsnprintf
#define SUB_VSNPRINTF $Sub$$vsnprintf
#if MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FILE_STREAM
#define SUPER_FPRINTF $Super$$fprintf
#define SUB_FPRINTF $Sub$$fprintf
#define SUPER_VFPRINTF $Super$$vfprintf
#define SUB_VFPRINTF $Sub$$vfprintf
#endif
#else
#warning "This compiler is not yet supported."
#endif
// Prevent optimization of printf() by the ARMCC or IAR compiler.
// This is done to prevent optimization which can cause printf() to be
// substituted with a different function (e.g. puts()) and cause
// the output to be missing some strings.
// Note: Optimization prevention for other supported compilers is done
// via compiler optional command line arguments.
#if defined(__CC_ARM) /* ARMC5 */
#pragma push
#pragma O0
#elif defined(__ICCARM__) /* IAR */
#pragma optimize=none
#endif
int SUB_PRINTF(const char *format, ...)
{
va_list arguments;
va_start(arguments, format);
int result = mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, NULL);
int result = mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);
va_end(arguments);
return result;
@ -108,7 +92,7 @@ int SUB_SNPRINTF(char *buffer, size_t length, const char *format, ...)
int SUB_VPRINTF(const char *format, va_list arguments)
{
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, NULL);
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);
}
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
return mbed_minimal_formatted_string(buffer, length, format, arguments, NULL);
}
#if MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FILE_STREAM
int SUB_FPRINTF(FILE *stream, const char *format, ...)
{
va_list arguments;
@ -136,6 +119,5 @@ int SUB_VFPRINTF(FILE *stream, const char *format, va_list arguments)
{
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stream);
}
#endif
#endif // MBED_MINIMAL_PRINTF
#endif // MBED_MINIMAL_PRINTF

View File

@ -1,12 +1,12 @@
{
"GCC_ARM": {
"common": ["-DMBED_MINIMAL_PRINTF", "-fno-builtin-printf"],
"common": ["-DMBED_MINIMAL_PRINTF"],
"ld": ["-Wl,--wrap,printf", "-Wl,--wrap,sprintf", "-Wl,--wrap,snprintf",
"-Wl,--wrap,vprintf", "-Wl,--wrap,vsprintf", "-Wl,--wrap,vsnprintf",
"-Wl,--wrap,fprintf", "-Wl,--wrap,vfprintf"]
},
"ARMC6": {
"common": ["-DMBED_MINIMAL_PRINTF", "-fno-builtin-printf"]
"common": ["-DMBED_MINIMAL_PRINTF"]
},
"ARM": {
"common": ["-DMBED_MINIMAL_PRINTF"]