Merge pull request #12 from ARMmbed/feature-swo

Optional SWO output instead of UART
pull/11051/head v1.0.0-minimal-printf
LIYOU ZHOU 2018-05-22 17:06:06 +01:00 committed by GitHub
commit 3e3b133515
2 changed files with 33 additions and 7 deletions

View File

@ -12,6 +12,10 @@
"enable-64-bit": {
"help": "Enable printing 64 bit integers",
"value": true
},
"console-output": {
"help": "Console output. Options: UART, SWO",
"value": "UART"
}
}
}

View File

@ -25,18 +25,26 @@
/* MBED */
/***************************/
#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_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"
#if DEVICE_SERIAL
static serial_t stdio_uart = { 0 };
#if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES
static char mbed_stdio_out_prev = 0;
#endif
#endif
/* module variable for keeping track of initialization */
static bool not_initialized = true;
@ -47,11 +55,9 @@ static void init_serial()
{
not_initialized = false;
#if DEVICE_SERIAL
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
#endif
}
}
@ -59,6 +65,22 @@ static void init_serial()
#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 */
/***************************/