Skip to content

Commit 3e3b133

Browse files
authored
Merge pull request ARMmbed#12 from ARMmbed/feature-swo
Optional SWO output instead of UART
2 parents 1b20647 + cbdb3fe commit 3e3b133

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

features/minimal-printf/mbed_lib.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"enable-64-bit": {
1313
"help": "Enable printing 64 bit integers",
1414
"value": true
15+
},
16+
"console-output": {
17+
"help": "Console output. Options: UART, SWO",
18+
"value": "UART"
1519
}
1620
}
1721
}

features/minimal-printf/mbed_printf_implementation.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,26 @@
2525
/* MBED */
2626
/***************************/
2727
#if TARGET_LIKE_MBED
28+
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_MINIMAL_PRINTF_CONSOLE_OUTPUT)
34+
35+
#if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES
36+
static char mbed_stdio_out_prev = 0;
37+
#endif
38+
39+
#if CONSOLE_OUTPUT == CONSOLE_OUTPUT_UART
40+
#if DEVICE_SERIAL
2841
/*
2942
Serial initialization and new line replacement is a direct copy from mbed_retarget.cpp
3043
If the static modifier were to be removed, this part of the code would not be necessary.
3144
*/
3245
#include "hal/serial_api.h"
3346

34-
#if DEVICE_SERIAL
3547
static serial_t stdio_uart = { 0 };
36-
#if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES
37-
static char mbed_stdio_out_prev = 0;
38-
#endif
39-
#endif
4048

4149
/* module variable for keeping track of initialization */
4250
static bool not_initialized = true;
@@ -47,18 +55,32 @@ static void init_serial()
4755
{
4856
not_initialized = false;
4957

50-
#if DEVICE_SERIAL
5158
serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX);
5259
#if MBED_CONF_PLATFORM_STDIO_BAUD_RATE
5360
serial_baud(&stdio_uart, MBED_CONF_PLATFORM_STDIO_BAUD_RATE);
54-
#endif
5561
#endif
5662
}
5763
}
5864

5965
#define MBED_INITIALIZE_PRINT(x) { init_serial(); }
6066
#define MBED_PRINT_CHARACTER(x) { serial_putc(&stdio_uart, x); }
6167

68+
#else
69+
70+
#define MBED_INITIALIZE_PRINT(x)
71+
#define MBED_PRINT_CHARACTER(x)
72+
73+
#endif // if DEVICE_SERIAL
74+
75+
#elif CONSOLE_OUTPUT == CONSOLE_OUTPUT_SWO
76+
77+
#include "hal/itm_api.h"
78+
79+
#define MBED_INITIALIZE_PRINT(x) { mbed_itm_init(); }
80+
#define MBED_PRINT_CHARACTER(x) { mbed_itm_send(ITM_PORT_SWO, x); }
81+
82+
#endif // if CONSOLE_OUTPUT
83+
6284
/***************************/
6385
/* Linux */
6486
/***************************/

0 commit comments

Comments
 (0)