diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-12-20 15:10:55 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-12-20 15:10:55 +0100 |
commit | 137489b6cd7e03031b0acb5d3abab4603decde04 (patch) | |
tree | 05193b73a0c6dd264af13b2b1a83eccf6a92e182 /debug.cpp | |
parent | 6d27f1755b782340d1c55c3f8f01a193514a3607 (diff) | |
download | stm32f103-playground-137489b6cd7e03031b0acb5d3abab4603decde04.tar.gz stm32f103-playground-137489b6cd7e03031b0acb5d3abab4603decde04.tar.bz2 stm32f103-playground-137489b6cd7e03031b0acb5d3abab4603decde04.tar.xz stm32f103-playground-137489b6cd7e03031b0acb5d3abab4603decde04.zip |
o Adding serial1 for testing USART.
Diffstat (limited to 'debug.cpp')
-rw-r--r-- | debug.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/debug.cpp b/debug.cpp new file mode 100644 index 0000000..d44fc79 --- /dev/null +++ b/debug.cpp @@ -0,0 +1,44 @@ +#include "debug.h" +#include "printf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static void append_char(void *v, char c) { + *(*((char **) v))++ = c; +} + +void dbg_printf(const char *fmt, ...) { + char msg[100]; + msg[0] = 0; + + va_list va; + va_start(va, fmt); + char *a = msg; + char **b = &a; + tfp_format(b, append_char, fmt, va); + va_end(va); + append_char(b, '\0'); + + send_command(SYS_WRITE0, msg); +} + +void dbg_putc(void *, char c) { + char cc = c; + send_command(SYS_WRITEC, &cc); +} + +void send_command(enum SemihostingCmd command, void *message) { + int c = command; + + __asm volatile ( + "mov r0, %[cmd];" + "mov r1, %[msg];" + "bkpt #0xAB" : : [cmd] "r"(c), [msg] "r"(message) : "r0", "r1", "memory" + ); +} + +#ifdef __cplusplus +}; +#endif |